我正在试图弄清楚如何以一种智能的方式对作为groupby聚合的结果生成的Series进行排序。
我生成了一个DataFrame聚合,如下所示:
means = df.testColumn.groupby(df.testCategory).mean()这会导致一系列的结果。我现在尝试按值对其进行排序,但得到一个错误:
means.sort()
...
-> Exception: This Series is a view of some other array, to sort in-place you must create a copy然后我尝试创建一个副本:
meansCopy = Series(means)
meansCopy.sort()
-> Exception: This Series is a view of some other array, to sort in-place you must create a copy怎样才能让这种排序正常工作呢?
发布于 2012-08-27 03:31:38
使用sort_values,即means = means.sort_values()。Pandas v0.17+
(非常旧的答案,在v0.17/2015之前)
pandas常用的order()方法:means = means.order()。
https://stackoverflow.com/questions/12133075
复制相似问题