问题:pyhton中使用pivot_table汇总数据后,结果不是DF格式,需要转为DF格式方便后面继续进行操作。
解决方法:使用 reset_index()
将数据透视表pivot_table转为DataFrame 格式
具体代码如下:
pivot=pd.pivot_table(df,index=['time'],columns=['products'],values=['price'],aggfunc='sum')
table=pivot.reset_index()
另外,还可以使用df.reset_index(drop=True)
将索引值删除