我正在尝试使用Flask将熊猫绘制到网络上。我认为我走在正确的轨道上,但是我在努力争取把日期放到x轴上的日期。
对于y轴数据,它很容易:
aapl = pd.io.data.get_data_yahoo('AAPL', start=datetime.datetime(2006, 10, 1), end=datetime.datetime(2012, 1, 1))
all_close = appl['Close'][10:]
for close in all_close:
y.append(close)
很容易。但是似乎没有办法知道返回的对象的日期
数据框如下所示:
Open High Low Close Volume Adj Close
Date
2006-10-02 75.10 75.87 74.30 74.86 25451400 72.38
2006-10-03 74.45 74.95 73.19 74.08 28239600 71.63
2006-10-04 74.10 75.46 73.16 75.38 29610100 72.89
2006-10-05 74.53 76.16 74.13 74.83 24424400 72.35
2006-10-06 74.42 75.04 73.81 74.22 16677100 71.76
有人知道我要怎么约会吗?
谢谢
日期是您的DataFrame的索引。您可以按以下方式简单地访问它:
df.index
香草的例子
In [13]: index = pd.DatetimeIndex(start='2012', end='2013', freq='1D')
In [14]: index
Out[14]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2012-01-17 00:00:00, ..., 2013-01-17 00:00:00]
Length: 367, Freq: D, Timezone: None
In [15]: df = pd.DataFrame(np.random.randn(len(index),1), index=index)
In [16]: df
Out[16]:
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 367 entries, 2012-01-17 00:00:00 to 2013-01-17 00:00:00
Freq: D
Data columns (total 1 columns):
0 367 non-null values
dtypes: float64(1)
In [17]: df.index
Out[17]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2012-01-17 00:00:00, ..., 2013-01-17 00:00:00]
Length: 367, Freq: D, Timezone: None
这也适用于其他类型的索引。
如果您要查找特定于DatetimeIndex的内容,则可以在此处找到有关时间序列的更多详细信息。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句