马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
# coding=gbk
import matplotlib.pyplot as plt #提供类matlab里绘图框架
import numpy as np
import pandas as pd
import tushare as ts
#获取数据
s_qjd = '002186' #全聚德
s_gm = '600597' #光明乳业
sdate = '2019-01-01'#起止日期
edate = '2019-05-31'
df_qjd = ts.get_h_data(s_qjd, start = sdate, end = edate).sort_index(axis = 0,ascending=True)#获取历史数据
df_gm = ts.get_h_data(s_gm, start = sdate, end = edate).sort_index(axis = 0,ascending=True)
df = pd.concat([df_qjd.close,df_gm.close], axis =1, keys=['df_qjd.close', 'df_gm.close'])#合并
df.ffill(axis=0, inplace=True)#填充缺失数据
df.to_csv('qjd_gm.csv')
#pearson方法计算相关性
corr = df.corr(method = 'pearson', min_periods = 1)
print(corr)
结果出现错误,为什么呢?
结果如下
[Getting data:]#[Getting data:]#Traceback (most recent call last):
File "C:/Users/fm-hbs/Desktop/test.py", line 16, in <module>
df = pd.concat([df_qjd.close,df_gm.close], axis =1, keys=['df_qjd.close', 'df_gm.close'])#合并
File "C:\Users\fm-hbs\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\generic.py", line 4376, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'close'
|