我目前正在从交叉表操作中处理数据帧。在熊猫DataFrame中安排列
pd.crosstab(data['One'],data['two'], margins=True).apply(lambda r: r/len(data)*100,axis = 1)
列出来以下顺序
A B C D E All
B
C
D
E
All 100
但我想订购的列如下所示:
A C D B E All
B
C
D
E
All 100
有没有一种简单的方法来组织列? 当我使用colnames=['C', 'D','B','E']
它返回一个错误:
'AssertionError: arrays and names must have the same length '