Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Making Your Code Beautiful | Dealing With Conditions
Advanced Techniques in pandas
course content

Kursusindhold

Advanced Techniques in pandas

Advanced Techniques in pandas

1. Getting Familiar With Indexing and Selecting Data
2. Dealing With Conditions
3. Extracting Data
4. Aggregating Data
5. Preprocessing Data

book
Making Your Code Beautiful

Let's make our code more convenient and more readable. By the way, it is essential to make your code understandable for your coworkers.

To simplify the code, we can write the condition first and then put it into the .loc[] function; look at the example from the previous chapter:

python

The first and second methods lead to the same output, but the second is much better for understanding because you can work with two conditions separately, and the statement within the .loc[] function takes up less space.

Opgave

Swipe to start coding

Your task here is to consolidate knowledge from this chapter. You need to extract data on small asteroids with a high magnitude, or hazardous ones. To do so, follow the algorithm:

  1. Write the first condition: values from the column'est_diameter_min' are less than 0.01. Assign it to the variable condition_1.
  2. Write the second condition: values from the column 'absolute_magnitude' are greater than 20. Assign it to the variable condition_2.
  3. Write the third condition: values from the column 'hazardous' are equal to False. Assign it to the variable condition_3.
  4. Write the general condition that satisfies the requirement: (condition_1 and condition_2) or condition_3.

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 2. Kapitel 4
toggle bottom row

book
Making Your Code Beautiful

Let's make our code more convenient and more readable. By the way, it is essential to make your code understandable for your coworkers.

To simplify the code, we can write the condition first and then put it into the .loc[] function; look at the example from the previous chapter:

python

The first and second methods lead to the same output, but the second is much better for understanding because you can work with two conditions separately, and the statement within the .loc[] function takes up less space.

Opgave

Swipe to start coding

Your task here is to consolidate knowledge from this chapter. You need to extract data on small asteroids with a high magnitude, or hazardous ones. To do so, follow the algorithm:

  1. Write the first condition: values from the column'est_diameter_min' are less than 0.01. Assign it to the variable condition_1.
  2. Write the second condition: values from the column 'absolute_magnitude' are greater than 20. Assign it to the variable condition_2.
  3. Write the third condition: values from the column 'hazardous' are equal to False. Assign it to the variable condition_3.
  4. Write the general condition that satisfies the requirement: (condition_1 and condition_2) or condition_3.

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 2. Kapitel 4
Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Vi beklager, at noget gik galt. Hvad skete der?
some-alt