我使用Python的Pandas從Yahoo Finance獲得一些財務數據,這是pandas_datareader的內置功能。我想訪問它打印出的日期,但它似乎並沒有在列,也不在我需要,但JSON是那裏當我打印出來的對象:如何訪問Pandas的DataReader中的日期行?
from pandas_datareader.data import DataReader
import datetime
start = datetime.datetime(2015, 6, 1)
goog = DataReader('GOOGL', 'yahoo', start)
goog.to_json(None, orient="records") # this doesn't include dates!
print(goog) # this prints out the dates along with the other data!
print(goog.columns) # prints every column except the date column
我怎麼能包括沿日期與JSON字符串中的其他數據?
有沒有一種優雅的方式來合併列表與數據的重置,所以我可以更容易地導出到JSON? – nico
@ Guy3000更好? – bananafish
reset_index()完全解決了我的問題,但這肯定是朝着正確方向邁出的第一步,謝謝! – nico