Python 为什么我在找出数据帧中一个变量和所有其他变量的相关性时出错

Python 为什么我在找出数据帧中一个变量和所有其他变量的相关性时出错,python,pandas,correlation,Python,Pandas,Correlation,考虑以下数据集(导入为df): 我想做的是找出印度卢比和所有其他货币的相关性,为此,我尝试使用以下python代码: df['Indian Rupee'].corr(~df['Indian Rupee']) 上面抛出了一个错误: TypeError: ufunc 'invert' not supported for the input types, and the inputs could not be safely coerced to any supported types accordi

考虑以下数据集(导入为df):

我想做的是找出
印度卢比
和所有其他货币的相关性,为此,我尝试使用以下python代码:

df['Indian Rupee'].corr(~df['Indian Rupee'])
上面抛出了一个错误:

TypeError: ufunc 'invert' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
我想了解为什么会出现上述错误?为什么我不能通过这种方式找到相关性?


这里有什么选择?

一个选择是对整个数据帧进行关联,然后只选择您关心的列

df.corr()['Indian Rupee']

ChineseYuan          0.304050
Euro                 0.243851
JapaneseYen         -0.270123
U.K.PoundSterling    0.314681
U.S.Dollar           0.872862
IndianRupee          1.000000
Name: IndianRupee, dtype: float64

一种选择是对整个数据帧进行关联,然后只选择您关心的列

df.corr()['Indian Rupee']

ChineseYuan          0.304050
Euro                 0.243851
JapaneseYen         -0.270123
U.K.PoundSterling    0.314681
U.S.Dollar           0.872862
IndianRupee          1.000000
Name: IndianRupee, dtype: float64

~
是按位求反运算符。可以对布尔值(级数)或整数(级数)求反。你不能否定浮点数系列,这是不安全的

换句话说,
~df['Indian rupe']
不会为您排除其他列。如果要删除,请使用:

df.drop('Indian Rupee', axis=1)
所以你可以

df.drop('Indian Rupee', axis=1).corrwith(df['Indian Rupee'])
输出:

Chinese Yuan           0.267802
Japanese Yen          -0.270123
U.K. Pound Sterling    0.197496
U.S. Dollar            0.846584
dtype: float64

~
是按位求反运算符。可以对布尔值(级数)或整数(级数)求反。你不能否定浮点数系列,这是不安全的

换句话说,
~df['Indian rupe']
不会为您排除其他列。如果要删除,请使用:

df.drop('Indian Rupee', axis=1)
所以你可以

df.drop('Indian Rupee', axis=1).corrwith(df['Indian Rupee'])
输出:

Chinese Yuan           0.267802
Japanese Yen          -0.270123
U.K. Pound Sterling    0.197496
U.S. Dollar            0.846584
dtype: float64

谢谢你给我解释这个:)谢谢你给我解释这个:)