[英]Convert timedelta to floating-point for entire column in data frame
I need to Convert timedelta to floating-point for every cell in a column of my data frame.我需要将数据帧列中的每个单元格的 timedelta 转换为浮点数。 Here is how you do it for single cell:以下是对单个单元格执行此操作的方法:
time_d = datetime_1 - datetime_2
number_of_days = float(time_d.days)
But when .days
is applied to entire column this error appears:但是当.days
应用于整个列时,会出现此错误:
AttributeError: 'Series' object has no attribute 'days'
I'd like the date difference to be in days to be used in future calculations.我希望在未来的计算中使用的日期差异以天为单位。
使用Series.dt.days
处理Series
:
df['column'] = df['column'].dt.days
尝试这个:
df['column'] = df['column'].map(lambda x: float(x.days))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.