【问题标题】:pg.pairwise_corr error: x and y must be 1D arraypg.pairwise_corr 错误:x 和 y 必须是一维数组
【发布时间】:2021-04-04 17:53:07
【问题描述】:

尝试使用 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 时,这应该无关紧要吗?

感谢您的建议!

【问题讨论】:

    标签: python correlation pingouin


    【解决方案1】:

    同时我解决了我的问题。

    之后

    df = pd.concat([df_part1, df_part2], axis=1) 
    

    我将 df 保存为 .csv 文件。然后我再次阅读 df 使用

    df = pd.read_csv('path/to/file', index=false)
    

    这样,函数

    pg.pairwise_corr(df)
    

    工作正常。

    【讨论】:

      猜你喜欢
      • 2020-05-10
      • 2021-06-05
      • 1970-01-01
      • 2017-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-20
      相关资源
      最近更新 更多