pandas PydanticImportError:`BaseSettings`已移动到`pydantic-settings`包中

nfeuvbwi  于 2023-08-01  发布在  其他
关注(0)|答案(4)|浏览(1560)

我从kaggle下载了泰坦尼克号数据集。我正在通过安装pandas_profiling来实现pandas的分析
您的贡献将不胜感激!

import pandas as pd 
df = pd.read_csv('E:/pythonWorkspace/excelFiles/train.csv')
df.head()

from pandas_profiling import ProfileReport
prof = ProfileReport(df) #object created!
prof.to_file(output_file='output.html')

字符串
错误代码:

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

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

0sgqnhkj

0sgqnhkj1#

首先,你需要安装ydata-profiling

pip install ydata-profiling

字符串
然后:

import pandas as pd
from ydata_profiling import ProfileReport

# Read the data from a csv file 
df = pd.read_csv("data.csv")

# Generate the data profiling report 
report = ProfileReport(df, title='My Data')
report.to_file("my_report.html")

czfnxgou

czfnxgou2#

pydantic v2具有从v1开始的突破性变化。

pip install "pydantic==1.*"

字符串
应该能修好

uqcuzwp8

uqcuzwp83#

我尝试了@SeaEngineering的解决方案,但我得到了环境冲突,不断返回错误。
我通过使用condas安装ydata-profiling来修复它:

conda install -c conda-forge ydata-profiling

字符串
这将安装ydata-profiling并修复您可能遇到的任何环境冲突。
安装后只需更换

from ydata_profiling import ProfileReport


from pandas_profiling import ProfileReport

7cjasjjr

7cjasjjr4#

将pydantic降级为<2或安装pydantic-settings

相关问题