Filter
Exercise 1:
The code below is filtering to keep only hits where country is United States.
Change the filter to get hits from Canada.
| country | position | track_name | artist | streams | duration | continent | |
|---|---|---|---|---|---|---|---|
| 7800 | United States | 1 | The Box | Roddy Ricch | 12987027 | 196.653 | Americas |
| 7801 | United States | 2 | Myron | Lil Uzi Vert | 9163134 | 224.955 | Americas |
| 7802 | United States | 3 | Blueberry Faygo | Lil Mosey | 8043475 | 162.547 | Americas |
| ... | ... | ... | ... | ... | ... | ... | ... |
| 7997 | United States | 198 | Lights Up | Harry Styles | 1606234 | 172.227 | Americas |
| 7998 | United States | 199 | Without Me | Halsey | 1606153 | 201.661 | Americas |
| 7999 | United States | 200 | Enemies (feat. DaBaby) | Post Malone | 1597824 | 196.760 | Americas |
200 rows × 7 columns
Test yourself
Comparing results, which artist is in the top 3 in both (the) United States and Canada?
(click to answer)
Exercise 2:
- Filter to keep tracks where position equals 5.
⚠️: Don't forget to replace all the blanks!
Test yourself
Which artist is in position 5 in South Africa?
(click to answer)
Exercise 3:
Find the top 5 songs in Hong Kong.
In the slides we discussed the == operator. Here is a longer list of some options!
| operator | meaning |
|---|---|
== | is equal to |
< | is less than |
> | is greater than |
⚠️: Don't forget to replace all the blanks!
Exercise 4: looking at The Weeknd's streams
How many times has The Weeknd had over 1,000,000 streams?
Hint:
Do in steps. Run first to get all rows where the artist is The Weeknd, and then modify your code to get where he has over 1,000,000 streams.()
