代码如下:
import pandas as pd df1 = pd.read_excel("小学//数学.xlsx", sheet_name="repository", dtype={"涉及题目": str}) df1 = df1.set_index("ID") df2 = pd.read_excel("小学//数学.xlsx", sheet_name="problems") df2 = df2.set_index("ID") for i in df2["涉及知识点"].index: id_know = df2["涉及知识点"].at[i] id_know = int(id_know) if df1["涉及题目"].at[id_know] == "nan": df1["涉及题目"].at[id_know] = str(i) else: df1["涉及题目"].at[id_know] += " " df1["涉及题目"].at[id_know] += str(i) writer = pd.ExcelWriter("小学//数学.xlsx") df1.to_excel(writer, sheet_name="repository") df2.to_excel(writer, sheet_name="problems") writer.save()