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 exercício faz parte do curso
Python for MATLAB Users
Instruções do exercício
- 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'.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# 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'],
____['____'],
____['____'])