개발/Python

[Kaggle] Pandas Profiling 사용방법

피로물든딸기 2025. 1. 5. 01:47
반응형

타이타닉 데이터를 로드한 후,

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

# 타이타닉 데이터 로드
url = "https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv"
data = pd.read_csv(url)
data.head()

 

pandas_profilingimport하면

import pandas_profiling

data.profile_report()

 

아래와 같은 에러가 발생하게 된다.

PydanticImportError: `BaseSettings` has been moved to the `pydantic-settings` package. See https://docs.pydantic.dev/2.9/migration/#basesettings-has-moved-to-pydantic-settings for more details.

---------------------------------------------------------------------------
PydanticImportError                       Traceback (most recent call last)
<ipython-input-7-044f13e41748> in <cell line: 2>()
      1 import pandas as pd
----> 2 import pandas_profiling
      3 
      4 train = pd.read_csv("../input/titanic/train.csv")
      5 train.head()

/usr/local/lib/python3.10/dist-packages/pandas_profiling/__init__.py in <module>
      6 from warnings import warn
      7 
----> 8 from pandas_profiling.compare_reports import compare
      9 from pandas_profiling.controller import pandas_decorator
     10 from pandas_profiling.profile_report import ProfileReport

/usr/local/lib/python3.10/dist-packages/pandas_profiling/compare_reports.py in <module>
      4 import pandas as pd
      5 
----> 6 from pandas_profiling.config import Correlation, Settings
      7 from pandas_profiling.model.alerts import Alert
      8 from pandas_profiling.profile_report import ProfileReport

/usr/local/lib/python3.10/dist-packages/pandas_profiling/config.py in <module>
      5 
      6 import yaml
----> 7 from pydantic import BaseModel, BaseSettings, Field, PrivateAttr
      8 
      9 

/usr/local/lib/python3.10/dist-packages/pydantic/__init__.py in __getattr__(attr_name)
    400     dynamic_attr = _dynamic_imports.get(attr_name)
    401     if dynamic_attr is None:
--> 402         return _getattr_migration(attr_name)
    403 
    404     package, module_name = dynamic_attr

/usr/local/lib/python3.10/dist-packages/pydantic/_migration.py in wrapper(name)
    294             return import_string(REDIRECT_TO_V1[import_path])
    295         if import_path == 'pydantic:BaseSettings':
--> 296             raise PydanticImportError(
    297                 '`BaseSettings` has been moved to the `pydantic-settings` package. '
    298                 f'See https://docs.pydantic.dev/{version_short()}/migration/#basesettings-has-moved-to-pydantic-settings '

PydanticImportError: `BaseSettings` has been moved to the `pydantic-settings` package. See https://docs.pydantic.dev/2.9/migration/#basesettings-has-moved-to-pydantic-settings for more details.

For further information visit https://errors.pydantic.dev/2.9/u/import-error

해결 방법

 

ProfileReport를 다음과 같이 import하면 정상적으로 report를 얻을 수 있다.

from ydata_profiling import ProfileReport

data.profile_report()

 

전체 코드는 아래 파일을 참고하자.

pandas-profiling.ipynb
5.41MB

반응형