【发布时间】:2017-07-08 16:14:16
【问题描述】:
>>> df
A B C D
0 foo one small 1
1 foo one large 2
2 foo one large 2
3 foo two small 3
4 foo two small 3
5 bar one large 4
6 bar one small 5
7 bar two small 6
8 bar two large 7
>>> table = pivot_table(df, values='D', index=['A', 'B'],
... columns=['C'], aggfunc=np.sum)
>>> table
small large
foo one 1 4
two 6 NaN
bar one 5 4
two 6 7
我希望输出如上所示,但我得到了一个排序的输出。 bar 高于 foo 等等。
【问题讨论】:
标签: python pandas dataframe pivot-table