Home > other >  Python implementation excel table combined, to realize the automatic operation of the form
Python implementation excel table combined, to realize the automatic operation of the form

Time:10-25

Table1 table2
Enquiries gender student id name class rank
1st man xin-sheng du 1
2 female recruit her 2
3 men 3 pepe 3


Table3 table4
Name class class rank subject class
Recruit her math class two grade three 1
Pepe class 2 three years three years in a physical class 3
Xin-sheng du 3 chemical



I want to achieve is four worksheet to merge, roughly form case as example, need to take four tables combined into a table, then table3 empty data can also according to the content of tabe4 populated, and synthesis of the table does not exist, repetitive
Because I was a novice, my code is only simple implementation is as follows:

The import pandas as pd
The import numpy as np

Def get_mac () :
# coding utf-8
# df1=pd. Read_excel (" C:/Users/asus/Desktop/W.x ls ")
# df2=pd. Read_excel (" C:/Users/asus/Desktop/R.x ls ")

# result=pd. The merge (df1, df2, how="inner", on="satisfaction_level" and "")
# result. To_excel (" C:/Users/asus/Desktop/result. XLS ")
Df=pd DataFrame ({" student id ": pd Series ([1, 2, 3, 4]), and \
"Gender" : pd. Series ([" male "and" female ", "male" and "female"])})
Df1=pd. DataFrame ({" student id ": pd Series ([1, 2, 3, 4]), and \
"Name" : pd. Series ([" xin-sheng du ", "call her", "pepe", "Wu Jinyan"]), \
"Class rank" : pd. Series ([1, 2, 3, 4])})
Df2=pd. DataFrame ({" name ": pd Series ([" called her", "xin-sheng du", "pepe", "Wu Jinyan"]), and \
"Class" : pd. Series ([" class 2 three years ", ""," three years three shifts ", ""])})
Df3=pd. DataFrame ({" class rank: pd Series ([1, 2, 3, 4]), and \
"Subject" : pd. Series ([" mathematics ", "physical", "chemical" and "political"]), and \
"Class" : pd. Series ([" three years class ", "three years class 2", "three years three shifts", "three years class"])})
Result1=pd. The merge (df, df1, how="inner", on="student id")
Result2=pd. The merge (df2 result1, how="inner", on="name")

Result3=pd. The merge (result2, df3, how="inner", on="class rank")
Print (data)
If __name__=="__main__" :
Get_mac ()
Copy the code


the existing problems are as follows:
1. How to combine result2 and table4, and according to complement a result2 table4 class information content
2. I have to deal with the four excel form, I consider not comprehensive too simple code in the way? Need not to need to filter data such as?
3. The same column to fuzzy matching rule out may input the wrong information?
May be due to I am too dishes, I research this stuff a day did not understand, ask you a great god help

CodePudding user response:

 

Def get_mac () :
Df=pd DataFrame ({u "student id" : pd Series ([1, 2, 3, 4]), and \
U "gender" : pd. Series ([u "male", u "female", u "male", u "female"])})
Print df
Df1=pd. DataFrame ({u "student id" : pd Series ([1, 2, 3, 4]), and \
U "name" : pd. Series ([u "xin-sheng du," u "called her", u "pepe," u "Wu Jinyan"]), and \
U "class rank" : pd. Series ([1, 2, 3, 4])})
Df2=pd. DataFrame ({u "name" : pd Series ([u "called her", u "xin-sheng du," u "pepe," u "Wu Jinyan"]), and \
U "class" : pd. Series ([u "class 2 three years", ", "u" three years three shifts ", ""])})
Df3=pd. DataFrame ({u "class rank: pd Series ([1, 2, 3, 4]), and \
"U" subject: pd. Series ([u "math", u "physics", u "chemistry," u "political"]), and \
U "class" : pd. Series ([u "three years class," u "class two in three years," u "three years three shifts," u "three years class"])})
Result1=pd. The merge (df, df1, how="inner", on=u "student id")
Result2=pd. The merge (df2 result1, how="inner", on=u "name")
Df3. Columns=[' cclass ', 'c_rank', 'subject']
Result3=pd. The merge (result2, df3, how="inner", left_on=u "class rank," right_on='c_rank')
Result3. Loc [(result3 [u 'class']==u '), u 'class']=result3. Cclass # supplement the null
Return result3
If __name__=="__main__" :
Print get_mac ()

CodePudding user response:

Much less data are ok, then, ha ha, it is better to oneself,,,,,,,,,
  • Related