pandas对excel遍历读取与填充:涉及多张表的保存、NAN的类型处理、NAN的处理(str类型下)

代码如下:

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()

 

上一篇:漫画:什么是 HTTPS 协议?


下一篇:数据集的合并