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.
Tehtävä
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.
Ratkaisu
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())
Oliko kaikki selvää?
Kiitos palautteestasi!
Osio 2. Luku 2
single
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(___)
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme