0

this is my code I did not put hour and seconds in my data but the result I got includes time, do you know if it is possible to remove the time?

input

fitness['Date']=pd.to_datetime(fitness['Date'])

result

1970-01-01 00:00:00.000000000 1979-09-09

1970-01-01 00:00:00.000000001 1979-09-09

1970-01-01 00:00:00.000000002 1979-09-09

1970-01-01 00:00:00.000000003 1979-09-09

1970-01-01 00:00:00.000000004 1979-09-09

Community
  • 1
  • 1
  • Welcome to StackOverflow. Please take the time to read this post on [how to provide a great pandas example](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) as well as how to provide a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve) and revise your question accordingly. These tips on [how to ask a good question](http://stackoverflow.com/help/how-to-ask) may also be useful. – jezrael Oct 17 '19 at 08:56
  • Possible duplicate of https://stackoverflow.com/questions/26763344/convert-pandas-column-to-datetime#26763793 – Ilya Datskevich Oct 17 '19 at 09:40

1 Answers1

0

As discussed here, the dt.strftime function can be utilised to format the output.

fitness['Date_formatted'] = pd.to_datetime(fitness['Date']).dt.strftime('%Y-%m-%d')

This will format the output of to_datetime() to follow %Y-%m-%d. However, the dtype of the column will be converted to string. You can find documentation for the function here.

Avi Agarwal
  • 103
  • 4