相关疑难解决方法(0)

排序熊猫系列

我试图弄清楚如何以智能方式对作为groupby聚合的结果生成的Series进行排序.

我生成一个我的DataFrame的聚合,如下所示:

means = df.testColumn.groupby(df.testCategory).mean()
Run Code Online (Sandbox Code Playgroud)

这导致了一个系列.我现在尝试按值排序,但得到一个错误:

means.sort()
...
-> Exception: This Series is a view of some other array, to sort in-place you must create a copy
Run Code Online (Sandbox Code Playgroud)

然后我尝试创建一个副本:

meansCopy = Series(means)
meansCopy.sort()
-> Exception: This Series is a view of some other array, to sort in-place you must create a copy
Run Code Online (Sandbox Code Playgroud)

我怎样才能使用这种方法?

python sorting series pandas

22
推荐指数
1
解决办法
6932
查看次数

标签 统计

pandas ×1

python ×1

series ×1

sorting ×1