简体   繁体   中英

Removing timestamp from a column name in a pandas dataframe

I have the following dataframe:

    ID  2019-01-31 00:00:00
 0  R01 1

How can I remove the time from the column name, so that I can slice the df by df['31/01/2019']?

You can do something like that:

from datetime import datetime

df.columns = [i.strftime('%Y-%m-%d') if isinstance(i, datetime) else i for i in df.columns]

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