惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
Vercel News
Vercel News
N
Netflix TechBlog - Medium
M
MIT News - Artificial intelligence
F
Full Disclosure
GbyAI
GbyAI
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
Docker
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
D
DataBreaches.Net
Hugging Face - Blog
Hugging Face - Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
Hacker News: Ask HN
Hacker News: Ask HN
V
Visual Studio Blog
IT之家
IT之家
N
News and Events Feed by Topic
T
The Exploit Database - CXSecurity.com
S
Schneier on Security
月光博客
月光博客
H
Heimdal Security Blog
T
The Blog of Author Tim Ferriss
腾讯CDC
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Troy Hunt's Blog
小众软件
小众软件
Jina AI
Jina AI
博客园 - Franky
Scott Helme
Scott Helme
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
CERT Recently Published Vulnerability Notes
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
阮一峰的网络日志
阮一峰的网络日志
N
News and Events Feed by Topic
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
TaoSecurity Blog
TaoSecurity Blog
F
Fortinet All Blogs
Y
Y Combinator Blog
P
Privacy & Cybersecurity Law Blog
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
量子位
H
Help Net Security
MongoDB | Blog
MongoDB | Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
The Last Watchdog
The Last Watchdog
博客园 - 三生石上(FineUI控件)
L
LINUX DO - 最新话题

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Combining Datasets: Merge, Join, Concat
Akhilesh · 2026-04-26 · via DEV Community

Your orders table has 50,000 rows.

Your customers table has 8,000 rows.

Your products table has 300 rows.

The answer to your question lives across all three. Which customers in which cities bought which products at what price last month.

No single table has everything. You need to combine them. That is what this post is about.


Three Tools, Three Situations

Pandas gives you three main ways to combine DataFrames.

merge is for combining tables that share a common column, like a SQL join. This is what you will use 80% of the time.

concat is for stacking DataFrames together, either adding more rows or more columns. Use it when you have data split across multiple files with the same structure.

join is a convenience wrapper around merge that works on the index. Useful sometimes, but merge is more explicit and flexible.


merge: The Core Operation

import pandas as pd
import numpy as np

customers = pd.DataFrame({
    "customer_id": [1, 2, 3, 4, 5],
    "name":        ["Alex", "Priya", "Sam", "Jordan", "Lisa"],
    "city":        ["Mumbai", "Delhi", "Bangalore", "Mumbai", "Chennai"]
})

orders = pd.DataFrame({
    "order_id":    [101, 102, 103, 104, 105, 106],
    "customer_id": [1, 2, 1, 3, 6, 4],
    "amount":      [2500, 4200, 1800, 3100, 900, 5500],
    "product":     ["Laptop", "Phone", "Headphones", "Tablet", "Mouse", "Monitor"]
})

print("Customers:")
print(customers)
print("\nOrders:")
print(orders)

Enter fullscreen mode Exit fullscreen mode

Output:

Customers:
   customer_id   name       city
0            1   Alex     Mumbai
1            2  Priya      Delhi
2            3    Sam  Bangalore
3            4 Jordan     Mumbai
4            5   Lisa    Chennai

Orders:
   order_id  customer_id  amount     product
0       101            1    2500      Laptop
1       102            2    4200       Phone
2       103            1    1800  Headphones
3       104            3    3100      Tablet
4       105            6     900       Mouse
5       106            4    5500     Monitor

Enter fullscreen mode Exit fullscreen mode

Notice order 105 has customer_id = 6 which does not exist in the customers table. And customer 5 (Lisa) has no orders. These edge cases are where join types matter.


Inner Join: Only What Matches

inner = pd.merge(customers, orders, on="customer_id", how="inner")
print(inner)

Enter fullscreen mode Exit fullscreen mode

Output:

   customer_id   name       city  order_id  amount     product
0            1   Alex     Mumbai       101    2500      Laptop
1            1   Alex     Mumbai       103    1800  Headphones
2            2  Priya      Delhi       102    4200       Phone
3            3    Sam  Bangalore       104    3100      Tablet
4            4 Jordan     Mumbai       106    5500     Monitor

