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

Manejando Varias CondicionesManejando Varias Condiciones

A veces necesitamos que se apliquen varias condiciones. Por ejemplo, queremos extraer datos sobre asteroides con un diámetro mínimo pequeño. Pero, ¿cómo escribimos dos condiciones simultáneamente? Fíjate en la tabla:

SignoUsoEjemplo de PythonEquivalente en sentencias booleanas
Se utiliza cuando queremos que se cumplan la primera y la segunda condición.
Se utiliza cuando queremos que se cumpla la primera condición o la segunda.

El ejemplo se incluyó para ayudarle a tratar este tema. Este código extrae datos sobre asteroides grandes y peligrosos, donde el diámetro mínimo estimado es mayor de 3.5 kilómetros y peligroso es `Verdadero``.

Sign Usage Python Example Equivalent in Boolean Statements
& This is used when we want to make the first and the second conditions satisfied. data.loc[condition_1 & condition_2] and
| This is used when we want to make the first or the second conditions satisfied. data.loc[condition_1 | condition_2] or

The example was included to help you deal with this topic. This code extracts data on large and hazardous asteroids, where the minimum estimated diameter is larger than 3.5 kilometers and 'hazardous' is True.

In the output, you can see all the rows that satisfy these two conditions:

  • est_diameter_min > 3.5,
  • hazardous == True.

En la salida, puede ver todas las filas que cumplen una de estas dos condiciones:

  • diámetro_mínimo < 0.0005,
  • máximo_diámetro > 20.

In the output, you can see all the rows that satisfy one of these two conditions:

  • est_diameter_min < 0.0005,
  • est_diameter_max > 20.

Tarea

Your task here is to extract data on very bright and not hazardous asteroids. The code should satisfy two conditions:

  • 'absolute_magnitude' is larger than or equal to 25;
  • 'hazardous' is False.

After this, output the random 5 rows of the data_extracted.

¿Todo estuvo claro?

Sección 2. Capítulo 3
toggle bottom row
course content

Contenido del Curso

Advanced Techniques in pandas

Manejando Varias CondicionesManejando Varias Condiciones

A veces necesitamos que se apliquen varias condiciones. Por ejemplo, queremos extraer datos sobre asteroides con un diámetro mínimo pequeño. Pero, ¿cómo escribimos dos condiciones simultáneamente? Fíjate en la tabla:

SignoUsoEjemplo de PythonEquivalente en sentencias booleanas
Se utiliza cuando queremos que se cumplan la primera y la segunda condición.
Se utiliza cuando queremos que se cumpla la primera condición o la segunda.

El ejemplo se incluyó para ayudarle a tratar este tema. Este código extrae datos sobre asteroides grandes y peligrosos, donde el diámetro mínimo estimado es mayor de 3.5 kilómetros y peligroso es `Verdadero``.

Sign Usage Python Example Equivalent in Boolean Statements
& This is used when we want to make the first and the second conditions satisfied. data.loc[condition_1 & condition_2] and
| This is used when we want to make the first or the second conditions satisfied. data.loc[condition_1 | condition_2] or

The example was included to help you deal with this topic. This code extracts data on large and hazardous asteroids, where the minimum estimated diameter is larger than 3.5 kilometers and 'hazardous' is True.

In the output, you can see all the rows that satisfy these two conditions:

  • est_diameter_min > 3.5,
  • hazardous == True.

En la salida, puede ver todas las filas que cumplen una de estas dos condiciones:

  • diámetro_mínimo < 0.0005,
  • máximo_diámetro > 20.

In the output, you can see all the rows that satisfy one of these two conditions:

  • est_diameter_min < 0.0005,
  • est_diameter_max > 20.

Tarea

Your task here is to extract data on very bright and not hazardous asteroids. The code should satisfy two conditions:

  • 'absolute_magnitude' is larger than or equal to 25;
  • 'hazardous' is False.

After this, output the random 5 rows of the data_extracted.

¿Todo estuvo claro?

Sección 2. Capítulo 3
toggle bottom row
some-alt