是否有自动方法来维护返回的数据帧的列('C','B','A')的顺序?
g = df.groupby(['people'])
g['people'].agg({'C' : len,
'B' : len,
'A' : len,
})
这将返回列A,B,C而不是C,B,A。
我只能找到示例,但不能找到agg函数本身的文档。
这似乎是一种解决方法:
g = df.groupby(['people'])
g['people'].agg({'C' : len,
'B' : len,
'A' : len,
}).reindex_axis(['C','B','A'], axis=1)