【问题标题】:Sorting DataFrame by values of a column [duplicate]按列的值对DataFrame进行排序[重复]
【发布时间】:2017-08-01 22:22:26
【问题描述】:

我想按“分数”的值对这个数据框进行排序(从 gi​​ggest 到 smalles,反之亦然,我只想要一些顺序) 我最后编码: models.sort_values(by='Score', ascending=False)

                        Model     Score
0     Support Vector Machines  0.685315
1                         KNN  0.748252
2         Logistic Regression  0.769231
3               Random Forest  0.944056
4                 Naive Bayes  0.769231
5                  Perceptron  0.720280
6  Stochastic Gradient Decent  0.447552
7                  Linear SVC  0.790210
8               Decision Tree  0.727273

显然我的代码不起作用,我应该写什么?

【问题讨论】:

    标签: python pandas


    【解决方案1】:

    sort_values 默认不是就地的。来自docs

    DataFrame.sort_values(by, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last')

    要么使用inplace=True

    models.sort_values(by='Score', ascending=False, inplace=True)

    或重新分配:

    models = models.sort_values(by='Score', ascending=False)

    【讨论】:

      猜你喜欢
      • 2016-12-21
      • 2016-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-05
      • 2011-12-28
      • 2019-11-13
      相关资源
      最近更新 更多