Hello Dataquest community!
Can someone help me understand why I am getting an error if I start my function code to search for NaN values first? or is there is something else that I am unable to identify? Thanks!
Screen Link:
https://app.dataquest.io/m/348/guided-project%3A-clean-and-analyze-employee-exit-surveys/9/clean-the-service-column
My Code:
def career_stage(val):
if pd.isnull(val):
return np.nan
elif val < 3:
return "New"
elif 3 <= val <7:
return "Experienced"
elif 7 <= val <11:
return "Established"
else:
return "Veteran"
combined_updated['service_cat'] = combined_updated['institute_service'].apply(career_stage)
What I expected to happen:
What actually happened:
TypeErrorTraceback (most recent call last)
<ipython-input-36-7d18d0064857> in <module>()
11 return "Veteran"
12
---> 13 combined_updated['service_cat'] = combined_updated['institute_service'].apply(career_stage)
14
/dataquest/system/env/python3/lib/python3.4/site-packages/pandas/core/series.py in apply(self, func, convert_dtype, args, **kwds)
2549 else:
2550 values = self.asobject
-> 2551 mapped = lib.map_infer(values, f, convert=convert_dtype)
2552
2553 if len(mapped) and isinstance(mapped[0], Series):
pandas/_libs/src/inference.pyx in pandas._libs.lib.map_infer()
<ipython-input-36-7d18d0064857> in career_stage(val)
2 if pd.isnull(val):
3 return np.nan
----> 4 elif val < 3:
5 return "New"
6 elif 3 <= val <7:
TypeError: unorderable types: str() < int()