Background: Apparently Google doesn't have a straight answer to a very basic question, so here goes...
I have a pandas df with a Open Date column [Dtype = object] which (when previewing df) is formatted yyyy-mm-dd, which is the format I want, great! Not so great however, when I write df to a .csv which then defaults the formatting to m/dd/yyyy.
Issue: I have tried just about everything for the .csv to output yyyy-dd-mm to no avail.
What I've tried:
I have tried specifying a date format when writing the .csv
df.to_csv(filename, date_format="%Y%d%d")
I have tried changing the format of the column in question, prior to writing to a .csv
df['Open Date'] = pd.to_datetime(df['Open Date'])
I have also tried converting the column to a string, to try and force the correct output
df['Open Date'] = df['timestamp'].apply(lambda v: str(v))
Despite these attempts, I still get a m/dd/yyyy output.
Help: where am I embarrasingly going wrong here?
df.to_csv(filename, date_format="%Y-%m-%d")but no luck. Am I approaching this the wrong way?"%Y%d%d"would never produce"%Y-%m-%d"output of course.