【发布时间】:2018-09-26 20:41:36
【问题描述】:
我知道这篇文章无法复制,因为数据是我在本地读取的 CSV 格式,但如果有用的话,我可以将数据发布到 github 帐户。我试图先找到相关性:
ng = pd.read_csv('C:/Users/me/Desktop/ngDataBaseline.csv', index_col='Date', parse_dates=True)
ng.head()
这将返回两列:
HDD Therm
Date
2011-05-01 347 3,506
2011-06-01 74 1,237
2011-07-01 0 139
2011-08-01 0 35
2011-09-01 154 170
但如果我这样做:
ng['HDD'].corr(ng['Therm'])
我收到关于 unsupported operand type(s) for /: 'str' and 'int' 的错误
这对我来说没有意义,因为我认为应该都是熊猫系列。
如果我执行print(type(ng['HDD'])),Ipython 将输出<class 'pandas.core.series.Series'>
与print(type(ng['Therm'])) 一样,为什么我不能关联数据?
【问题讨论】:
-
'Therm' 是一个字符串。查看列中的逗号。
-
'Therm' 列被读取为字符串而不是浮点数(因为它包含逗号)。如果你做过
ng.info(),你会看到的。这个有很多重复。