您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何将日期时间格式转换为分钟-pandas

如何将日期时间格式转换为分钟-pandas

使用total_secondsseconds除以60,最后转换为integers:

#if necessary converting to timedelta
#df['usage_duration'] = pd.to_timedelta(df['usage_duration'])

df['new'] = df['usage_duration'].dt.total_seconds().div(60).astype(int)

要么:

 df['new'] = (df['usage_duration'].dt.seconds.div(60).astype(int) 
             + df['usage_duration'].dt.days.multiply(1440).astype(int) )

print (df)
   processid userid  usage_duration   new
0      17613   root 0 days 23:41:03  1421
1      17641   root 2 days 04:05:26  3125
2      13848    acs 0 days 00:00:50     0
3       3912    acs 0 days 06:07:38   367
4       6156    acs 0 days 17:22:43  1042
其他 2022/1/1 18:52:08 有439人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