Vlad Aleshin
Vlad Aleshin

Reputation: 411

Format datetime column using pandas

I need to delete dot and digits after dot in pandas datetime colums:

0   2020-01-05 21:58:15.030099
1   2020-01-09 09:15:01.286888

I write this code, but the result is the same (digits after dot):

ret.reg_dt = pd.to_datetime(ret.reg_dt, format='%Y-%m-%d %H:%M:%S')

How can I delete it?

Upvotes: 1

Views: 65

Answers (1)

jezrael
jezrael

Reputation: 863501

You can use Series.dt.floor by seconds:

ret.reg_dt = ret.reg_dt.dt.floor('S')
print (ret)
               reg_dt
0 2020-01-05 21:58:15
1 2020-01-09 09:15:01

Upvotes: 1

Related Questions