TypeError:corr()缺少1个必需的位置参数:"other" [英] TypeError: corr() missing 1 required positional argument: 'other'
问题描述
我是python的新手,碰壁了.我应该计算皮尔逊相关系数,但是我有错误.我唯一能想到的是python需要不同的语法.
I am new to python and have hit a wall. I should count pearson correlation coefficient, but I have error. The only thing I can think of is that python requires different syntax.
import pandas
import numpy as np
data = pandas.read_csv('One_imortant_table.csv', index_col='Id')
corr1 = data['Numb'].corr(method='pearson', min_periods=1)
print(corr1)
TypeError:
TypeError:
---> corr1 = data['Numb'].corr(method='pearson', min_periods=1)
TypeError: corr() missing 1 required positional argument: 'other'
我在这里做错了什么?我已经搜索了这个错误,但是找不到更多.我正在将Windows 10与最新版本的python一起使用,并以Jupyter进行编码.
What am I doing wrong here? I have searched for this mistake, but can't find any more. I am using windows 10 with the latest version of python, coding in Jupyter.
推荐答案
应该在两列之间计算相关性.参数其他"是应使用的第二列.例如,您可以执行以下操作:
Correlation should be calculated between two columns. The argument 'other' is the second column that should be used. For example, you could do something like that:
import pandas
import numpy as np
data = pandas.DataFrame({'Numb':[1,2,3],'a':[7,8,9]})
corr1 = data['Numb'].corr(data['a'],method='pearson', min_periods=1)
print(corr1)
这将打印1.0
这篇关于TypeError:corr()缺少1个必需的位置参数:"other"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!