Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to only display date component in a timestamp column - Python

I have a Pandas Dataframe that has a timestamp column. I would like to display only the date portion of it and not the hh:mm:ss portion. I tried using to_datetime function but it did not remove the time component. Could anyone assist on this. Thanks

input date : 2018-05-03 07:20:17
date = pd.to_datetime(df["FileReceivedTime"], format="%Y%m%d%")
date

Output : 2018-05-03 07:20:17
like image 743
dark horse Avatar asked May 05 '26 00:05

dark horse


1 Answers

You can add this:

dt.strftime('%Y/%m/%d')

in

date = pd.to_datetime(df["FileReceivedTime"], format="%Y%m%d%").dt.strftime('%Y/%m/%d')
like image 170
Joe Avatar answered May 06 '26 12:05

Joe