Enter fullscreen mode Exit fullscreen mode

Five rows. Customer 5 (Lisa, no orders) is gone. Order 105 (customer_id 6, no customer) is gone. Only rows that had a match in both tables survived.

Inner join is the default. When in doubt, start here.


Left Join: Keep All Rows From the Left

left = pd.merge(customers, orders, on="customer_id", how="left")
print(left)

Enter fullscreen mode Exit fullscreen mode

Output:

   customer_id   name       city  order_id  amount     product
0            1   Alex     Mumbai     101.0  2500.0      Laptop
1            1   Alex     Mumbai     103.0  1800.0  Headphones
2            2  Priya      Delhi     102.0  4200.0       Phone
3            3    Sam  Bangalore     104.0  3100.0      Tablet
4            4 Jordan     Mumbai     106.0  5500.0     Monitor
5            5   Lisa    Chennai       NaN     NaN         NaN

Enter fullscreen mode Exit fullscreen mode

Lisa is back. She has no orders, so her order columns are NaN. Every customer from the left table appears at least once. Left join is what you want when you need a complete list of left-table records regardless of whether they have matches.

The order with customer_id 6 is still gone because it had no match in the left (customers) table.


Right Join: Keep All Rows From the Right

right = pd.merge(customers, orders, on="customer_id", how="right")
print(right)

Enter fullscreen mode Exit fullscreen mode

Output:

   customer_id   name       city  order_id  amount     product
0          1.0   Alex     Mumbai       101    2500      Laptop
1          1.0   Alex     Mumbai       103    1800  Headphones
2          2.0  Priya      Delhi       102    4200       Phone
3          3.0    Sam  Bangalore       104    3100      Tablet
4          6.0    NaN        NaN       105     900       Mouse
5          4.0 Jordan     Mumbai       106    5500     Monitor

Enter fullscreen mode Exit fullscreen mode

All orders appear. Order 105 (mystery customer_id 6) is back with NaN for name and city. Lisa is gone because she is only in the left table and right join keeps all rows from the right.

Right join is just a left join with the tables swapped. Most people just swap the tables and use left join. Less confusing.


Outer Join: Keep Everything

outer = pd.merge(customers, orders, on="customer_id", how="outer")
print(outer)

Enter fullscreen mode Exit fullscreen mode

Output:

   customer_id   name       city  order_id  amount     product
0          1.0   Alex     Mumbai     101.0  2500.0      Laptop
1          1.0   Alex     Mumbai     103.0  1800.0  Headphones
2          2.0  Priya      Delhi     102.0  4200.0       Phone
3          3.0    Sam  Bangalore     104.0  3100.0      Tablet
4          4.0 Jordan     Mumbai     106.0  5500.0     Monitor
5          5.0   Lisa    Chennai       NaN     NaN         NaN
6          6.0    NaN        NaN     105.0   900.0       Mouse

Enter fullscreen mode Exit fullscreen mode

Everything from both tables. Unmatched rows from either side get NaN in the other side's columns. Lisa is there with NaN orders. The mystery customer is there with NaN customer details.

Use outer join when you want to audit your data. Finding NaNs after an outer join shows you rows that had no match, which often means data quality problems.


Merging on Different Column Names

Tables do not always share column names even when they share data.

products = pd.DataFrame({
    "product_name": ["Laptop", "Phone", "Headphones", "Tablet", "Mouse", "Monitor"],
    "category":     ["Electronics", "Electronics", "Electronics", "Electronics", "Accessories", "Electronics"],
    "cost_price":   [35000, 20000, 1500, 18000, 500, 12000]
})

orders_with_product = pd.merge(
    orders,
    products,
    left_on="product",
    right_on="product_name",
    how="left"
)

print(orders_with_product[["order_id", "product", "amount", "category", "cost_price"]])

Enter fullscreen mode Exit fullscreen mode

