尝试使用 pandas 模块在 python 中运行 ```corr()``` 时出错

Eli*_*101 7 python pandas future-warning

当尝试使用 pandas 模块在 python 中运行该corr()方法时,出现以下错误:

FutureWarning: The default value of numeric_only in DataFrame.corr is deprecated. In a future version, it will default to False. Select only valid columns or specify the value of numeric_only to silence this warning.
  print(df.corr())
Run Code Online (Sandbox Code Playgroud)

注意(只是为了澄清):-df是从 a 读取的数据帧的名称csv

例如:-

import pandas as pd

df = pd.read_csv('Data.csv')
print(df.corr())
Run Code Online (Sandbox Code Playgroud)

问题在于corr()引发上述错误的方法:

FutureWarning: The default value of numeric_only in DataFrame.corr is deprecated. In a future version, it will default to False. Select only valid columns or specify the value of numeric_only to silence this warning.
Run Code Online (Sandbox Code Playgroud)

我部分理解该错误,但我想知道:

是否有其他替代方法可以执行相同的功能corr()来识别数据集中每列之间的关系?就像有没有一种方法可以在不使用方法的情况下复制函数 corr()

抱歉,如果我的问题是错误或不恰当的,我愿意接受反馈。

提前致谢。

小智 8

问题仅在于一个函数corr()未被弃用,但该numeric_only函数中的参数已被弃用。因此,您可以根据需要将其设置为 false 或 true df.corr(numeric_only = *[True/False]*)您可以在其文档中了解更多信息。

ps - 我这样写是为了更容易理解,而且事实上这个问题对我来说是众所周知的。