如果有任何新内容,请将sheet2到sheet1的所有列名匹配,要求添加sheet3,并忽略区分大小写的
在Sheet1〃中;fName";并且在表2〃中;fname";应该考虑相同(此处区分大小写(并替换sheet2中的名称fName
"相同";全名";并且在表2"中;fullname(忽略空格和区分大小写(,但这是相同的。因此,请替换sheet2中的名称fName
并且";Zip";不在工作表中。因此,询问是否要添加zip(Y/N(如果是,则在表单3中添加单列
表1中没有更改,替换表2中的列名并在表3 中添加新列
第1张
Id fName Address1 Full Name
1 Parth 1, street Parth Hirpara
2 Ujas 10, avenue Ujas Gajera
第2张
Id fname Zip fullname
3 Keval 123 Keval Borad
4 Vivek 456 Keyur Jasani
更改列名后的Sheet2
Id fName Zip Full Name
3 Keval 123 Keval Borad
4 Vivek 456 Keyur Jasani
最终数据表列
忽略数据相关的东西
第3张
Id fName Address1 Full Name Zip
...
...
...
...
加载sheet1&sheet2为df1&df2。。。
df3 = df1.copy()
lst_col1 = df1.columns.to_list()
lst_col2 = df2.columns.to_list()
lst_col1_temp = [str(col).lower().replace(" ","") for col in lst_col1]
lst_col2_temp = [str(col).lower().replace(" ","") for col in lst_col2]
# Renaming columns in Sheet2 (df2)
for col1 in lst_col1:
col1_temp = str(col1).lower().replace(" ","")
if col1 not in lst_col2 and col1_temp in lst_col2_temp:
lst_col2[lst_col2_temp.index(col1_temp)] = col1
# Adding columns in Sheet3 (df3)
for col2 in lst_col2:
col2_temp = str(col2).lower().replace(" ","")
if col2_temp not in lst_col1_temp:
df3[col2] = df2[col2]
希望这能帮助。。。