I have a dataframe that has column names like below, with some of the column name having substring within []
'date', 'customer','region[level1]','priority[s2]','planning[WIP]' ...
Jan.10, ABC , East[3] , Normal[1] , TBD[WIP] ...
I want to rename all the columns so that only the value within the [] is kept.
'date','customer','level1','s2','WIP' ...
I've tried below code but kept getting error code 'NoneType' object has no attribute 'groups'. Which part went wrong?
import re
for i in range(len(df.columns)):
df.columns.value[i] = [re.match(r"[^[]*\[([^]]*)\]", col_name).groups()[0] for col_name in df.columns]