Question: Question 2 Merge flights _ df dataframe with airports _ df dataframe and return the number of departing flights ( NUM _ FLIGHTS ) per

Question 2
Merge flights_df dataframe with airports_df dataframe and return the number of departing flights (NUM_FLIGHTS) per airport (IATA_CODE) across the year.
[4]:
import pandas as pd
def flights_per_airport(flights_df, airports_df):
num_flights_df=flights_df.merge(airports_df, left_on='ORIGIN_AIRPORT ', right_on='IATA_CODE', how=' left' )
num_flights_df=flights_df.groupby(['IATA_CODE'])['FLIGHT_NUMBER'].count ().reset_index()
num_flights_df. rename (columns={'FLIGHT_NUMBER' : 'NUM_FLIGHTS'}, inplace=True)
num_flights_df.drop(columns=['IATA_CODE'], inplace=True)
return num_flights_df
flights_df_raw = pd.read_csv('assets/flights.csv', low_memory=False)
airports_df = pd.read_csv('assets/airports.csv')
num_flights_df = flights_per_airport(flights_df_raw.copy(), airports_df.copy())
print(num_flights_df)
Key error 'IATA_CODE'
How do i fix?
 Question 2 Merge flights_df dataframe with airports_df dataframe and return the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!