Home > Enterprise >  round datetime to nearest min
round datetime to nearest min

Time:11-24

how do I round below :

                   Time
0   2021-11-23 08:07:35
1   2021-11-09 23:12:13

to nearest min :

                   Time
0   2021-11-23 08:08:00
1   2021-11-09 23:12:00

CodePudding user response:

Coerce Time to datetime and use dt.round(Minute) to round. Code below

df['Time']=pd.to_datetime(df['Time']).dt.round("T")



 Time
0 2021-11-23 08:08:00
1 2021-11-09 23:12:00
  • Related