[英]column to datetime pandas with rolling time
I have a df that has a timestamp column that looks like:我有一个 df,它的时间戳列如下所示:
0:40:40
0:40:45
...
23:59:55
0:00:00
0:00:05
...
And repeats like this for many days.并且这样重复很多天。 How can this be converted into a datetime object with a different consecutive day assigned to each new day?如何将其转换为日期时间 object 并为每个新的一天分配不同的连续日期? Currently, the to_datetime
assigns them all to the same day.目前, to_datetime
将它们全部分配到同一天。
after making the DATE column with to_datetime:使用 to_datetime 创建 DATE 列后:
df['New_date'] = df.apply(lambda row : row['DATE']+datetime.timedelta(days=row.name), axis=1)
NB: row.name to add the index number as a day注意:row.name 将索引号添加为一天
df.timestamp = pd.to_datetime(df.timestamp) days = 0 for i in range(2, size + 1): if df.at[i - 1, 'timestamp'].hour > df.at[i, 'timestamp'].hour: days += 1 df.at[i, 'timestamp'] += datetime.timedelta(days=days)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.