Question: Here is my code and attached the error attached the error at the end, please advice to fix it . . . . . .
Here is my code and attached the error attached the error at the end, please advice to fix it import pandas as pd
# Step : Data Preparation
airportsdf pdreadcsv UserssureshvelusamyDocumentsKarthikaPY scriptsAirportCodes.csv
ticketsdf pdreadcsv UserssureshvelusamyDocumentsKarthikaPY scriptsTicketscsv
flightsdf pdreadcsv UserssureshvelusamyDocumentsKarthikaPY scriptsFlightscsv
# Perform necessary data cleaning and filtering steps
ticketsdfITINFARE' ticketsdfITINFARE'strreplace$astypefloat
ticketsdfITINFARE' ticketsdfITINFARE'astypeInt
# Step : Identify the busiest round trip routes
filteredflightsdf flightsdfflightsdfCANCELLED
RoundtripTickets ticketsdfticketsdfROUNDTRIP
MLAirportmediumairport', 'largeairport'
roundtriproutes filteredflightsdfgroupbyORIGIN 'DESTINATION'sizeresetindexname'Count'
topbusiestroutes roundtriproutes.nlargest 'Count'
# Step : Calculate the profitability of round trip routes
revenueperroute RoundtripTickets.groupbyORIGIN 'DESTINATION'ITINFARE'sumresetindexname'TotalRevenue'nlargest 'TotalRevenue'
revenueperrouteORIGIN pdtonumericrevenueperrouteORIGIN errors'coerce'
revenueperrouteDESTINATION pdtonumericrevenueperrouteDESTINATION errors'coerce'
revenueperrouteTotalRevenue pdtonumericrevenueperrouteTotalRevenue errors'coerce'
printrevenueperroute.dtypes
# Calculate the cost components for each route
costpermile
costpermileother
airportcostmedium
airportcostlarge
delaycostpermin
def calculateroutecostroute:
origin, dest route
distance flightsdfflightsdfORIGIN origin & flightsdfDESTINATION destDISTANCEmean
numroundtrips roundtriproutesroundtriproutesORIGIN origin & roundtriproutesDESTINATION destCountvalues
airportcost airportsdfairportsdfIATACODE' originTYPEvalues 'mediumairport' airportcostmedium airportsdfairportsdfIATACODE' destTYPEvalues 'mediumairport' airportcostmedium airportsdfairportsdfIATACODE' originTYPEvalues 'largeairport' airportcostlarge airportsdfairportsdfIATACODE' destTYPEvalues 'largeairport' airportcostlarge
operationalcost distance costpermile distance costpermileother airportcost
delaycost filteredflightsdffilteredflightsdfORIGIN origin & filteredflightsdfDESTINATION destARRDELAY'sum filteredflightsdffilteredflightsdfORIGIN dest & filteredflightsdfDESTINATION originDEPDELAY'sum delaycostpermin
totalcost operationalcost delaycost
return totalcost numroundtrips
costperroute revenueperroute.applylambda x: calculateroutecostxORIGIN xDESTINATION axis
profitperroute revenueperrouteTotalRevenue costperroute
topprofitableroutes pdDataFrame
'Origin': topbusiestroutesORIGIN
'Dest': topbusiestroutesDESTINATION
'TotalRevenue': revenueperrouteTotalRevenue
'TotalCost': costperroute,
'Profit': profitperroute
nlargest 'Profit'
# Step : Recommend round trip routes to invest in
recommendedroutes topprofitableroutes.nlargest 'Profit'Origin 'Dest'
# Step : Calculate the breakeven point for upfront airplane costs
upfrontairplanecost # $ million
breakevenflights
for route in recommendedroutes.itertuplesindexFalse:
origin, dest route
revenue revenueperrouterevenueperrouteORIGIN origin & revenueperrouteDESTINATION destTotalRevenuevalues
cost costperrouterevenueperrouteORIGIN origin & revenueperrouteDESTINATION dest
breakevenpoint upfrontairplanecost revenue cost
breakevenflights.appendbreakevenpoint
# Step : Recommend Key Performance Indicators KPIs
recommendedkpis Load Factor', Ontime Performance', 'Customer Satisfaction'
# Print the results
print Busiest Round Trip Routes:"
printtopbusiestroutes
print
Most Profitable Round Trip Routes:"
printtopprofitableroutes
print
Recommended Round Trip Routes:"Error IndexError Traceback most recent call last Cell In line costperroute revenueperroute.applylambda x: calculateroutecostxORIGIN x
