Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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?
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Implementing Ai And Machine Learning For Business Optimization

Authors: Robert K Wiley

1st Edition

B0CPQJW72N, 979-8870675855

More Books

Students also viewed these Databases questions

Question

1. Which position would you take?

Answered: 1 week ago