imledger 发表于 2019-6-5 22:12:24

'DataFrame' object has no attribute 'close'这是什么问题?

# 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(, 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)


结果出现错误,为什么呢?
结果如下
##Traceback (most recent call last):
File "C:/Users/fm-hbs/Desktop/test.py", line 16, in <module>
    df = pd.concat(, 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'

Seawolf 发表于 2019-6-6 02:22:08

错误在这一行,df = pd.concat(, axis =1, keys=['df_qjd.close', 'df_gm.close'])#合并,根据他的提示应该是close这个属性没有匹配上

imledger 发表于 2019-6-6 08:37:42

Seawolf 发表于 2019-6-6 02:22
错误在这一行,df = pd.concat(, axis =1, keys=['df_qjd.close', 'df_gm.close ...

怎么修改呢?

Seawolf 发表于 2019-6-6 21:59:18

一是检查一下两个dataFrame里的close ,二是查一下df_qjd.close,df_gm.close这两个参数属不属于dataFrame类型
页: [1]
查看完整版本: 'DataFrame' object has no attribute 'close'这是什么问题?