在DataFrame中对值进行分组

时间:2019-04-10 15:29:27

标签: python pandas dataframe

我有一个DataFrame enter image description here

我想将相似的项目列值分组

不使用groupby()。agg()函数,因为不想在价格列上执行任何算术运算

我要制作此DataFrame

变成这样

2 个答案:

答案 0 :(得分:0)

如果我正确理解了您的问题,那么下面的答案可以通过使用pivot_table

来获得所需的结果
df.pivot_table(index=['item','date'],values='price')

位置:

df =您的数据框

请检查并告知它是否对您有用。

答案 1 :(得分:0)

IIUC,

您可以使用set_index

df = df.set_index(['item','date'])
相关问题