In a python pandas Jupiter notebook: I have a series of data in a clolum named "Course Age" and the following code of which the first three lines were given
In a python pandas Jupiter notebook: I have a series of data in a clolum named "Course Age" and the following code of which the first three lines were given.
-I need to put this into these categories: unknown, 17 and under, 18-25, 26-35, 36-45, 46-55, and 56+
-I need to convert all the strings into the text "unknown" and then into the category "unknown".
-This is the code I am working with and I am getting a type float/ string error. I know I have a problem with my strings and numbers but I don't know how to fix it. Please tell me what I did wrong and what I should be doing.
array(['44', '49', '40', '23', nan, '53', '33', '43', '56', '64', '37',
'48', '54', '36', '45', '25', '34', '35', '38', '58', '50', '47',
'16', '52', '63', '65', '41', '27', '31', '59', '61', '46', '42',
'62', '29', '39', '32', '28', '69', '67', '30', '22', '51', '70',
'24', '19', 'Old enough', '57', '60', '66', '12', 'Many', '55',
'72', '?', '21', '11', 'no', '9', '68', '20', '6', '10', '71',
'13', '26', '45-55', '7', '39.4', '74', '18', 'older as heck',
'17', '15', '8', '75', '5u', 'Enough', 'Over 50', '90', '76',
'sixty-nine', 'ancient', '77', 'Young', 'old', '73', '70 1/2', '14',
'NAME IS STEVE', '4', '59 on Tuesday', 'old enough',
'your momA', 'I can remember',
'60+'], dtype=object)
# create True/False index
age_index = student['COURSE AGE'].str.isnumeric()
# for the index, fill missing values with False
age_index = age_index.fillna(False)
# select Age column for only those False values from index and code as missing
student.loc[~age_index, 'COURSE AGE'] = np.nan
ser1=candy['COURSE AGE']
ser1 = pd.cut(ser1,6, precision=0, labels=['17 and under', '18-25', '26-35', '36-45', '46-55', '56+'])
ser1
Trending now
This is a popular solution!
Step by step
Solved in 2 steps