0

I want to merge multiple excelsheet what should be the query

importing the module

import pandas
  
# reading the files
f1 = pandas.read_excel("registration details.xlsx")
f2 = pandas.read_excel("exam results.xlsx")
  
# merging the files
f3 = f1[["REGISTRATION NO", 
         "STUDENT EMAIL ID "]].merge(f2[["REGISTRATION NO", 
                                         "Name", "Marks Obtained", 
                                         "Percentage"]], 
                                     on = "REGISTRATION NO", 
                                     how = "left")
  
# creating a new file
f3.to_excel("Results.xlsx", index = False)
  • If that is your attempt, are you getting a particular error or is the outcome not what you expected? – Bashton Nov 01 '21 at 13:48
  • @Bashton, It is not attempt. Merge from two excel sheets is working perfect. but i have multiple sheets to merge. – Meet Thaker Nov 01 '21 at 13:54
  • I see, do all the tables have the same key of `REGISTRATION NO`? – Bashton Nov 01 '21 at 13:55
  • @Bashton, yes all the tables have the "REGISTRATION NO" – Meet Thaker Nov 01 '21 at 13:59
  • If there aren't too many, you could just do a chained join, or alternatively, try this method using `reduce` : https://stackoverflow.com/questions/23668427/pandas-three-way-joining-multiple-dataframes-on-columns – Bashton Nov 01 '21 at 14:05
  • You can use [`functools.reduce`](https://docs.python.org/3/library/functools.html#functools.reduce) or `pd.concat(list_dfs).groupby().first()`. – Quang Hoang Nov 01 '21 at 14:06

0 Answers0