Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing timestamp from a column name in a pandas dataframe

Tags:

python

pandas

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']?

like image 894
Filipe Avatar asked Oct 19 '25 04:10

Filipe


1 Answers

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]
like image 105
fsl Avatar answered Oct 22 '25 00:10

fsl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!