[英]how to convert multiple date formats in one format in pandas
I have following pandas dataframe with date column as object
我有以下pandas数据帧与日期列作为
object
ID Date Volume
0 13-02-2018 00:06 85
1 13-02-2018 00:10 70
2 13-02-2018 00:11 100
3 2018-02-13 06:30 123
4 02-13-2018 07:56 100
I want to convert it to following one format 我想将其转换为以下格式
ID Date Volume
0 2018-02-13 00:06 85
1 2018-02-13 00:10 70
2 2018-02-13 00:11 100
3 2018-02-13 06:30 123
4 2018-02-13 07:56 100
I am trying to achieve this by following command 我试图通过以下命令实现这一目标
df['Date'] = df.date.apply(lambda x: pd.to_datetime(x).strftime('%Y-%m-%d %H:%M')[0])
But it throws an error. 但它会引发错误。 How can I do it in pandas?
我怎么能在熊猫里做到这一点?
try this: 试试这个:
df['Date'] = pd.to_datetime(df.Date)
df['Date'] = df['Date'].dt.strftime('%Y-%m-%d %H:%M')
link: Series.dt.strftime 链接: Series.dt.strftime
Import time 进口时间
Localtime= time.asctime(time.localtime(time.time()))
Print(localtime)
Check if this we work 检查我们是否有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.