- Data Analysis with Python
-
Overview
- Introduction to Data Science and Analytics
- Loading and Cleaning Data in Pandas
- Data Manipulation with NumPy and Pandas
- Exploratory Data Analysis (EDA) Techniques
- Handling Missing Data and Duplicates
- Merging, Joining, and Concatenating DataFrames
- Time Series Analysis Basics
- Data Visualization with Matplotlib and Seaborn
- Descriptive Statistics and Data Summarization
- Advanced Pandas Operations
Merging, Joining, and Concatenating DataFrames
Add to BookmarkWhen working with large datasets in Python, we often need to combine multiple DataFrames. Pandas provides powerful functions for merging, joining, and concatenating datasets efficiently. In this tutorial, we will explore these techniques with practical examples.
1. Concatenating DataFrames
Concatenation in Pandas is used to stack DataFrames either vertically (along rows) or horizontally (along columns).
Concatenating Along Rows (axis=0)
import pandas as pd
data1 = pd.DataFrame({'ID': [1, 2], 'Name': ['Amit', 'Priya']})
data2 = pd.DataFrame({'ID': [3, 4], 'Name': ['Rahul', 'Sneha']})
result = pd.concat([data1, data2], ignore_index=True)
print(result)Concatenating Along Columns (axis=1)
data3 = pd.DataFrame({'Age': [25, 30]})
merged_data = pd.concat([data1, data3], axis=1)
print(merged_data)2. Merging DataFrames
Merging is similar to SQL joins and allows combining DataFrames based on common columns.
Inner Join (Default Merge)
dataA = pd.DataFrame({'ID': [1, 2, 3], 'Name': ['Amit', 'Priya', 'Rahul']})
dataB = pd.DataFrame({'ID': [2, 3, 4], 'Salary': [50000, 60000, 70000]})
merged_data = pd.merge(dataA, dataB, on='ID')
print(merged_data)Left Join
left_join = pd.merge(dataA, dataB, on='ID', how='left')
print(left_join)Right Join
right_join = pd.merge(dataA, dataB, on='ID', how='right')
print(right_join)Outer Join (Full Join)
outer_join = pd.merge(dataA, dataB, on='ID', how='outer')
print(outer_join)3. Joining DataFrames
Pandas join() is used when combining DataFrames based on index.
df1 = pd.DataFrame({'Salary': [50000, 60000]}, index=['Amit', 'Priya'])
df2 = pd.DataFrame({'Age': [25, 30]}, index=['Amit', 'Priya'])
joined_df = df1.join(df2)
print(joined_df)Summary
- Concatenation: Used for stacking DataFrames vertically or horizontally.
- Merging: Similar to SQL joins, merging combines DataFrames based on a key column.
- Joining: Works on index-based merging.
Prepare for Interview
- JavaScript Interview Questions for 5+ Years Experience
- JavaScript Interview Questions for 2–5 Years Experience
- JavaScript Interview Questions for 1–2 Years Experience
- JavaScript Interview Questions for 0–1 Year Experience
- JavaScript Interview Questions For Fresher
- SQL Interview Questions for 5+ Years Experience
- SQL Interview Questions for 2–5 Years Experience
- SQL Interview Questions for 1–2 Years Experience
- SQL Interview Questions for 0–1 Year Experience
- SQL Interview Questions for Freshers
- Design Patterns in Python
- Dynamic Programming and Recursion in Python
- Trees and Graphs in Python
- Linked Lists, Stacks, and Queues in Python
- Sorting and Searching in Python
Random Blogs
- Create Virtual Host for Nginx on Ubuntu (For Yii2 Basic & Advanced Templates)
- Loan Default Prediction Project Using Machine Learning
- What is YII? and How to Install it?
- Ideas for Content of Every niche on Reader’s Demand during COVID-19
- AI Agents: The Future of Automation, Work, and Opportunities in 2025
- AI & Space Exploration – AI’s Role in Deep Space Missions and Planetary Research
- Mastering Python in 2025: A Complete Roadmap for Beginners
- Avoiding the Beginner’s Trap: Key Python Fundamentals You Shouldn't Skip
- Understanding Data Lake, Data Warehouse, Data Mart, and Data Lakehouse – And Why We Need Them
- Datasets for Speech Recognition Analysis
- Datasets for Natural Language Processing
- Python Challenging Programming Exercises Part 3
- The Ultimate Guide to Data Science: Everything You Need to Know
- OLTP vs. OLAP Databases: Advanced Insights and Query Optimization Techniques
- Mastering SQL in 2025: A Complete Roadmap for Beginners
Datasets for Machine Learning
- Awesome-ChatGPT-Prompts
- Amazon Product Reviews Dataset
- Ozone Level Detection Dataset
- Bank Transaction Fraud Detection
- YouTube Trending Video Dataset (updated daily)
- Covid-19 Case Surveillance Public Use Dataset
- US Election 2020
- Forest Fires Dataset
- Mobile Robots Dataset
- Safety Helmet Detection
- All Space Missions from 1957
- OSIC Pulmonary Fibrosis Progression Dataset
- Wine Quality Dataset
- Google Audio Dataset
- Iris flower dataset
