0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

あるシリーズの文字列が辞書のKeyにあった時、辞書のValueに文字列を変換させる

Last updated at Posted at 2019-12-10

やりたいこと : あるSeriesが辞書のkeyにあった時、辞書のvalueに値を変換させる

【元のデータ】
hoge = pd.Series(["3回目", "1回目", "5回目", "5回目", "2回目", "4回目"])

【変換リスト】
name_lis = {"1回目": "01.first",
"2回目": "02.second",
"3回目": "03.third",
"4回目": "04.fourth",
"5回目": "05.fifth"
}

mapでSeriesを囲う(@nkayさんありがとうございます!)

hoge.map(name_lis)

辞書でSeriesを囲う

hoge.apply(lambda x: name_lis[x])

0 03.third
1 01.first
2 05.fifth
3 05.fifth
4 02.second
5 04.fourth
dtype: object

0
0
2

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?