Selecting Data Based on Condition
To excel in programming, you always need to practice. So, in this task, you must also memorize functions from the previous chapter. If you aren't solid on the functions from the last chapter, look at the hints to revise them.
Compito
Swipe to start coding
- Extract all rows from the columns
'name
' and'hazardous'
using the.loc[]
attribute. - Filter data; extract rows where
'hazardous'
is True. - Output the first five rows of the
data_filtered
dataset.
Soluzione
99
1
2
3
4
5
6
7
8
9
10
11
12
import pandas as pd
data = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/4bf24830-59ba-4418-969b-aaf8117d522e/planet')
# Extract all rows from the columns 'name' and 'hazardous'
data_extracted = data.loc[:, ['name', 'hazardous']]
# Filter data
data_filtered = data_extracted.loc[data_extracted['hazardous'] == True]
# Output dataset
print(data_filtered.head())
Tutto è chiaro?
Grazie per i tuoi commenti!
Sezione 2. Capitolo 2
99
1
2
3
4
5
6
7
8
9
10
11
12
import pandas as pd
data = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/4bf24830-59ba-4418-969b-aaf8117d522e/planet')
# Extract all rows from the columns 'name' and 'hazardous'
data_extracted = data.___[___, ___]
# Filter data
data_filtered = data_extracted.___[data_extracted['___'] ___]
# Output dataset
print(___)
Chieda ad AI
Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione