Adding np.where solution:
df['col1']= np.where(df['col'] < 3, 1,np.where( (df['col'] >3 )& (df['col'] <5),2,3))
The general logic is:
np.where(Condition, 'true block','false block').
With each true / false block, you can in turn be invested again.
Also, check out & for ANDing! (not 'and') ANDing! (not 'and') ANDing! (not 'and') ANDing! (not 'and')
source share