LoginSignup
1
1

More than 5 years have passed since last update.

【Python】Dataframeでソート

Last updated at Posted at 2018-11-08

データフレーム(df)作成

以下のようなdfを作成

  word  score
0    a      1
1    b     10
2    c      3
import pandas as pd

# 列を宣言
key = "word"
value = "score"

data = {}
data[key] = ["a", "b", "c"]
data[value] = [1, 10, 3]

df = pd.DataFrame(data=data)

ソート


df = df.sort_values(by=value, ascending=False)

ソート後のdfは

  word  score
1    b     10
2    c      3
0    a      1
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1