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:
d.rename(columns = lambda x: 'FY1920' if x.endswith('2019') else x)
also tried:
d.columns.str.contains('2019')
d.rename(lambda x:'FY1920' if any(k in x for k in keys) else x, axis=1)
I am sure there is an easy way. Any ideas?
Thanks :)