LoslegenKostenlos loslegen

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_DATE column)
  • Airport (AIRPORT column)
  • Type of aircraft (ATYPE column)
  • Severity of the damage (DAMAGE column)

Diese Übung ist Teil des Kurses

Python for MATLAB Users

Kurs anzeigen

Anleitung zur Übung

  • Print the first five lines of the wildlife_strikes DataFrame.
  • Construct a for loop that iterates through each row of wildlife_strikes.
  • Create a conditional statement that determines if SPECIES is a 'Snowy egret'.
  • If your if statement evaluates to True, print the 'INCIDENT_DATE', 'AIRPORT', ' ATYPE', and 'DAMAGE'.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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'],
              ____['____'],
              ____['____'])
Code bearbeiten und ausführen