1

I have imported some timestamps into a Pandas frame (via MongoDBclient). They are to the microseconds. I'd like a way to round to the Day. I've seen a previous question about using np.round while converting to ints and back again, but this doesn't work (I tried inlining a div by 3600 x 24 x 100000 but that didn't work).

I have this rather plain version, but it seems REALLY inefficient. What am I missing in either to_datetime, or the np.round example.

df['doa'] = df['doa'].map(lambda x: x.strftime("%Y-%m-%d")
pd.to_datetime(df['doa'])

Note, these are not INDEXES so I can't use the frequency trick.

doru
  • 9,022
  • 2
  • 33
  • 43
user3735204
  • 81
  • 1
  • 8

1 Answers1

0

There's this feature request, which suggests there's no good way: ENH: add rounding method to DatetimeIndex/TimedeltaIndex

However, in the article I found there is also this approach for minutes, which I might be able to modify:

pd.DatetimeIndex(((dti.asi8/(1e9*60)).round()*1e9*60).astype(np.int64))

Rounding Pandas Timestamp to minutes

Community
  • 1
  • 1
user3735204
  • 81
  • 1
  • 8