python - 将字符串转换为不带日期的 pandas 时间戳
问题描述
我应该如何将时间 '14:12:2006' 、 '1200' 和 '1500' 转换为 pandas 日期时间,只有时间部分,以便我可以检查第一次是否在其他两个时间之间。
我正在寻找的是:
12:00 < 14:12:2006 < 15:00
我只需要转换,而不是比较。
解决方案
如果您只需要比较它们,您可以使用
s=pd.Series(['14:12:2006' , '1200' , '1500']).str.replace(':','').astype(str)
s=s.str.ljust(s.str.len().max(),'0').astype(int)
s.iloc[1]<s.iloc[0]<s.iloc[2]
True
s
0 14122006
1 12000000
2 15000000
dtype: int64
推荐阅读
- javascript - Json 对象在 IE11 中未正确获取
- state - 有没有像 Svelte 3 的 Vuex 之类的东西?
- node.js - 可能很简单:MongoDB 连接到数据库,但不向其中添加项目
- python - 持久 CPLEX - 模块 cplex 没有属性 cplex
- python - Tkinter entry.get() 仅适用于每 2 次按钮点击
- java - java.lang.NoClassDefFoundError: org/apache/htrace/core/HTraceConfiguration
- php - 使用主管运行队列工作者时,Laravel 作业无法在 /tmp/ 中找到文件
- r - 在 SVM 中使用 tune.svm() 函数和交叉验证技术
- html - 如何创建复制文本链接?
- c - sqlite3_bind_text() 不绑定占位符