7
1

More than 1 year has passed since last update.

[Python3 / pandas] colaboratory上で、pandas_profilingのProfileReportを実行するとエラーコンボが発生

Last updated at Posted at 2021-11-13

Summary(概要)

発生したエラーはこれら。

# 1. join_axesなんて引き数は知らないよ
TypeError: concat() got an unexpected keyword argument 'join_axes'

# 2. pandas_profiling.mplstyleってファイルが見つからないよ
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/lib/python3.7/dist-packages/pandas_profiling/pandas_profiling.mplstyle'

# 3. 新しいバージョン使いたかったらruntime再起動してね
WARNING: The following packages were previously imported in this runtime:
  [pandas_profiling]
You must restart the runtime in order to use newly installed versions.

この対処法を書いていく。

Environment(環境)

Target Versionなど
colabortory (2021/11/13現在)
pandas-profiling 3.1.0

pandas-profiling のバージョンはこうやって確認した
2021-11-13_08h52_58.png

Detail

サンプルとして、scikit-learnのirisのデータでやるね。

import pandas as pd
from sklearn.datasets import load_iris
x, t = load_iris(return_X_y=True)
df = pd.DataFrame(x)
df

0   1   2   3
0   5.1 3.5 1.4 0.2
1   4.9 3.0 1.4 0.2
2   4.7 3.2 1.3 0.2
3   4.6 3.1 1.5 0.2
4   5.0 3.6 1.4 0.2
... ... ... ... ...
145 6.7 3.0 5.2 2.3
146 6.3 2.5 5.0 1.9
147 6.5 3.0 5.2 2.0
148 6.2 3.4 5.4 2.3
149 5.9 3.0 5.1 1.8
150 rows × 4 columns

1. エラー1個目

1-1. エラー内容

from pandas_profiling import ProfileReport
report = ProfileReport(df)
report

/usr/local/lib/python3.7/dist-packages/pandas_profiling/describe.py in describe(df, bins, check_correlation, correlation_threshold, correlation_overrides, check_recoded, pool_size, **kwargs)
    390             if name not in names:
    391                 names.append(name)
--> 392     variable_stats = pd.concat(ldesc, join_axes=pd.Index([names]), axis=1)
    393     variable_stats.columns.names = df.columns.names
    394 

TypeError: concat() got an unexpected keyword argument 'join_axes'

ぷわーw

1-2. 対処法

この、1個目のエラーの対処法はこちらの記事に記載されているよ。

!pip install -U pandas_profiling

を実行すればよいとのこと。

2. エラー2個目

2-1. エラー内容

!pip install -U pandas_profiling

from pandas_profiling import ProfileReport
report = ProfileReport(df)
report

FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/lib/python3.7/dist-packages/pandas_profiling/pandas_profiling.mplstyle'

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/matplotlib/style/core.py in use(style)
    118                     "{!r} not found in the style library and input is not a "
    119                     "valid URL or path; see `style.available` for list of "
--> 120                     "available styles".format(style))
    121 
    122 

OSError: '/usr/local/lib/python3.7/dist-packages/pandas_profiling/pandas_profiling.mplstyle' not found in the style library and input is not a valid URL or path; see `style.available` for list of available styles

(^ワ^#)イラッ☆彡

2-2. 対処法

今度はこっちに書かれていた。

pandas_profilingを1回アンインストールしろということらしい。1
OK。

これでどうや!

!pip uninstall pandas_profiling
!pip install -U pandas_profiling
from pandas_profiling import ProfileReport
report = ProfileReport(df)
report

なんか出たけど処理が止まった。

2021-11-13_09h02_28.png

実は、この点滅しているところをクリックすると、文字を入力できる。

Proceed (y/n)?: 進めていい? (yes or no)

と聞かれているので、yesの意味の y(半角) を入力してEnterキーを押す。

2021-11-13_09h02_42.png

すると処理が進む

Found existing installation: pandas-profiling 3.1.0
Uninstalling pandas-profiling-3.1.0:
  Would remove:
    /usr/local/bin/pandas_profiling
    /usr/local/lib/python3.7/dist-packages/pandas_profiling-3.1.0.dist-info/*
    /usr/local/lib/python3.7/dist-packages/pandas_profiling/*
Proceed (y/n)? y
  Successfully uninstalled pandas-profiling-3.1.0
Collecting pandas_profiling
  Using cached pandas_profiling-3.1.0-py2.py3-none-any.whl (261 kB)
Requirement already satisfied: jinja2>=2.11.1 in /usr/local/lib/python3.7/dist-packages (from pandas_profiling) (2.11.3)

~  ~

Requirement already satisfied: PyWavelets in /usr/local/lib/python3.7/dist-packages (from imagehash->visions[type_image_path]==0.7.4->pandas_profiling) (1.2.0)
Installing collected packages: pandas-profiling
Successfully installed pandas-profiling-3.1.0

そしてこんな感じのが出る。

image.png

ん~~~全然先に進めませんねぇ(^ワ^##)

3. エラー3個目(warning)

3-1. エラー内容

WARNING: The following packages were previously imported in this runtime:
[pandas_profiling]
You must restart the runtime in order to use newly installed versions.

3-2. 対処法

大人しく言われた通り、RESTART RUNTIMEする。
表示されている灰色のボタンを押せばOK。

そして、先ほどまで行ってきたことを再度実行する。

すると、次のような結果が表示される!(^ワ^*)

image.png

おしまい!!


  1. 実は、一つ目のエラーの対処法の記事にも同じことが書かれていたが、自分がその条件に該当するとは気が付かなかった。自分でインストールした覚えはなかったので「インストールしてる人は」と書かれていてもスルーしてしまったが、実際にはcolaboratoryには最初からインストールされていたので、colaboratoryを使う人はおそらく全員「インストールしてる人は」に該当する。 

7
1
1

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