Pandas pivot_table 将行重新排列为列
Pandas pivot_table rearangging rows to columns
我是Pandas新手,非常喜欢。我正在尝试创建一个枢轴 table 但遇到了麻烦。这是一个解释我的问题的小图像文件:
我试过下面的行,但它没有按照我想要的方式输出。
df = df.pivot_table(index = 'Time', columns = 'Item', values = 'Value', aggfunc = list)
试试这个:
output = pd.pivot_table(df, values='Value', index=['Time', 'ID'],
columns=['Item'], aggfunc=np.sum, fill_value="")
我是Pandas新手,非常喜欢。我正在尝试创建一个枢轴 table 但遇到了麻烦。这是一个解释我的问题的小图像文件:
我试过下面的行,但它没有按照我想要的方式输出。
df = df.pivot_table(index = 'Time', columns = 'Item', values = 'Value', aggfunc = list)
试试这个:
output = pd.pivot_table(df, values='Value', index=['Time', 'ID'],
columns=['Item'], aggfunc=np.sum, fill_value="")