Начните с экранирования строк в char1
. Затем создайте отображение char1
→ char2
и передайте его pd.Series.replace
в столбцах.
import re
char1 = [r"\s+" , r"(" , r")" , r"%" , r";"]
char2 = ["_" , "" , "", "percent" , ""]
mapping = dict(zip((re.escape(c) if '\\' not in c else c for c in char1), char2))
# this next step is similar to MaxU's solution
df.columns = df.columns.to_series().replace(mapping, regex=True)
df
percent_score C D start_name
0 one 0 0 foo
1 one 1 2 bar
2 two 2 4 foo
3 three 3 6 bar
4 two 4 8 foo
5 two 5 10 bar
6 one 6 12 foo
7 three 7 14 foo