以DateTime格式导入excel数据以熊猫DF并转换为秒
我正在尝试使用DateTime格式将Excel数据导入PANDAS DF。数据是由Porgram生成的导出文件跟踪工作时间。我的代码工作正常,但我刚刚意识到,我从以为我的导入文件始终包含以下格式:
任务 | 持续时间 |
---|---|
第一个 | 1900-01-01 22:21:20 |
SECTEN | 1900-01-01-01 12:13:14 |
我没有每当持续时间超过24小时时,'t意识到持续时间开始显示日期为'1900-01-01'。 “持续时间”超过48小时等等。
- '每当
- 持续时间切换到日期:' 1900-01-02 持续时间为28小时,该单元的值显示:'1900-01-01 04:00:00
- 持续时间为50小时,单元格的值显示:'1900-01-02 02:00:00
我现在需要一个将此格式转换为秒数的代码。在我意识到错误之前,我已经使用了“ pd.to_timedelta”。我没有找到从TimeDELTA文档中直接进行操作的方法。
i'm trying to import excel data to a pandas df with datetime format. The data is an export file generated by a porgram to track worktime. My code works fine but i just realised, that i started from thinking that my import file always contains the following format:
Task | Duration |
---|---|
First | 1900-01-01 22:21:20 |
Second | 1900-01-01 12:13:14 |
I didn't realise that the Duration starts showing the Date '1900-01-01' whenever the Duration exceeds 24 Hours. The Duration switches to the Date: '1900-01-02' whenever the 'Duration' exceeds 48 hours and so on...
- When the Duration is 6 Hours the value of the cell shows: '06:00:00'
- When the Duration is 28 Hours the value of the cell shows: '1900-01-01 04:00:00
- When the Duration is 50 Hours the value of the cell shows: '1900-01-02 02:00:00
I now need a piece of code to convert this format to seconds as an integer. I've used 'pd.to_timedelta' for this before i realised my mistake but i've always cleared out the date before calculating the total seconds. I didn't find a way to do it straight from the timedelta documentation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
IIUC使用如果输入值以格式
HH:MM:SS
:IIUC use if input values are in format
HH:MM:SS
:如果
Duration
没有日期部分,请添加前缀,然后计算日期时间和原点 (1899-12-31) 之间的差异。输出:
Add a prefix if the
Duration
has no date part then compute the difference between datetime and origin (1899-12-31).Output: