我有一个数据帧,看起来像这样:
date,time,metric_x
2016-02-27,00:00:28.0000000,31
2016-02-27,00:01:19.0000000,40
2016-02-27,00:02:55.0000000,39
2016-02-27,00:03:51.0000000,48
2016-02-27,00:05:22.0000000,42
2016-02-27,00:05:59.0000000,35
我希望生成一个新列
df['time_slot'] = df.apply(lambda row: time_slot_convert(pd.to_datetime(row['time'])), axis =1)
在哪里
def time_slot_convert(time):
return time.hour + 1
此函数用于查找此记录的小时数加1。你知道吗
这是非常缓慢的。我知道数据是作为字符串读取的。有没有更有效的方法来加速这一进程?你知道吗
更快的是删除
apply
:相关问题 更多 >
编程相关推荐