From the course: Data Analysis with Python and Pandas
Unlock this course with a free trial
Join today to access over 24,900 courses taught by industry experts.
The map() method
From the course: Data Analysis with Python and Pandas
The map() method
- [Instructor] Okay, so let's talk about a function that many of you may never use, but it can be very handy in certain situations. The map method maps values to a column or to an entire data frame. We can pass a dictionary with existing values as the keys and new values as the values of that dictionary. Let's take a look. So here I've created a mapping dictionary. We're taking some of our product families and mapping them to dietary categories. So we have dairy, we're mapping that to non-vegan. Vegetables is being mapped to vegan and fruits is being mapped to vegan. I'm then creating a column based off of these mapped values that's called vegan question mark. And this is going to be based off of our product column. We're then going to map our mapping dictionary and return our vegan column. So let's take a look. Our keys are going to be mapped to the value selected. So our dairy has been mapped to non-vegan, vegetables has been mapped to vegan, and fruit has been mapped to vegan. And…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
DataFrame basics4m 20s
-
(Locked)
Creating a DataFrame4m 59s
-
(Locked)
Challenge: DataFrame basics53s
-
(Locked)
Solution: DataFrame basics1m 46s
-
(Locked)
Exploring DataFrames: Heads, tails, and sample3m 35s
-
(Locked)
Exploring DataFrames: Info and describe8m 20s
-
(Locked)
Challenge: Exploring a DataFrame3m 12s
-
(Locked)
Solution: Exploring a DataFrame4m 3s
-
(Locked)
Accessing DataFrame columns4m 53s
-
(Locked)
Accessing DataFrame data with .iloc and .loc6m 6s
-
(Locked)
Challenge: Accessing DataFrame data1m 18s
-
(Locked)
Solution: Accessing DataFrame data3m 23s
-
(Locked)
Dropping columns and rows5m 54s
-
(Locked)
Identifying and dropping duplicates7m
-
(Locked)
Challenge: Dropping data1m 1s
-
(Locked)
Solution: Dropping data2m 38s
-
(Locked)
Missing data3m 17s
-
(Locked)
Challenge: Missing data51s
-
(Locked)
Solution: Missing data2m 13s
-
(Locked)
Filtering DataFrames4m 29s
-
(Locked)
Pro tip: The query() method4m 15s
-
(Locked)
Challenge: Filtering DataFrames1m 29s
-
(Locked)
Solution: Filtering DataFrames6m 46s
-
(Locked)
Sorting DataFrames6m 53s
-
(Locked)
Challenge: Sorting DataFrames44s
-
(Locked)
Solution: Sorting DataFrames2m 45s
-
(Locked)
Renaming and reordering columns3m 10s
-
(Locked)
Challenge: Renaming and reordering columns54s
-
(Locked)
Solution: Renaming and reordering columns3m 18s
-
(Locked)
Arithmetic and Boolean column creation6m 22s
-
(Locked)
Challenge: Arithmetic and Boolean columns1m 40s
-
(Locked)
Solution: Arithmetic and Boolean columns3m 58s
-
(Locked)
Pro tip: Advanced conditional columns with select()5m 59s
-
(Locked)
Challenge: The select() function1m 46s
-
(Locked)
Solution: The select() function3m 34s
-
(Locked)
The map() method4m 24s
-
(Locked)
Pro tip: Multiple column creation with assign()8m 19s
-
(Locked)
Challenge: map() and assign()1m 24s
-
(Locked)
Solution: map() and assign()2m 38s
-
(Locked)
The categorical data type5m 31s
-
(Locked)
Type conversion1m 37s
-
(Locked)
Pro tip: Memory usage and data types6m 2s
-
(Locked)
Pro tip: Downcasting numeric data types4m 58s
-
(Locked)
Challenge: DataFrame data types1m 24s
-
(Locked)
Solution: DataFrame data types3m 19s
-
(Locked)
Key takeaways1m 33s
-
(Locked)
-
-
-
-
-
-
-