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.
Pro tip: The query() method
From the course: Data Analysis with Python and Pandas
Pro tip: The query() method
- [Instructor] All right, so let's go ahead and take a look at one of my favorite data frame methods in Pandas. The query method lets us use SQL like syntax to filter data frames. We can specify any number of filtering conditions in a single line by using the 'and' and 'or' keywords. Here I'm calling the query method on our retail data frame, and I'm passing through the query, family in cleaning or dairy. And sales is greater than zero. So I probably don't need to explain the syntax to you given how intuitive it is. But what we're doing is filtering down to rows where our family is either cleaning or dairy, and our sales are greater than zero. And if we take a look at our results, we can see that our family column only has values cleaning and dairy, and we don't see any zero values for sales. Particularly if you're coming from an SQL background. This type of syntax is going to feel very comfortable and probably feel a little bit more intuitive than the Boolean mask building that we've…
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)
-
-
-
-
-
-
-