The filter verb

The filter verb

The filter verb

Filter for top songs

(music_top200
  >> filter(_.position == 1)
)

Filter step 1: start the block

(music_top200

)

Filter step 2: pipe operator and verb name

(music_top200
  >> filter()
)

Filter step 3: write the operation

(music_top200
  >> filter(_.position == 1)
)

Filter for top songs

(music_top200
  >> filter(_.position == 1)
)
country position track_name artist streams duration continent
0 Argentina 1 Tusa KAROL G 1858666 200.960 Americas
200 Austria 1 Blinding Lights The Weeknd 229576 201.573 Europe
400 Australia 1 Blinding Lights The Weeknd 1757343 201.573 Oceania
... ... ... ... ... ... ... ...
11800 Uruguay 1 Tusa KAROL G 120175 200.960 Americas
12000 Viet Nam 1 Sweet Night V 189261 214.259 Asia
12200 South Africa 1 The Box Roddy Ricch 94422 196.653 Africa

62 rows × 7 columns

Filter for country

(music_top200
  >> filter(_.country == "United States")
)
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

Filter with two variables

(music_top200
  >> filter(_.position == 1, _.country == "United States")
)
country position track_name artist streams duration continent
7800 United States 1 The Box Roddy Ricch 12987027 196.653 Americas

1 rows × 7 columns

Let’s practice!