I have a dataframe that uses a DateTime index. Due to the nature of the data, there are duplicate rows in the raw data that produce duplicate indices. I would like to add a random number of microseconds to each index to make them unique.
So, my index is currently:
2021-06-01 08:58:47+00:00
and I want it to be:
2021-06-01 08:58:47.011356+00:00
I have a column named TimeUTC which I used to create the index. I tried adding a random number of microseconds to it:
df.index = df.index + datetime.timedelta(microseconds= random.randrange(0,1000000,1))
but that added the same number of microseconds to all rows. I had the same result when trying to use apply + lambda.
- How can I add a random number of microseconds to each row's TimeUTC?
- Can I do this directly to the index instead of updating TimeUTC and then reindexing?
Thank you.