2017-06-29 145 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