python - 如何在 Pandas 中对日期时间列进行分组?
问题描述
我想将我的日期时间列数据分为 4 个组,命名为: 12AM-06 AM,06 AM-12PM,12PM-18PM,18PM-12AM 。我怎样才能做到这一点?
Time_Interval
0 00:00:00
1 00:00:00
2 06:00:00
3 12:00:00
4 12:00:00
...
209526 18:00:00
209527 00:00:00
209528 06:00:00
209529 12:00:00
209530 12:00:00
起初我试图将日期时间转换为对象,但得到了这个错误:只能使用带有类似日期时间值的 .dt 访问器这是我的代码:
df['Time_Interval'] = df['Time_Interval'].dt.strftime('%H:%M:%S')
什么是最好的解决方案?
解决方案
推荐阅读
- android - 无法使用 JobIntentService 安排警报
- java - Spring Boot 应用程序端点返回 403
- mysql - 如何应用约束和使用 NO Action 规则意味着不采取任何行动
- python - 无法将 JSON 放入 InfluxDB
- powerbi - 我们能否在没有 Microsoft Azure 的情况下在 Web 应用程序中创建 Power BI Embedded 仪表板/报告?
- python - 如何在单个 ZMQ 发送请求中同时发送图像(ndarray)和字符串数据
- postfix-mta - 配置 Postfix 以在 ubuntu 上发送电子邮件
- php - 如何在 Laravel 中同时保存两个模型?
- ios - 通过 iOS 使用 Sylius API
- javascript - Firebase 托管部署错误“HTTP 错误:404,未找到”