Question: My Problems: Problem 1 : My problem is , If I convert Origin and Destination as numeric all the values become NaN and I am
My Problems:
Problem:
My problem is If I convert Origin and Destination as numeric all the values become NaN and I am getting error as below:
IndexError Traceback most recent call last
Cell In line
for route in recommendedroutes.itertuplesindexFalse:
origin, dest route
revenue revenueperrouterevenueperrouteORIGIN origin & revenueperrouteDESTINATION destTotalRevenuevalues
cost costperrouterevenueperrouteORIGIN origin & revenueperrouteDESTINATION dest
breakevenpoint upfrontairplanecost revenue cost if revenue cost else floatinf
IndexError: index is out of bounds for axis with size
Problem :
But if I dont convert them into Numeric then I am getting the Error as
TypeError Traceback most recent call last
Cell In line
return totalcost numroundtrips
# Apply cost calculation and compute profitability
costperroute revenueperroute.apply
lambda x: calculateroutecostxORIGIN xDESTINATION if not pdisnaxORIGIN and not pdisnaxDESTINATION else
axis
profitperroute revenueperrouteTotalRevenue costperroute
topprofitableroutes pdDataFrame
Origin: topbusiestroutesORIGIN
Dest: topbusiestroutesDESTINATION
Profit: profitperroute
nlargest 'Profit'
File LibraryFrameworksPythonframeworkVersionslibpythonsitepackagespandascoreframepy: in DataFrame.applyself func, axis, raw, resulttype, args, byrow, engine, enginekwargs, kwargs
from pandas.core.apply import frameapply
op frameapply
self
funcfunc,
kwargskwargs,
def suma axisNone, dtypeNone, outNone, keepdimsFalse,
initialNoValue, whereTrue:
return umrsuma axis, dtype, out, keepdims, initial, where
TypeError: unsupported operand types for : 'float' and str
I thought of using anther column Distance from flights csv file which gives the Distance between Origin and Destination Airports in Miles but that has some data issues which I couldnt fix all of them
By default it is dtypeobject I couldnt convert it to numeric when I tried I got following errors
Error Couldnt convert string Hundred to numericI fixed it by replacing it with number
Error Couldnt convert string Twenty to numeric I fixed it by replacing it with number
Error Couldnt convert string to numeric
When I tried to convert to numeric getting below error:
TypeError Traceback most recent call last
Cell In line
filteredflightsdfDISTANCEfillna
FfilteredflightsdfreplaceDISTANCE:Hundred: 'Twenty':Hundred::::
FastypeInt
#roundtripcost filteredflightsdfgroupbyORIGIN 'DESTINATION'DISTANCEsumresetindexname'Toipcost'
print F
File LibraryFrameworksPythonframeworkVersionslibpythonsitepackagespandascoregenericpy: in NDFrame.astypeself dtype, copy, errors
results
ser.astypedtype copycopy, errorserrors for ser in self.items
else:
# else, only a single dtype is given
newdata self.mgrastypedtypedtype, copycopy, errorserrors
res self.constructorfrommgrnewdata, axesnewdata.axes
return res.finalizeself method"astype"
File LibraryFrameworksPythonframeworkVersionslibpythonsitepackagespandascoreinternalsmanagerspy: in BaseBlockManager.astypeself dtype, copy, errors
elif usingcopyonwrite:
copy False
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
