Finding certain rows in a DataFrame
Bird strikes by aircraft are both dangerous to human life and of great concern to conservation efforts. Luckily, the Federal Aviation Administration has been tracking wildlife strikes for nearly 30 years.
You're going to use for loops to explore the FAA Wildlife Strikes database. A pandas DataFrame that contains wildlife strikes by aircraft in California recorded from 1990 to 2018 is loaded into your session. You want to find incidences that involve Snowy egrets, a migratory bird that winters in California. For each incident, display:
- Date of incident (
INCIDENT_DATEcolumn) - Airport (
AIRPORTcolumn) - Type of aircraft (
ATYPEcolumn) - Severity of the damage (
DAMAGEcolumn)
Este ejercicio forma parte del curso
Python for MATLAB Users
Instrucciones del ejercicio
- Print the first five lines of the
wildlife_strikesDataFrame. - Construct a for loop that iterates through each
rowofwildlife_strikes. - Create a conditional statement that determines if
SPECIESis a'Snowy egret'. - If your if statement evaluates to
True, print the'INCIDENT_DATE','AIRPORT',' ATYPE', and'DAMAGE'.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# Print the first few lines of the wildlife_strikes DataFrame
print(____)
# Loop through each row in wildlife_strikes
for i, ____ in ____.iterrows():
# Use an if statement to check the species of this row
if row['____']=='____':
# Print the INCIDENT_DATE, AIRPORT, ATYPE, and DAMAGE
print(row['____'],
____['AIRPORT'],
____['____'],
____['____'])