Combining Data With Pandas

In the lesson on aggregating data with Python, we worked with just one data set, the 2015 World Happiness Report, to explore data aggregation. However, it’s very common in practice to work with more than one data set at a time.

Oftentimes, you’ll find that you need additional data to perform analysis, or you’ll find that you have the data, but need to pull it from multiple sources. In this lesson, you’ll learn a couple of different techniques for combining data using pandas to easily handle situations like these.

You’ll use what you learned in the last lesson to analyze 2015, 2016, and 2017 World Happiness Reports. Specifically, you’ll look to answer the following question:

  • Did world happiness increase, decrease, or stay about the same from 2015 to 2017?

Just like in the last lesson, you’ll work with the World Happiness Report, an annual report created by the UN Sustainable Development Solutions Network with the intent of guiding policy. The report assigns each country a happiness score based on the answers to a poll question that asks respondents to rank their life on a scale of 0 to 10.

To perform this analysis, you’ll have to pull together multiple data sets, but we’ll show you how to combine data sets with pandas step-by-step in our interactive learning environment!


  • Learn different techniques for combining data.
  • Learn about database-style joins and keys.

Lesson Outline

  1. Introduction
  2. Combining Dataframes with the Concat Function
  3. Combining Dataframes with the Concat Function Continued
  4. Combining Dataframes with Different Shapes Using the Concat Function
  5. Joining Dataframes with the Merge Function
  6. Joining on Columns with the Merge Function
  7. Left Joins with the Merge Function
  8. Join on Index with the Merge Function
  9. Challenge: Combine Data and Create a Visualization
  10. Next steps
  11. Takeaways

Get started for free

No credit card required.

Or With

By creating an account you agree to accept our terms of use and privacy policy.