从pandas数据框中删除日期时间戳

12 浏览
0 Comments

从pandas数据框中删除日期时间戳

场景:我有一个从Excel工作表中检索到的包含多列的数据框。其中一些列是日期,其中一些值是日期(yyyy:mm:dd),而另一些是日期时间(yyyy:mm:dd 00.00.000000)。

问题:当日期不是数据框的索引时,我如何删除日期中的时间戳?

我已经尝试过的方法:从这里的其他帖子中(working with dates in pandas - remove unseen characters in datetime and convert to stringHow to strip a pandas datetime of date, hours and seconds)中,我找到了以下方法:

pd.DatetimeIndex(dfST['timestamp']).date

strfitme (df['timestamp'].apply(lambda x: x.strftime('%Y-%m-%d'))

但我似乎找不到在所需列不是数据框索引时如何直接使用这些方法的办法。

0