Solved
I have the current dataframe df:
Farmer Good Fruit
Matt 5
Tom 10
which I want to change to:
Farmer Fruit
Matt 5
Tom 10
I am wondering if I can convert any column name containing Fruit, such as "Good Fruit" or "Dope Fruit", to simply "Fruit".
By using
df.columns.str.replace('.*Fruit*', 'Fruit', regex=True)
I was able to successfully change the column name to "Fruit". However, I'm not sure how to apply this change to the actual dataframe, df.
Index(['Farmer', 'Fruit'], dtype='object')
edit Thanks to @wjandrea for the solution. The code needs to be changed to:
df.columns = df.columns.str.replace('.*Fruit*', 'Fruit', regex=True)