将奇数时间格式转换为小时 [英] Convert odd time format to hours

查看:99
本文介绍了将奇数时间格式转换为小时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,最简单的将日期格式为 2017-01-01T19的日期重新格式化的方法是: 33:28 + 0000

Hello, what's the easiest way to reformat a date that looks like "2017-01-01T19:33:28+0000"

例如,该日期表示2017年1月1日,晚上7:33:28。

For example, that date means January 1st, 2017, at 7:33:28pm.

我只对删除月份,日期和年份以及保持小时和分钟感兴趣。

I'm interested in removing the month, day, and year, and keeping hour and minutes only.

在我查看的数据中,用户的软件命令全部发生在同一天,时间超过2小时(从晚上7点到晚上9点)。 (查看图片)

In the data I'm looking at, users' software commands take place all on the same day, over 2 hours (7pm to 9pm). (See image)

我想重新格式化时间,以方便地分析这两个小时内的命令分布。

Python或r的建议?也许是为了间隔时间?

Suggestions for either Python or r? Maybe for making time intervals?

更新我要使用下面发布的解决方案

Update I want to use the posted solution below


从datetime导入datetime

from datetime import datetime

x = datetime.strptime('2017-01-01T19:33:28 + 0000',
'%Y- %m-%dT%H:%M:%S%z')\
.strftime('%H:%M')

x = datetime.strptime('2017-01-01T19:33:28+0000', '%Y-%m-%dT%H:%M:%S%z')\ .strftime('%H:%M')

但是,我只能对列中的一个值执行此操作。您如何将其应用于整个列中的所有值?

However I can only do this for one value in a column. How do you apply it to all values in an entire column?

要转换的列值

谢谢!

推荐答案

这是使用 datetime 的Python解决方案,该解决方案属于标准库:

This is a Python solution using datetime, which belongs in the standard library:

from datetime import datetime

x = datetime.strptime('2017-01-01T19:33:28+0000', '%Y-%m-%dT%H:%M:%S%z')\
            .strftime('%H:%M')

# '19:33'

这篇关于将奇数时间格式转换为小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