How to return only the date from DateTime column in pandas with python

1 Answer

0 votes
import pandas as pd

df = pd.DataFrame({"dt_tm": 
    ["2022-01-05 08:09:01", 
     "2022-02-09 09:10:13", 
     "2022-03-12 10:24:17", 
     "2022-04-27 11:37:28"]})

print(pd.to_datetime(df['dt_tm']).dt.date)




'''
run:

0    2022-01-05
1    2022-02-09
2    2022-03-12
3    2022-04-27
Name: dt_tm, dtype: object

'''

 



answered Jul 11, 2022 by avibootz
...