I am trying to group & assign a numeric value to a column 'neighborhood' having values like: #Queens#Jackson Heights#, #Manhattan#Upper East Side#Sutton Place#, #Brooklyn#Williamsburg#,#Bronx#East Bronx#Throgs Neck#. (Values have 2,3 sometimes 4,5 hashtags) I used normal if else loop, which worked fine for first 3 values, as given in the image attached. But m not sure if its working right. Please help me group and assign values to then those groups. [the if else loop i used is as below: *
*# Create a list to store the data
grades = []
# For each row in the column,
for row in new_train1['neighborhood']:
# if more than a value,
if row > '#Queens#':
# Append a num grade
grades.append('1')
# else, if more than a value,
elif row > '#Manhattan#':
# Append a letter grade
grades.append('2')
# else, if more than a value,
elif row > '#Bronx#':
# Append a letter grade
grades.append('3')
# else, if more than a value,
elif row > '#Brooklyn#':
# Append a letter grade
grades.append('4')
# else, if more than a value,
else:
# Append a failing grade
grades.append('0')