我想访问熊猫数据透视表的“日期/索引”列,然后将日期用作matplotlib轴以面向对象的方式绘制股票数据,我正在尝试弄清楚如何将日期变成自己的日期宾语?谢谢
import pandas as pd
import yfinance as yf
amazon = yf.download('amzn','2000-01-01','2019-09-26')
amazon.head()
Open High Low Close Adj Close Volume
Date
2000-01-03 81.50 89.56 79.05 89.38 89.38 16117600
2000-01-04 85.38 91.50 81.75 81.94 81.94 17487400
2000-01-05 70.50 75.12 68.00 69.75 69.75 38457400
2000-01-06 71.31 72.69 64.00 65.56 65.56 18752000
2000-01-07 67.00 70.50 66.19 69.56 69.56 10505400
答案 0 :(得分:1)
您可以使用amazon.index
:
print (amazon.index)
DatetimeIndex(['1999-12-31', '2000-01-03', '2000-01-04', '2000-01-05',
'2000-01-06', '2000-01-07', '2000-01-10', '2000-01-11',
'2000-01-12', '2000-01-13',
...
'2019-09-12', '2019-09-13', '2019-09-16', '2019-09-17',
'2019-09-18', '2019-09-19', '2019-09-20', '2019-09-23',
'2019-09-24', '2019-09-25'],
dtype='datetime64[ns]', name='Date', length=4965, freq=None)
但是如果以大熊猫为食,例如由Series.plot
撰写:
amazon['Open'].plot()