'How to group columns based on unique values from another columns in pandas
Let's say I have a pandas dataframe:
| brand | category | size |
|---|---|---|
| nike | sneaker | 9 |
| adidas | boots | 11 |
| nike | boots | 9 |
There could be more than 100 brands and some brands could have more categories than others. How do I get a table that will group them based on brands? That is the first column(index) that should be the brands, the second should be the categories belonging to the brand, and if possible the mean size for each brand as well, using pandas.
| brand | category | size |
|---|---|---|
| nike | sneaker | 10.5 |
| boots | ||
| adidas | boots | 11 |
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
