Right way to categorize an int variable with python?

Can someone help me to see if this could be a right way to create a new variable from an integer variables, or if there could be another to do so

I have a data frame with world ranking universities and i want to group them by their ranking

    def create_category(ranking):
    if (ranking >= 1) & (ranking <= 100):
        return "First Tier Top Unversity"
    elif (ranking >= 101) & (ranking <= 200):
        return "Second Tier Top Unversity"
    elif (ranking >= 201) & (ranking <= 300):
        return "Third Tier Top Unversity"
    return "Other Top Unversity"
🟢 Solution

Your quickest way is to use np.where:

import numpy as np
df['cat'] = 'Other Top Unversity' # default
df['cat'] = np.where((df['ranking']>=1) &  (df['ranking']<=100), 'First Tier Top Unversity', df['cat'])
df['cat'] = np.where((df['ranking']>=101) &  (df['ranking']<=200), 'Second Tier Top Unversity', df['cat'])
df['cat'] = np.where((df['ranking']>=201) &  (df['ranking']<=300), 'Third Tier Top Unversity', df['cat'])