简体   繁体   中英

Change all row values in Pandas dataframe in date format “mm/dd/yyyy” to “yyyy-mm-dd”

Like the title states, I have two csv files I have read into a Pandas dataframe and I want to join the two tables on their "Dates" column values. I'm having an issue converting the special character "/" to "-" and switching the ordering to year-month-day. Any easy quick way that will convert all the row values from the "mm/dd/yyyy" format to the correct "yyyy-mm-dd" format for the join?

When you read your csv adding parse_dates

pd.read_csv('q.csv',parse_dates=True)

Or

pd.read_csv('q.csv',parse_dates=['Dates'])# your date format column here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM