Please bin using df.cut
import numpy as np
df['company_size']=pd.cut(df['no_employees']. astype('category').cat.codes*10,[-np.inf,9,19,29,39,49,np.inf], labels=['Very Small','Large','Medium','Very Large','Small','Extremely Large'])
print(df)
no_employees company_size
0 6-25 Small
1 More than 1000 Extremely Large
2 500-1000 Very Large
3 26-100 Medium
4 100-500 Large
5 1-5 Very Small
It works like this:
#Converted no of employees to codes but for ease of defining bins multiplied by ten
df['no_employees']. astype('category').cat.codes*10
#Decided to bin using df.cut
pd.cut(df['no_employees']. astype('category').cat.codes*10,\
[-np.inf,9,19,29,39,49,np.inf], labels=['Very Small','Large','Medium','Very Large','Small','Extremely Large'])
Learn Python for Data Science Course to improve your technical knowledge.