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

查看:62
本文介绍了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?

时间增量列

7 天,23:29:00

7 days, 23:29:00

日整数列

7

推荐答案

Series 类有一个 pandas.Series.dt 访问器对象 有几个有用的日期时间属性,包括 dt.days.通过以下方式访问此属性:

The Series class has a pandas.Series.dt accessor object with several useful datetime attributes, including dt.days. 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天全站免登陆