【发布时间】:2022-11-15 17:31:37
【问题描述】:
尝试使用 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())
笔记(只是为了澄清):- df 是从 csvfile 读取的数据帧的名称。
例如:-
import pandas as pd
df = pd.read_csv('Data.csv')
print(df.corr())
问题只要在于引发上述错误的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.
我部分理解该错误,但我想知道:
是否有任何其他替代方法可以执行
corr()的相同功能来识别数据集中每一列之间的关系?就像有没有一种方法可以在不使用的情况下复制该功能corr()方法?抱歉,如果我的问题无论如何是错误的或不恰当的,我愿意接受反馈。
提前致谢。
【问题讨论】:
-
您还有其他原因要避免使用
corr方法吗?因为它一般不被弃用,只有其numeric_only参数的默认值。使用df.corr(numeric_only = True)(或False,取决于需要)应该可以消除警告。 -
好的,谢谢...除了在我的代码中引发错误之外,我没有任何其他理由避免它。
-
您应该编辑帖子并添加代码以获得更好的帮助。
-
问题不在于我的代码,而在于一种方法 - corr 方法
-
但是@matszwecja 的评论解决了我的问题..我想结束这个问题。
标签: python pandas future-warning