Reputation: 513
I have a list of dataframes called: control1,control2,control3,control4,control5. I want to rename only the column named 10 (integer) for each dfs in the list. I want to rename to this names: 'OPE_PROM_1','OPE_PROM_2','OPE_PROM_3','OPE_PROM_4','OPE_PROM_5'. I tried this code
lista_controles=[control1,control2,control3,control4,control5]
for df in lista_controles:
df.rename(columns={10:'OPE_PROM_'+df+''}, inplace=True)
But is not working. Is there any possible solution to this?
Upvotes: 0
Views: 169
Reputation: 71689
Simply, Use:
lista_controles = [control1, control2, control3, control4, control5]
for i, df in enumerate(lista_controles, 1):
df.rename(columns={10: f'OPE_PROM_{i}'}, inplace=True)
Upvotes: 1