Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara 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.

Compito

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.

Soluzione

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?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 2. Capitolo 2
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

expand
ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

some-alt