-
|
Hello, I am experimenting with my_table = perspective.Table(
pd.DataFrame(
[
["Fruit", "Apple", 10],
["Fruit", "Orange", 5],
["Fruit", "Strawberry", 12],
["Vegetable", "Potato", 8],
["Vegetable", "Carrot", 4],
],
columns=["Category", "Item", "Quantity"],
),
index="index",
)
pivoted = my_table.view(group_by=["Category"], columns=["Quantity"])
print(
pivoted.to_records()
) # [{'__ROW_PATH__': [], 'Quantity': 39}, {'__ROW_PATH__': ['Fruit'], 'Quantity': 27}, {'__ROW_PATH__': ['Vegetable'], 'Quantity': 12}]
print(pivoted.get_row_expanded(1)) # False
print(pivoted.get_row_expanded(2)) # False
pivoted.expand(1)
print(
pivoted.to_records()
) # [{'__ROW_PATH__': [], 'Quantity': 39}, {'__ROW_PATH__': ['Fruit'], 'Quantity': 27}, {'__ROW_PATH__': ['Vegetable'], 'Quantity': 12}]
print(pivoted.get_row_expanded(1)) # False |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Your problem isn't with row expansion, rather this is not how group-by works. You can't expand the If you want a pivot table, use |
Beta Was this translation helpful? Give feedback.
Your problem isn't with row expansion, rather this is not how group-by works. You can't expand the
"Fruit"row because this is a leaf node, there are no children because you've only applied a single pivot level. Please check the documentation forgroup_by, or any of the interactive examples on the perspective docs site that feature group-by operations.If you want a pivot table, use
perspective-viewer- there is nothing in theperspective-pythonAPI which is not 1:1 already implemented in theperspective-viewerUI. If you want a master-detail view, here is an example.