I want to change the column labels of a Pandas DataFrame from
['evaluationId' , 'createdAt', 'scheduleEndDate', 'sharedTo', ...]
to
['EVALUATION_ID', 'CREATED_AT', 'SCHEDULE_END_DATE', 'SHARED_TO',...]
I have a lot of columns with this pattern "aaaBb" and I want to create this pattern "AAA_BB" of renamed columns
I tried something like :
new_columns = [unidecode(x).upper() for x in df.columns]
But I don't have idea how to create a solution.
You can use a regex with
str.replace
to detect the lowercase-UPPERCASE shifts and insert a_
, thenstr.upper
:Before:
After: