0

So I have two excel files with only 3 columns in common, and I want to merge the rest of the information to get a new Excel file with all together and ordered, but I can't find a way to get a row and add it to another row

import pandas as pd
df1 = pd.read_excel(r'C:/Users/User/Desktop/UTP/Trabajo Alvaro_Christian/CE.xlsx')
df2 = pd.read_excel(r'C:/Users/User/Desktop/UTP/Trabajo Alvaro_Christian/Matricula.xlsx')
dfs = []
for x in df1:
    for y in df2: 
        if((df1['COD_PERIODO'] == df2['COD_PERIODO']) and (df1['TERCERO'] == df2['TERCERO'])):
            dfs.append(????)
dfs.to_excel('FinalData.xlsx')

So I find the matching rows and how do I copy the info of the second row to the first one and make the append to the new dataframe.

Taku
  • 31,927
  • 11
  • 74
  • 85
  • Does this answer your question? [how to merge two data frames based on particular column in pandas python?](https://stackoverflow.com/questions/37697195/how-to-merge-two-data-frames-based-on-particular-column-in-pandas-python) – Mahrkeenerh Oct 20 '21 at 15:08
  • 1
    `df1.merge(df2,on=['COD_PERIODO', 'TERCERO'])` – RJ Adriaansen Oct 20 '21 at 15:24
  • 1
    @Toni Hello, regarding your [edit](https://stackoverflow.com/revisions/69648461/2), overall it's pretty good—which is why I approved it; however, I understand you had good intentions when you formatted the code, but if you're unfamiliar with the language, please refrain from changing the code (including adding newlines), since it could break the original syntax (in your case, the newline after `pd.read_excel` would cause the syntax to differ). [From review](https://stackoverflow.com/review/suggested-edits/30152510). – Taku Oct 23 '21 at 13:28

0 Answers0