A more efficient way to round to a timestamp with pandas

I imported some timestamps into a Pandas frame (via MongoDBclient ). They relate to microseconds. I would like to circle on the Day. I saw the previous question about using np.round when converting to int and vice versa, but this does not work (I tried to embed the div on 3600 x 24 x 100000, but this did not work).

I have this pretty simple version, but it seems REALLY ineffective. What I miss in either to_datetime or in the np.round example.

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

Please note that these are not INDEXES, so I cannot use the frequency trick.

+1
source share
1 answer

Here is a function request that does not offer a good way: ENH: add a rounding method to DatetimeIndex / TimedeltaIndex

However, in the article I found, there is also this approach for minutes, which I could change:

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

Rounding Pandas Timestamp to Minutes

0
source

Source: https://habr.com/ru/post/978432/


All Articles