I'm working on writing a pandas DataFrame to a CSV file using to_csv :
df.to_csv("Output.csv")
I'm looking to customize the naming of the csv file by adding the actual datetime so it should look like this : Output_2021-12-17T14:09:09Z
Any idea?
CodePudding user response:
Use f-string
s with to_datetime
and Timestamp.strftime
:
print (f"Output_{pd.to_datetime('now').strftime('%Y-%m-%dT%H:%M:%SZ')}.csv")
Output_2021-12-17T13:12:58Z.csv
df.to_csv(f"Output_{pd.to_datetime('now').strftime('%Y-%m-%dT%H:%M:%SZ')}.csv")