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

bookSetting Condition

In this section, we will learn how to extract data using specific conditions, but first I want you to examine the data set we will use. It includes data on asteroids:

  • id - Unique identifier for each asteroid;
  • name - Name given by NASA;
  • est_diameter_min - Minimum estimated diameter in kilometers;
  • est_diameter_max - Maximum estimated diameter in kilometers;
  • absolute_magnitude - Describes how light the object is;
  • hazardous - Boolean feature that shows whether asteroid is harmful or not.

You are already familiar with the .loc[] attribute, but here we will expand its possibilities.

One of the most useful tools is to set conditions on a column to extract specific values. So, you just put the condition of the column inside the .loc[] attribute. Look at the several conditions and outputs.

  • data.loc[data['est_diameter_max'] < 0.005].head() - extracts the first five rows where the column values 'est_diameter_max' are less then 0.005;
  • data.loc[data['absolute_magnitude'] >= 30].head() - extracts the first five rows where the column values 'absolute_magnitude' are greater than or equal to 30.
question mark

Your task is to choose all correct forms of setting conditions on the column 'est_diameter_min'. Please look; this column is numerical, so think about the conditions we can use with numbers.

Select the correct answer

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 1

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

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

Suggested prompts:

Can you explain what each column in the asteroid dataset means?

How can I use conditions to filter the asteroid data?

Can you give more examples of using .loc[] with different conditions?

Awesome!

Completion rate improved to 3.03

bookSetting Condition

Pyyhkäise näyttääksesi valikon

In this section, we will learn how to extract data using specific conditions, but first I want you to examine the data set we will use. It includes data on asteroids:

  • id - Unique identifier for each asteroid;
  • name - Name given by NASA;
  • est_diameter_min - Minimum estimated diameter in kilometers;
  • est_diameter_max - Maximum estimated diameter in kilometers;
  • absolute_magnitude - Describes how light the object is;
  • hazardous - Boolean feature that shows whether asteroid is harmful or not.

You are already familiar with the .loc[] attribute, but here we will expand its possibilities.

One of the most useful tools is to set conditions on a column to extract specific values. So, you just put the condition of the column inside the .loc[] attribute. Look at the several conditions and outputs.

  • data.loc[data['est_diameter_max'] < 0.005].head() - extracts the first five rows where the column values 'est_diameter_max' are less then 0.005;
  • data.loc[data['absolute_magnitude'] >= 30].head() - extracts the first five rows where the column values 'absolute_magnitude' are greater than or equal to 30.
question mark

Your task is to choose all correct forms of setting conditions on the column 'est_diameter_min'. Please look; this column is numerical, so think about the conditions we can use with numbers.

Select the correct answer

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 1
some-alt