Python:在数据框中将timedelta转换为int

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.