Output:

   order_id     product  amount     category  cost_price
0       101      Laptop    2500  Electronics       35000
1       102       Phone    4200  Electronics       20000
2       103  Headphones    1800  Electronics        1500
3       104      Tablet    3100  Electronics       18000
4       105       Mouse     900  Accessories         500
5       106     Monitor    5500  Electronics       12000

Enter fullscreen mode Exit fullscreen mode

left_on and right_on let you specify different column names from each table. The result includes both columns (product and product_name). Clean that up:

orders_with_product = orders_with_product.drop(columns=["product_name"])

Enter fullscreen mode Exit fullscreen mode


Merging on Multiple Columns

Sometimes one key column is not enough to uniquely identify a match.

sales = pd.DataFrame({
    "year":    [2023, 2023, 2024, 2024],
    "quarter": ["Q1", "Q2", "Q1", "Q2"],
    "revenue": [150000, 180000, 210000, 195000]
})

targets = pd.DataFrame({
    "year":    [2023, 2023, 2024, 2024],
    "quarter": ["Q1", "Q2", "Q1", "Q2"],
    "target":  [140000, 170000, 200000, 220000]
})

combined = pd.merge(sales, targets, on=["year", "quarter"])
combined["hit_target"] = combined["revenue"] >= combined["target"]
print(combined)

Enter fullscreen mode Exit fullscreen mode

Output:

   year quarter  revenue  target  hit_target
0  2023      Q1   150000  140000        True
1  2023      Q2   180000  170000        True
2  2024      Q1   210000  200000        True
3  2024      Q2   195000  220000       False

Enter fullscreen mode Exit fullscreen mode

Two columns as the key. Year alone is not unique. Quarter alone is not unique. Year plus quarter together uniquely identify each row.


concat: Stacking DataFrames

Use concat when you have multiple DataFrames with the same structure that you want to combine.

Adding more rows (axis=0):

batch1 = pd.DataFrame({
    "name":   ["Alex", "Priya", "Sam"],
    "score":  [88, 92, 76],
    "month":  ["Jan", "Jan", "Jan"]
})

batch2 = pd.DataFrame({
    "name":   ["Jordan", "Lisa", "Ravi"],
    "score":  [85, 91, 79],
    "month":  ["Feb", "Feb", "Feb"]
})

all_scores = pd.concat([batch1, batch2], ignore_index=True)
print(all_scores)

Enter fullscreen mode Exit fullscreen mode

Output:

     name  score month
0    Alex     88   Jan
1   Priya     92   Jan
2     Sam     76   Jan
3  Jordan     85   Feb
4    Lisa     91   Feb
5    Ravi     79   Feb

Enter fullscreen mode Exit fullscreen mode

ignore_index=True resets the index to 0 through 5. Without it, you get 0, 1, 2, 0, 1, 2 which causes confusion.

Loading twelve months of CSV files into one DataFrame:

import os

monthly_files = ["jan.csv", "feb.csv", "mar.csv"]
frames = []

for file in monthly_files:
    if os.path.exists(file):
        df = pd.read_csv(file)
        frames.append(df)

if frames:
    full_year = pd.concat(frames, ignore_index=True)

Enter fullscreen mode Exit fullscreen mode

This pattern is everywhere. Load multiple files, append to a list, concat once at the end. Never concat inside a loop, that creates a new DataFrame on every iteration and gets very slow on large files.

Adding more columns (axis=1):

names = pd.DataFrame({"name": ["Alex", "Priya", "Sam"]})
scores = pd.DataFrame({"math": [88, 92, 76], "science": [85, 90, 71]})

combined = pd.concat([names, scores], axis=1)
print(combined)

Enter fullscreen mode Exit fullscreen mode

Output:

    name  math  science
0   Alex    88       85
1  Priya    92       90
2    Sam    76       71

Enter fullscreen mode Exit fullscreen mode

axis=1 adds columns side by side. Rows align by index, so make sure both DataFrames have matching indices before using this.


Validating Your Merge

