Course Content
Advanced Techniques in pandas
1. Get Familiar With Indexing and Selecting Data
2. Dealing With Conditions
Advanced Techniques in pandas
Is Data in ...?
In this section, we will continue extracting data using specific conditions. Here, you will become familiar with the helpful function called .isin()
. But firstly, you need to examine the dataset. Look at the first five rows:
Now, take a look at the example and the explanation below:
Explanation:
If you remember, we always put the conditions inside the .loc[]
function. Here, we do the same. The .isin(list)
function checks if the values from the column are in the array. In our case, we check if values from the column 'Manufacturer'
are in the list models
.
Task
Your task here is to extract data about cars where values from the column 'Color'
are equal to 'Grey'
, 'White'
, 'Black'
. Follow the algorithm to easily manage with the task:
- Create the
colors
list with the elements'Grey'
,'White'
,'Black'
(in this order). - Extract values from the column
'Color'
that the listcolor
consists of. Use the.loc[]
function. - Output the last five rows of the dataset
data_extracted
.
Everything was clear?