python - how to deal quotes_historical_yahoo date time? -
i try use matplotlib.finance download data yahoo finance.
from matplotlib.finance import quotes_historical_yahoo datetime import date import pandas pd import numpy np %matplotlib inline today=date.today() start=(today.year-1,today.month,today.day) quotes=quotes_historical_yahoo('axp',start,today) df=pd.dataframe(quotes,columns=['date','open','high','low','close','vol']) df
the result
date open high low close vol 0 735536 87.376999 87.524947 88.264678 86.992340 5069300 1 735537 88.708520 88.718378 89.359479 88.146325 6848600 2 735540 89.083316 89.606057 89.961129 88.984686 3707900
i know first column should date, don't know how date time it. how deal column make "2011-01-01"
?
i solve myself, key date.fromordinal()
+date.strftime(x,'%y-%m-%d')
today=date.today() start=(today.year-1,today.month,today.day) quotes=quotes_historical_yahoo('axp',start,today) fields=['date','open','high','low','close','vol'] list1=[] in range(0,len(quotes)): x=date.fromordinal(int(quotes[i][0])) y=date.strftime(x,'%y-%m-%d') list1.append(y) df = pd.dataframe(quotes,index=list1,columns=fields) df=df.drop(['date'],axis=1)
Comments
Post a Comment