'Is it possible to pivot in this way with pandas?
I have this dataframe.
| report_id | landcover_type | data_type | mean | area |
|---|---|---|---|---|
| 615 | Acid grassland | canopyheight | 2 | 493.9125 |
| 615 | Arable and horticulture | canopyheight | 4 | 0.86 |
| 615 | Acid grassland | carbonstoragewoodlands | 8 | 493.9125 |
| 615 | Arable and horticulture | carbonstoragewoodlands | 161 | 0.86 |
is it possible to pivot it so I have a new column for each distinct data_type with their own aggregation of my choosing like this?
| report_id | landcover_type | canopyheight_mean | carbonstorage_total | area |
|---|---|---|---|---|
| 615 | Acid Grassland | 2 | 8 | 493.9125 |
| 615 | Arable and horticulture | 4 | 161 | 493.9125 |
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
