atoti.hierarchies.Hierarchies#
- final 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 copying it and deleting the old one.
>>> h["Country"] = h["Nation"] >>> del h["Nation"] >>> list(h) [('Prices', 'Country')] >>> list(h["Country"]) ['Nation']
update()
can be used to batch hierarchy creation operations for improved performance:>>> h.update( ... { ... ("Geography", "Geography"): [table["Nation"], table["City"]], ... "Color": {"Color": table["Color"]}, ... } ... ) >>> sorted(h) [('Geography', 'Geography'), ('Prices', 'Color'), ('Prices', 'Country')]
See also
Hierarchy
to configure existing hierarchies.