Reputation: 513
I have 5 dfs called:
control1,control2,control3,control4,control5
.
All of these have a column name 1
. This column name is int
type.
How can i change this column name for each df to 'CODIGO'
(str
type).
I tried this:
for j in range(1,6):
exec(f"control{j}=control{j}.rename(columns=lambda x: x.replace(1, 'CODIGO'))")
But does not work. Can you help me please?
Upvotes: 0
Views: 35
Reputation: 34086
Like this:
l = [control1, control2, control3, control4, control5]
for df in l:
df.rename(columns={1:'CODIGO'}, inplace=True)
Upvotes: 1