【发布时间】:2018-06-11 21:35:05
【问题描述】:
我有一个熊猫数据框 df:
id value mins
1 a 12.4
2 u 14.2
3 i 16.2
3 g 17.0
我有一个 datetime.datetime 变量:
current_time = datetime.datetime(2018, 1, 2, 14, 0, 34, 628481)
我想在我的 df 'total_time' 中添加新列
这样对于每一行,它都会在 current_time 中添加增量值 mins。
id value mins total_time
1 a 12.4 current_time+timedelta(minutes = 12.4)
2 u 14.2 and
3 i 16.2 so
3 g 17.0 on... for every row
我试过了:
df['total_time' = current_time+timedelta(minutes = df['mins'].item())
但我得到了一个错误:
can only convert an array of size 1 to a Python scalar
还有其他方法吗?
我正在使用 datetime.datetime 包
【问题讨论】:
标签: pandas