0

I have a Pandas DataFrame that contains 'Report Date' in datetime format. The df contains a single record. I want to get just the string value. This is what I am using:

report_date = df['Report Date'].dt.strftime('%Y-%m-%d')
report_date

which produces this output:

0    2021-06-30

Name: Report Date, dtype: object

How do I get to a variable that is just the string "2021-06-30" ?

  • Does this answer your question? [datetime to string with series in pandas](https://stackoverflow.com/questions/30132282/datetime-to-string-with-series-in-pandas) – FObersteiner Oct 20 '21 at 15:46

1 Answers1

0

Add the following line:

report_date = df['Report Date'].dt.strftime('%Y-%m-%d')
report_date = report_date[0]
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 20 '21 at 14:31