我不知道该怎么问这个问题,但我会试着解释我的情况。
我有一个数据集,数据如下:
<表类>
产品价值值类型 年 tbody><<tr>21日5 价格 21 5 卷 21 B55岁,3 价格 21 B10 卷 21 C70, 0 价格 21 D37岁5 价格 21 D7日7 卷 21 表类>
使用pivot
:
out = df.pivot(index=['Product', 'year'], columns='Value type', values=['Value'])
.droplevel(0, axis=1).reset_index().rename_axis(None, axis=1)
[['Product', 'Price', 'Volume', 'year']]
>>> out
Product Price Volume year
0 A 21.5 5.0 21
1 B 55.3 10.0 21
2 C 70.0 NaN 21
3 D 37.5 7.7 21