2017-06-29 596 views
3

由於某些原因,重新採樣爲24H或1D從DateTimeIndex打印時間。Python Dataframe.resample()從日期時間索引中刪除時間

我使用 蟒蛇:3.5.3 /暢達 numpy的:1.11.3 大熊貓:0.20.2

df = pd.read_csv(inFile, parse_dates=True) 

print(df.head()) 
df = df.resample("1D").agg({'open':'first','high':'max','low' :'min','close': 'last','volume': 'sum'}).dropna() 

print(df.head() 

首先print語句

enter image description here

enter image description here

+0

你的期望是什麼?對我來說這似乎很正常。 – ayhan

+0

如果您檢查索引,則會在重新採樣時看到它的freq屬性從None更改爲'D'。它在2年前的這個答案中有所解釋,並且看起來並不像它可以改變(至少從2年前開始)https://stackoverflow.com/questions/27607974/python-pandas-dataframe-以編程方式任意設置頻率在任何情況下,請注意這是一個顯示問題,索引類型沒有更改。 – JohnE

+0

@ayhan - 我想看到打印時間(00:00:00) – TaeWoo

回答

0

想出來

df.index = pd.to_datetime(df.index.format(formatter=lambda x: x.strftime('%Y-%m-%d %H:%M:%S'))) 
+0

您確定這是否適合?它不適合我。 – JohnE