Skip to content
Advertisement

Rename column containing substring – Pandas

I need to rename columns in containing specific substring. In my case I am using data with columns that are named a specific date dd/mm/yyyy. I want to rename the column based on the yyyy of the column name (eg. 30/06/2020 rename FY1920).

Approach I have tried is as follows:

JavaScript

also tried:

JavaScript

I am sure there is an easy way. Any ideas?

Thanks :)

Advertisement

Answer

rename does not work in-place, you need to assign the result back:

JavaScript
JavaScript

Another option is to use set_axis or direct assignment:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement