[英]How to rename many dfs with digit-like column?
I have 5 dfs called: control1,control2,control3,control4,control5
.我有 5 个 dfs 称为: control1,control2,control3,control4,control5
。
All of these have a column name 1
.所有这些都有一个column name 1
。 This column name is int
type.此列名是int
类型。
How can i change this column name for each df to 'CODIGO'
( str
type).如何将每个 df 的列名更改为'CODIGO'
( str
类型)。
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?你能帮我吗?
Like this:像这样:
l = [control1, control2, control3, control4, control5]
for df in l:
df.rename(columns={1:'CODIGO'}, inplace=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.