We can merge two dataframes in one dataframe based on one common column in python. pandas provide merger function to join two datasets.
First, read two dataset using pandas dataframe.
import pandas as pd
dataset1 = pd.read_csv('filename1.csv')
dataset2 = pd.read_csv('filename2.csv')
dataset1 ## display dataset1
dataset2 ## display dataset2
merger two dataset (dataset1 and dataset 2) using primary key invoice id, in both dataset invoice id is common.
new_dataset = pd.merge(dataset1, dataset2,
on='Invoice_ID',
how='inner')
new_dataset
In above code, merger function is used to join two dataset based on the invoice id key.
how arguments in merge function determine which keys are included in resulting table. inner is same as inner join in SQL which show intersection of keys. Merger method can be inner , outer , left and right.