2017-02-22 108 views
1

我創建了一個數據幀。在IPython中運行一些命令我得到如下結果:將pandas DataFrame索引轉換爲時間戳格式

In [5]: df.tail() 
Out[5]: 
       open  high  low close volume 
date               
2017-02-22 15:00 1.05131 1.05137 1.05074 1.05075  543 
2017-02-22 15:30 1.05074 1.05165 1.05072 1.05139  506 
2017-02-22 16:00 1.05137 1.05193 1.05121 1.05141  488 
2017-02-22 16:30 1.05144 1.05205 1.05056 1.05065  747 
2017-02-22 17:00 1.05061 1.05167 1.04988 1.04997  753 

In [6]: df.index[0] 
Out[6]: '2011-11-21 14:30' 

In [7]: type(df.index[0]) 
Out[7]: str 

正如你看到的,該指數是在海峽的格式,但我需要它是在時間戳格式。可能嗎?

回答

3

試試這個

df.index = pd.to_datetime(df.index) 
相關問題