Skip to content
Advertisement

Match two dataframes and fill the column value in pandas

I have two excel file. I have to match them based on particular column and fill the other column. I explain you in the example.

Example: 2 excel files:

monitered call.xlsx In this excel 2 sheets are there, 1. print add 2. digital

digital C2D.xlsx single sheet is there Sheet1

monitered calls.xlsx:

enter image description here

digital C2D.xlsx

enter image description here

I have to match Caller Number with CONTACT and if both are matching then take the REMARK from 2nd excel and paste in first excel.

In the last save the updated data into monitered calls.xlsx in the same sheet.

df = pd.read_excel(r'D:UsersSPate233DownloadsAlkamonitored calls.xlsx', sheet_name='digital')
df1 = pd.read_excel(r'D:UsersSPate233DownloadsAlkadigital C2D.xlsx', sheet_name='Sheet1') 

Advertisement

Answer

Read and store both sheets in Pandas dataframes and use merge to get the result you are looking for. The pandas documentation has some really nice examples: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.merge.html. And in case you are not familair with joins, check this out: https://www.w3schools.com/sql/sql_join.asp.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement