LoginSignup
1
0

More than 3 years have passed since last update.

[備忘録]pandas mode()で最頻値を抽出する

Posted at

いつもforループを使って処理していて
処理に1時間とかかかっていたので。

使い方

サンプルデータとして
kaggle-House Prices


features['MSZoning'] = features.groupby('MSSubClass')['MSZoning'].transform(lambda x: x.fillna(x.mode()[0]))

これで 'MSSubClass'のグループ毎に'MSZoning'の最頻値を欠損値に代入できる。

x.mode()[0]
>>>最頻値そのものの値を取得

以上

まとめ

初めての記事投稿。
間違っている部分やアドバイス等ご指摘いただけると助かります。

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