‘DataFrame‘ object has no attribute ‘sort‘报错

在使用sort方法时报错
报错代码

segStat = segmentDataFrame.groupby(
    ["segment"]
    )["segment"].agg(
    [("num",numpy.size)]
    ).reset_index().sort(
           column="num",ascending=False
        )

报错信息

Traceback (most recent call last):
  File "XXX\2.3.py", line 58, in <module>
    ).reset_index().sort(
  File "D:\program\Python\lib\site-packages\pandas\core\generic.py", line 5902, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'sort'

分析
sort方法需要修改为sort_values方法

修改如下

segStat = segmentDataFrame.groupby(
    ["segment"]
    )["segment"].agg(
    [("num",numpy.size)]
    ).reset_index().sort_values(
            "num",ascending=False
        )

你可能感兴趣的:(python,python,pandas,机器学习)