我正在这样导入我的数据:
new=pd.read_csv('/My Drive/DYZ2013.txt')
new.columns = new.columns.str.replace(' ', '')
new.index = pd.to_datetime(new.Date + ' ' + new.Time)
new['Date'] = pd.to_datetime(new.Date)
new['Time'] = pd.to_datetime(new['Time'], format=' %H:%M:%S.%f').dt.time
数据如下:
Date Time Close
2013-01-04 07:00:00.000 2013-01-04 07:00:00 7846
2013-01-04 07:00:00.100 2013-01-04 07:00:00.100000 7846
2013-01-04 07:00:00.200 2013-01-04 07:00:00.200000 7846
2013-01-04 07:00:00.300 2013-01-04 07:00:00.300000 7846
2013-01-04 07:00:00.400 2013-01-04 07:00:00.400000 7846
2013-01-04 07:00:00.500 2013-01-04 07:00:00.500000 7846
2013-01-04 07:00:00.600 2013-01-04 07:00:00.600000 7846
2013-01-04 07:00:00.700 2013-01-04 07:00:00.700000 7846
2013-01-04 07:00:00.800 2013-01-04 07:00:00.800000 7846
2013-01-04 07:00:00.900 2013-01-04 07:00:00.900000 7846
2013-01-04 07:00:00.100 2013-01-04 07:00:00.100000 7846
2013-01-04 07:00:00.110 2013-01-04 07:00:00.110000 7846
2013-01-04 07:00:00.120 2013-01-04 07:00:00.120000 7846
2013-01-04 07:00:00.130 2013-01-04 07:00:00.130000 7846
2013-01-04 07:00:00.140 2013-01-04 07:00:00.140000 7846
2013-01-04 07:00:00.150 2013-01-04 07:00:00.150000 7846
2013-01-04 07:00:00.160 2013-01-04 07:00:00.160000 7846
,并尝试使用以下代码绘制时间序列时:
plt.figure(figsize=(14, 5), dpi=100)
plt.plot(new['Time'], new['Close'], label='price')
plt.vlines(datetime.date(2016,4, 20), 0, 270, linestyles='--', colors='gray', label='Train/Test data cut-off')
plt.xlabel('Date_ Time')
plt.ylabel('USD')
plt.title('Figure 2: price')
plt.legend()
plt.show()
我遇到错误:
AttributeError:“ DataFrame”对象没有属性“ date”
如何使用索引或任何其他日期和时间来绘制数据?