Welcome to the world of Machine Learning !

Merge Datasets Python Code Implementation

import pandas as pd
# Create the first dataset
df1 = pd.DataFrame({'ID': [1, 2, 3, 4],
'Name': ['Ravi', 'Sham', 'Pooja', 'Suraj'],
'Age': [25, 30, 42, 35]})
# Create the second dataset
df2 = pd.DataFrame({'ID': [1, 2, 3, 4],
'Salary': [40000, 56000, 68000, 79000],
'Location': ['Jalandhar', 'Phagwara', 'Ludhiana', 'Amritsar']})
# Merge the datasets on the 'ID' column
merged_df = pd.merge(df1, df2, on='ID')
# Display the merged dataset
print(merged_df)

merged datasets image

Advertisement

Advertisement