Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Selecting Data Based on Condition | Dealing With Conditions
Advanced Techniques in pandas

book
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

  1. Extract all rows from the columns 'name' and 'hazardous' using the .loc[] attribute.
  2. Filter data; extract rows where 'hazardous' is True.
  3. Output the first five rows of the data_filtered dataset.

Ratkaisu

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ää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 2
single

single

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ä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

some-alt