相关疑难解决方法(0)

熊猫:排序枢轴表

只是第一次尝试大熊猫,我试图先通过索引对数据透视表进行排序,然后按系列中的值进行排序.

到目前为止,我已经尝试过:

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
Run Code Online (Sandbox Code Playgroud)

按索引排序数据透视表的正确方法是什么?

python pandas

4
推荐指数
1
解决办法
9304
查看次数

标签 统计

pandas ×1

python ×1