We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Data Merging

Real data almost never lives in one neat table. You might have:

  • customers.csv with customer info
  • orders.csv with purchases
  • products.csv with product details

If you want customer names, product details, and order history in one place, you need to combine those datasets by matching shared keys. In Pandas you'll usually do that with pd.merge().

We use the term merge in Pandas to refer to this process; it's similar to what SQL calls a JOIN. Different join types answer different kinds of questions.

Merging Is Usually Necessary

Production data is often normalized, which means related information is split across multiple tables to avoid duplication. Analysis usually wants the opposite: a wider dataset with the relevant context all in a single place. That's how you answer questions like:

  • Which customers bought which products?
  • What was revenue by product category?
  • Which orders reference missing customers or products?