Python:在数据框中将timedelta转换为int [英] Python: Convert timedelta to int in a dataframe

查看:836
本文介绍了Python:在数据框中将timedelta转换为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在pandas数据框中创建一列,该列是timedelta列中天数的整数表示.是否可以使用"datetime.days",还是我需要做更多手动操作?

I would like to create a column in a pandas data frame that is an integer representation of the number of days in a timedelta column. Is it possible to use 'datetime.days' or do I need to do something more manual?

timedelta列

7天23:29:00

7 days, 23:29:00

天整数列

7

推荐答案

使用

Use the dt.days attribute. Access this attribute via:

timedelta_series.dt.days

您还可以通过相同的方式获取secondsmicroseconds属性.

You can also get the seconds and microseconds attributes in the same way.

这篇关于Python:在数据框中将timedelta转换为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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