我第一次尝试使用pandas,我想先按索引排序一个透视表,然后再按一个系列中的值排序。
到目前为止,我已经尝试过:
table = pivot_table(sheet1, values='Value', rows=['A','B'], aggfunc=np.sum)
# Sorts by value ascending, can't change to descending
table.copy().sort()
table
# The following gives me the correct ordering in values, but ignores index
sorted_table = table.order(ascending=False)
sorted_table
# The following brings me back to the original ordering
sorted_table = table.order(ascending=False)
sorted_table2 = sorted_table.sortlevel(0)
sorted_table2
如何正确地按照索引和值来排序一个数据透视表(pivot table)?