问题描述
尝试使用 pg.pairwise_corr 方法时出现以下错误:
pg.pairwise_corr(df)
/usr/local/lib/python3.7/dist-packages/pingouin/correlation.py in corr(x,y,tail,method,**kwargs)
507 x = np.asarray(x)
508 y = np.asarray(y)
--> 509 assert x.ndim == y.ndim == 1,'x and y must be 1D array.'
510 assert x.size == y.size,'x and y must have the same length.'
511
AssertionError: x and y must be 1D array.
我尝试了这个功能,只选择了这样的一列
pg.pairwise_corr(df,columns='col')
并得到同样的错误。
事实上,我的数据帧的所有列都具有相同的长度。 (它对于另一个数据框工作得非常好)。不过我用pd.concat的方法连接了一些文件,但是这个应该不管对象到底是data.frame还是data.frame?
多谢指教!!
解决方法
同时我解决了我的问题。
之后
df = pd.concat([df_part1,df_part2],axis=1)
我将 df 保存为 .csv 文件。然后我再次使用
读入dfdf = pd.read_csv('path/to/file',index=false)
像这样,函数
pg.pairwise_corr(df)
工作正常。