Skip to content Skip to sidebar Skip to footer

Python Pandas Merging Excel Sheets Not Working

I'm trying to merge two excel sheets using the common filed Serial but throwing some errors. My program is as below : (user1_env)root@ubuntu:~/user1/test/compare_files# cat compar

Solution 1:

Small modification worked for me,

import pandas as pd

source1_df = pd.read_excel('a.xlsx', sheetname='source1')
source2_df = pd.read_excel('a.xlsx', sheetname='source2')
joined_df = pd.merge(source1_df,source2_df,on='Serial',how='outer')
joined_df.to_excel('/home/gk/test/result.xlsx')

Solution 2:

It is because of the overlapping column names after join. You can either set your index to Serial and join, or specify a rsuffix= or lsuffix= value in your join function so that the suffix value would be appended to the common column names.

Post a Comment for "Python Pandas Merging Excel Sheets Not Working"