Rename column with the filter selection

Viewed 33

How to rename the column name with the filter selection. I'm trying to automate the process so every time when filter is changed, I want the column name to be replaced by the filter selection. I need to declare the variable at the end to rename the column name based on the filter that is created at the beginning of the script. I want to replace the column name "Col1" with the filter name e.g. "General". How can I declare the filter name into renaming column

    df1 = df[(df.typ == 'GENERAL')]  #filter
     cols = df1.columns
     for col in cols:
        df1.rename({'Col1':'filter_name'}, axis=1, inplace =True) #assigning filter name to replace the column name.

 Current output:
 Col1   Col2   Col3
  10     20     30
  40     50     60

 Expected output:
  General   Col2   Col3
  10     20     30
  40     50     60
0 Answers
Related