pandas to excel traversal reads filling: Save relates to multiple tables, the type of treatment from NAN, (the type str) process from NAN

code show as below:

Import PANDAS AS PD 
DF1 = pd.read_excel ( " Primary Mathematics // .xlsx " , SHEET_NAME = " Repository " , DTYPE = { " relates entitled " :} STR) 
DF1 = df1.set_index ( " ID " ) 
DF2 = PD. read_excel ( " Primary Mathematics // .xlsx " , sheet_name = " Problems " ) 
DF2 = df2.set_index ( " ID " ) 

for i in DF2 [ " involving knowledge " ] .index:
    id_know = df2[" relates knowledge " ] .at [I] 
    id_know = int (id_know)
     IF DF1 [ " relates entitled " ] .at [id_know] == " NaN3 " : 
        DF1 [ " relates entitled " ] .at [id_know] = STR (I)
     the else : 
        DF1 [ " relates entitled " ] .at [id_know] + = "  " 
        DF1 [ " relates entitled " ] .at [id_know] = + STR (I) 

Writer = pd.ExcelWriter ( " Primary // mathematics .xlsx ") 
DF1.to_excel(writer, sheet_name="repository")
df2.to_excel(writer, sheet_name="problems")
writer.save()

 

Guess you like

Origin www.cnblogs.com/Chaosliang/p/11620073.html