Google Colaboratoryでエラーを出さずにpandas-profilingを使う
Google Colaboratoryでpandas-profilingを使うためのサンプルコードです。
Google Drive内のcsvファイルに対してpandas-profilingを実行したときを想定しています。
サンプルコード
①Google Colaboratory上にpandas-profilingの実行結果を出力する
!pip install markupsafe==2.0.1
#実行後に[y]をクリックし、処理終了後に[RESTART RUNTIME]と出るのでクリックする
!pip uninstall pandas_profiling
!pip install git+https://github.com/pandas-profiling/pandas-profiling.git
import pandas as pd
import pandas_profiling as pdp
#GoogleDrive マウント コラボ側がこう使ってくれと用意しているもの
from google.colab import drive
drive.mount('/content/drive')
#ここではGoogleDriveのマイドライブにtrain.csvとある場合を想定しています。必要に応じてパスを変更してください
train = pd.read_csv('/content/drive/MyDrive/train.csv')
pdp.ProfileReport(train)
②Google Colaboratory上でpandas-profilingを実行し、HTML形式で出力する
!pip install markupsafe==2.0.1
#実行後に[y]をクリックし、処理終了後に[RESTART RUNTIME]と出るのでクリックする
!pip uninstall pandas_profiling
!pip install git+https://github.com/pandas-profiling/pandas-profiling.git
import pandas as pd
import pandas_profiling as pdp
#GoogleDrive マウント コラボ側がこう使ってくれと用意しているもの
from google.colab import drive
drive.mount('/content/drive')
#ここではGoogleDriveのマイドライブにtrain.csvとある場合を想定しています。必要に応じてパスを変更してください
train = pd.read_csv('/content/drive/MyDrive/train.csv')
profile = pdp.ProfileReport(train)
#Google Driveのマイドライブに「profile.html」という名前で出力します。Google Driveからダウンロードした「profile.html」をダブルクリックすると、pandas-profilingを使った結果がブラウザで確認できます。
profile.to_file("profile.html")
参考
clione.online
import pandas_profiling as pdpで以下のエラーが出たときの対処法
ImportError: cannot import name ‘soft_unicode’ from ‘markupsafe’
yurukaiha.hatenablog.com
pdp.ProfileReport(train)に以下のエラーが出たときの対処法
TypeError: concat() got an unexpected keyword argument 'join_axes'
Google colabにインストールされているpandas-profilingのバージョンが古いことが原因で起こるエラーです。
なので、pandas-profilingのアップグレードやGithubから最新バージョンをインストールが必要。