我有一个包含datetime列的Pandas数据帧,其中所有值的格式如下:25/09/15 12:00:00。我想在所有行中重新格式化这个字段,以便匹配以下格式:25.09.15 12:00。
下面是一些示例数据:
Date | Value
25/08/15 12:00:00 | 49.0
25/08/15 13:00:00 | 49.5日期列数据类型为字符串。
提前谢谢你
发布于 2020-03-24 17:26:51
使用Series.dt.strftime格式化日期时间
df
Date Value
0 2015-08-25 12:00:00 49.0
1 2015-08-25 13:00:00 49.5
df['Date'] = df['Date'].dt.strftime('%Y.%m.%d %H:%M')
df
Date Value
0 2015.08.25 12:00 49.0
1 2015.08.25 13:00 49.5如果列类型为str,则需要首先转换为datetime
df.Date = pd.to_datetime(df.Date)https://stackoverflow.com/questions/60828013
复制相似问题