我把雅虎的股票价格数据保存在price_data数据字典中,我想用它生成一些基本的时间序列图。
我试过在这里使用一些其他的答案,但是我最终得到了一些混乱的结果。例如,x轴不能从this one中正确显示。
从dataframe price_data['AAPL']__生成price_data['AAPL']列的时间序列并将结果保存到png文件的最简洁的方法是什么?
下面是一些有关这个dataframe的结构的信息:
In [41]: type(price_data['AAPL'])
Out[41]: pandas.core.frame.DataFrame
In [42]: list(price_data['AAPL'].columns.values)
Out[42]: ['Open', 'High', 'Low', 'Close', 'Volume', 'Adj Close']
In [45]: type(price_data['AAPL'].index)
Out[45]: pandas.tseries.index.DatetimeIndex发布于 2015-04-30 08:56:57
您需要将日期列设置为时间戳,并将其设置为索引。
In [829]: temp
Out[829]:
Date Open High Low Close Volume Adj
0 19/10/11 27.37 27.47 27.01 27.13 42880000 27.13
1 18/10/11 26.94 27.40 26.80 27.31 52487900 27.31
2 17/10/11 27.11 27.42 26.85 26.98 39433400 26.98
3 14/10/11 27.31 27.50 27.02 27.27 50947700 27.27
In [830]: temp['Date'] = pd.to_datetime(temp['Date'])
In [831]: temp
Out[831]:
Date Open High Low Close Volume Adj
0 2011-10-19 27.37 27.47 27.01 27.13 42880000 27.13
1 2011-10-18 26.94 27.40 26.80 27.31 52487900 27.31
2 2011-10-17 27.11 27.42 26.85 26.98 39433400 26.98
3 2011-10-14 27.31 27.50 27.02 27.27 50947700 27.27然后,这会让你得到一个阴谋:
In [832]: temp.set_index('Date')['Adj'].plot()https://stackoverflow.com/questions/29958511
复制相似问题