简体   繁体   中英

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:

在此处输入图像描述

digital C2D.xlsx

在此处输入图像描述

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:\Users\SPate233\Downloads\Alka\monitored calls.xlsx', sheet_name='digital')
df1 = pd.read_excel(r'D:\Users\SPate233\Downloads\Alka\digital C2D.xlsx', sheet_name='Sheet1') 

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM