atoti.hierarchies module#
- class atoti.hierarchies.Hierarchies#
Manage the hierarchies of a
Cube
.Example
>>> prices_df = pd.DataFrame( ... columns=["Nation", "City", "Color", "Price"], ... data=[ ... ("France", "Paris", "red", 20.0), ... ("France", "Lyon", "blue", 15.0), ... ("France", "Toulouse", "green", 10.0), ... ("UK", "London", "red", 20.0), ... ("UK", "Manchester", "blue", 15.0), ... ], ... ) >>> table = session.read_pandas(prices_df, table_name="Prices") >>> cube = session.create_cube(table, mode="manual") >>> h = cube.hierarchies >>> h["Nation"] = {"Nation": table["Nation"]} >>> list(h) [('Prices', 'Nation')]
A hierarchy can be renamed by creating a new one with the same levels and then removing the old one.
>>> h["Country"] = h["Nation"].levels >>> del h["Nation"] >>> list(h) [('Prices', 'Country')]
update()
can be used to batch hierarchy creation operations for improved performance:>>> h.update( ... { ... ("Geography", "Geography"): [table["Nation"], table["City"]], ... "Color": {"Color": table["Color"]}, ... } ... ) >>> list(h) [('Prices', 'Color'), ('Geography', 'Geography'), ('Prices', 'Country')]
See also
Hierarchy
to configure existing hierarchies.