MISSION 345

Transforming Data With Pandas

In this lesson, we'll continue working with the World Happiness Report and explore another aspect of it that we haven't analyzed yet - the factors that contribute to happiness. As a reminder, the World Happiness Report assigns each country a happiness score based on a poll question that asks respondents to rank their life on a scale of 0 to 10.

Throughout this lesson, we'll explore how to transform data using pandas. To facilitate your exploration of transforming data with pandas, you'll work to answer the following question in this mission:

  • Which of the factors that contribute to happiness contribute the most to the happiness score?

In order to answer this question, we need to manipulate our data into a format that makes it easier to analyze. We'll explore the following functions and methods to perform this task:

  • Series.map()
  • Series.apply()
  • DataFrame.applymap()
  • DataFrame.apply()
  • pandas.melt()

As you work through each concept in this lesson, you’ll get to apply what you’ve learned from within your browser so that there's no need to use your own machine to do the exercises. The Python environment inside of this course includes answer checking so you can ensure that you've fully mastered each concept before learning the next concept.

Objectives

  • Learn how to apply custom functions to transform columns in pandas.
  • Learn how to reshape data to prepare it for analysis.

Mission Outline

1. Introduction
2. Apply a Function Element-wise Using the Map and Apply Methods
3. Apply a Function Element-wise Using the Map and Apply Methods Continued
4. Apply a Function Element-wise to Multiple Columns Using Applymap Method
5. Apply Functions along an Axis using the Apply Method
6. Apply Functions along an Axis using the Apply Method Continued
7. Reshaping Data with the Melt Function
8. Challenge: Aggregate the Data and Create a Visualization
9. Next steps
10. Takeaways

python-datacleaning

Course Info:

Beginner

The median completion time for this course is 7.2 hours. View Details

This course requires a basic subscription and includes five missions and one guided project.  It is the sixth course in the Data Analyst in Python path and Data Scientist in Python path.

START LEARNING FREE

Take a Look Inside