我有上千分的数据。它记录了100人在一天中做某项经常性活动的时间戳。它记录每一分钟的水平,所以在数据中有重复的。
我想索引我的时间戳列,但我不能这样做,因为有重复的时间戳。我想在第二步把副本分开,这样我就可以索引它们了。
我该怎么做?
timestamp
2022-10-10 01:05:00
2022-10-10 01:05:00
2022-10-10 01:23:00
... 我想在两个重复的值中增加1秒。
发布于 2022-11-09 12:50:49
您可以使用groupby.cumcount和pandas.to_timedelta进行反复制。
df['timestamp'] = pd.to_datetime(df['timestamp'])
df['timestamp'] += pd.to_timedelta(df.groupby('timestamp').cumcount(), unit='s')产出:
timestamp
0 2022-10-10 01:05:00
1 2022-10-10 01:05:01
2 2022-10-10 01:23:00已使用的投入:
timestamp
0 2022-10-10 01:05:00
1 2022-10-10 01:05:00
2 2022-10-10 01:23:00https://stackoverflow.com/questions/74375119
复制相似问题