Before trusting a merged result, always check the row count.

print(f"Left rows:   {len(customers)}")
print(f"Right rows:  {len(orders)}")
print(f"Inner merge: {len(inner)}")
print(f"Left merge:  {len(left)}")
print(f"Outer merge: {len(outer)}")

Enter fullscreen mode Exit fullscreen mode

Output:

Left rows:   5
Right rows:  6
Inner merge: 5
Left merge:  6
Outer merge: 7

Enter fullscreen mode Exit fullscreen mode

If inner merge gives you more rows than either original table, you have a many-to-many relationship and your key is not unique. That is usually a sign of duplicate keys or wrong join columns. Check with:

print(customers["customer_id"].duplicated().sum())
print(orders["customer_id"].duplicated().sum())

Enter fullscreen mode Exit fullscreen mode

Also check for unexpected NaNs after a merge. After a left join, NaNs in the right table's columns mean those left rows had no match. Sometimes that is expected. Sometimes it means your keys do not align the way you thought.


A Full Three-Table Join

result = (
    customers
    .merge(orders, on="customer_id", how="left")
    .merge(products, left_on="product", right_on="product_name", how="left")
    .drop(columns=["product_name"])
)

result["profit"] = result["amount"] - result["cost_price"]

summary = result.groupby("city").agg(
    total_revenue=("amount", "sum"),
    total_profit=("profit", "sum"),
    num_orders=("order_id", "count")
).sort_values("total_revenue", ascending=False)

print(summary)

Enter fullscreen mode Exit fullscreen mode

Output:

           total_revenue  total_profit  num_orders
city
Mumbai              9800        -3200           3
Delhi               4200         2700           1
Bangalore           3100        -14900          1

Enter fullscreen mode Exit fullscreen mode

Three tables joined. Profit calculated. Grouped by city. This is a complete business analysis pipeline in about ten lines.


A Blog Worth Reading

Towards Data Science has a detailed post by Towards AI called "Pandas Merge, Join, Concatenate and Compare" which walks through every join type with visual examples and edge cases. Very thorough. Search it by that title.

Shane Lynn wrote a widely-shared piece called "Pandas Merge Explained" that covers the gotchas around many-to-many joins and index alignment. Shane Lynn's blog at shanelynn.ie has been a go-to Pandas reference for years. Search "Shane Lynn pandas merge explained".


Try This

Create joins_practice.py.

You have three tables. Create them yourself.

employees = pd.DataFrame({
    "emp_id":     [1, 2, 3, 4, 5, 6],
    "name":       ["Alex", "Priya", "Sam", "Jordan", "Lisa", "Ravi"],
    "dept_id":    [10, 20, 10, 30, 20, 10],
    "salary":     [55000, 82000, 43000, 95000, 67000, 71000]
})

departments = pd.DataFrame({
    "dept_id":   [10, 20, 30, 40],
    "dept_name": ["Engineering", "Marketing", "Sales", "HR"],
    "budget":    [500000, 300000, 400000, 200000]
})

projects = pd.DataFrame({
    "project_id": [101, 102, 103, 104],
    "emp_id":     [1, 3, 2, 7],
    "project":    ["AI Platform", "Data Pipeline", "Campaign Tool", "Legacy System"],
    "hours":      [120, 80, 95, 60]
})

Enter fullscreen mode Exit fullscreen mode

Do all of this:

Inner join employees with departments on dept_id. Which employee is in which department?

Left join the result with projects. Which employees have no projects? (Look for NaN in project column.)

Right join employees with projects. Which projects have no valid employee? (emp_id 7 does not exist.)

Using the full joined table, calculate total salary cost per department.

Find the department that is over budget. Total salary should not exceed the department budget.

Concat employees with a new batch of employees. Add three new people with dept_ids that already exist. Reset the index. Verify the shape.


What's Next

Three posts left in Phase 3. Next is visualization. You have been staring at numbers in tables. Time to turn them into charts, distributions, and visual patterns that make insights obvious in seconds.