假设我有一个透视表,如下所示:
completed_olns total_completed_olns
work_type A B C
employee
Employee1 94 1163 1 1258
Employee2 168 770 4 942
Employee3 173 746 8 927
如何将A、B、C列重新排列为任意顺序,如B、A、C?你知道吗
这些数据是从数据库输出的,并通过带有pd.read_csv()
的csv读入
我试过pivot.sort_index(level=1, axis=1, ascending=False)
,这让我更接近我需要的东西。你知道吗
我也试过pivot = pivot[['B', 'A', 'C']]
,这给了我:
KeyError: "['B', 'A', 'C'] not in index"
这是我发现的两个最常见的建议。你知道吗
将
.reindex
与level
参数一起使用样本数据
代码
如果组缺少标签或标签不存在,则不会插入所有
NaN
列相关问题 更多 >
编程相关推荐