Datetime Milliseconds To Seconds In Pandas
Have a datetime column in pandas dataframe with values like these: time 2018-04-11 22:18:30.122 2018-04-11 23:00:21.399 I'm wondering how can I round these values, get rid of mill
Solution 1:
Use floor
with T
for minutes for set 0 seconds
:
#if necessary#df['time'] = pd.to_datetime(df['time'])
df['time'] = df['time'].dt.floor('T')
#alternative solution#df['time'] = df['time'].dt.floor('Min')
print (df)
time
0 2018-04-11 22:18:00
1 2018-04-11 23:00:00
I want round
values time after 30sec
is changed to next one:
df['time'] = df['time'].dt.round('T')
print (df)
time
0 2018-04-11 22:19:00
1 2018-04-11 23:00:00
Solution 2:
well, ceil is also work for this question.
df['time'] = pd.to_datetime(df['time'])
df['time'] = df['time'].dt.ceil('T')
df
time
0 2018-04-11 22:19:00
1 2018-04-11 23:01:00
Post a Comment for "Datetime Milliseconds To Seconds In Pandas"