LoginSignup
0
0

More than 3 years have passed since last update.

pandas-profiling で IndexError: index 0 is out of bounds for axis 0 with size 0 になる

Posted at

事象

pandas-profiling の ProfileReportを実行したら以下のエラーになって1時間くらい悩んだので備忘メモを残します。

IndexError: index 0 is out of bounds for axis 0 with size 0 "pandas.profiling" profilereport

原因

NaN と False の2値しかもたない項目があったから。
以下の記事が参考になりました。

In my case I pinned this down to column which only contains two values: NaN and False. Converting that only column to dtype float was workaround for this issue.
(NaN と False の2値しかもたない項目があると発生するよ)

対応策

もっといい方法がありそうですが、今回は下記で項目を特定しました。

# NaN と False の項目数の取得し、1つの表にする
s1 = df.isnull().sum()
s2 = (df == False).sum()
s_h = pd.concat([s1, s2], axis=1)
print(s_h)

# 全行ががFalse または Nan の行をTrueで表示
s = (s_h.sum(axis=1) == df.shape[0])
print(s)

# DataFrame型に変換し、index関数でTrue行だけを取得
_df = pd.DataFrame(s)
_df.index[_df[0]].tolist()

参考
df.index で文字列にマッチした(またはTrue/False)の項目値を取得する方法
https://stackoverflow.com/questions/21800169/python-pandas-get-index-of-rows-which-column-matches-certain-value

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