简体   繁体   中英

PYTHON convert mm/dd/yy hh:mm:ss AM TO mm/dd/yy

I use PYTHON do dateframe merge my output is: Name: Date, dtype: datetime64[ns]. I expert it to excel file, the Date column shows like: 3/2/2020 12:00:00 AM Is that possible to convert 3/2/2020 12:00:00 AM to 3/2/2020

Thank you!

Yes, you can do it by this:

df['date_column'] = pd.to_datetime(df['column_date'], format='%m/%d/%y')

The first part of the code, get the column date in the dataframe. The 2nd part convert it to the format you want.

This is something you need to change in Excel, not Python. Use the number format dropdown to select your preferred date format.

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