Using Pandas with PyMPX

Importing the pympx module will add extra functionality to the pandas module.

The extra functions behave in a similar way to pd.read_csv() and pd.DataFrame.to_csv()

Reading from Empower into a pandas DataFrame

For example pd.read_empower() returns a pandas DataFrame in the same way that pd.read_csv() does:

Notebook

The returned dataframe contains the standard Empower fields, and the Empower custom fields. In the example above NewField is an Empower custom attribute. The column ID contains the Empower physid.

Tip

Typing the dot (.) symbol and then the [TAB] key will bring up the pandas autocomplete. If you type part of a method name you can see the matching methods in the dropdown list.

_images/using_autocomplete_in_jupyter.png

pd.read_empower() appears in the dropdown along with the standard pandas read functions.

Creating elements from csv, via a pandas DataFrame

Elements can be created from csv very easily, via a pandas DataFrame.

The one difficulty is to know that the DataFrame’s columns need renaming to the standard dimension field names

  • Short Name

  • Long Name

  • Description

  • Group Only

  • Calculation Status

  • Calculation

  • Colour

  • Measure Element

  • …and custom field longnames

Notebook

Creating a hierarchy from a flat list in a pandas DataFrame

Hierarchy structure can be loaded from pandas DataFrames.

Notebook