pandas df.corr()返回NaN,尽管数据已填充 [英] pandas df.corr() returns NaN despite data fed having populated data

查看:295
本文介绍了pandas df.corr()返回NaN,尽管数据已填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据如下:

print data

                   A                B 
2014-04-04        163.24         191.77
2014-06-11        165.43         182.25
2014-12-22        194.44         161.44
2014-03-25        163.25         195.04
2014-11-03        190.83         164.36
2014-06-16        165.85         182.35
2014-11-24        190.07         162.15
2014-05-21        159.35         186.39
2015-01-21        177.15         152.09
2014-08-28        177.65         192.00
2014-02-19        163.26         182.95
2014-05-12        159.55         192.57
2014-07-09        164.67         188.42
2015-02-26        192.20         160.87
2014-10-14        178.70         183.80
2014-07-16        170.47         192.36
2014-01-21        173.20         188.43
2014-06-03        161.80         184.37
2014-03-17        166.84         185.81
2014-08-11        172.46         187.47
2015-01-07        187.28         155.05
2014-05-29        160.74         183.76
2015-02-11        187.65         158.20
2014-02-27        165.38         185.27
2015-01-05        188.34         159.51
2014-07-01        166.81         186.35
2015-02-18        188.67         162.19
2014-04-03        166.09         192.69
2014-10-06        187.48         189.04
2014-12-29        196.19         160.51

当我尝试呼叫data.corr()时,我会退回所有NaN.我在excel中对此进行了测试,确实可以计算出相关性.

When I try to call data.corr() I receive back all NaN. I tested this in excel, and the correlation is indeed able to be calculated.

知道为什么会这样吗?

我很乐意发布更多内容,但不确定会有所帮助.

I am happy to post more but i am unsure what would help.

print data.info()

<class 'pandas.core.frame.DataFrame'>
Index: 298 entries, 2014-04-04 to 2014-01-29
Data columns (total 2 columns):
A     298 non-null float64
B    298 non-null float64
dtypes: float64(2)None



print data.describe()
              A                B
    count    298.000000     298.000000
    mean     175.152886     178.596242
    std       11.490668      13.709316
    min      152.720000     151.410000
    25%      165.502500     162.655000
    50%      175.480000     184.330000
    75%      185.085000     189.692500
    max      196.890000     197.770000


print pd.version
0.14.1

推荐答案

Jason,使用示例数据对我来说很好.

Jason, Using the sample data it works fine for me.

data.corr()
    A   B
A   1.000000    -0.779864
B   -0.779864   1.000000

我在您的data.info()中注意到dtype上贴有'None'.当我加载样本数据时,我得到了

I noticed in your data.info() there is a 'None' tacked on to dtypes. When I load your sample data I get

data.info()
<class 'pandas.core.frame.DataFrame'>
Index: 30 entries, 2014-04-04 to 2014-12-29
Data columns (total 2 columns):
A     30 non-null float64
B     30 non-null float64
dtypes: float64(2)

我想是什么原因导致无"导致您的问题.

I imagine what's causing that 'None' is causing your problem.

希望这可以帮助[希望我可以留下评论,但还没有声誉!]

Hope this helps [wish I could leave as a comment but don't have the reputation yet!]

这篇关于pandas df.corr()返回NaN,尽管数据已填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