atoti.Cube.create_parameter_hierarchy_from_column()#

Cube.create_parameter_hierarchy_from_column(name, column)#

Create a single-level hierarchy which dynamically takes its members from a column.

Parameters:
  • name (str) – Name given to the created dimension, hierarchy and its single level.

  • column (Column) – Column from which to take members.

Example

>>> df = pd.DataFrame(
...     {
...         "Seller": ["Seller_1", "Seller_1", "Seller_2", "Seller_2"],
...         "ProductId": ["aBk3", "ceJ4", "aBk3", "ceJ4"],
...         "Price": [2.5, 49.99, 3.0, 54.99],
...     }
... )
>>> table = session.read_pandas(df, table_name="Seller")
>>> cube = session.create_cube(table)
>>> l, m = cube.levels, cube.measures
>>> cube.create_parameter_hierarchy_from_column(
...     "Competitor", table["Seller"]
... )
>>> m["Price"] = tt.agg.single_value(table["Price"])
>>> m["Competitor price"] = tt.at(
...     m["Price"], l["Seller"] == l["Competitor"]
... )
>>> cube.query(
...     m["Competitor price"],
...     levels=[l["Seller"], l["ProductId"]],
... )
                   Competitor price
Seller   ProductId
Seller_1 aBk3                  2.50
         ceJ4                 49.99
Seller_2 aBk3                  2.50
         ceJ4                 49.99
>>> cube.query(
...     m["Competitor price"],
...     levels=[l["Seller"], l["ProductId"]],
...     filter=l["Competitor"] == "Seller_2",
... )
                   Competitor price
Seller   ProductId
Seller_1 aBk3                  3.00
         ceJ4                 54.99
Seller_2 aBk3                  3.00
         ceJ4                 54.99