I have the following Pandas dataframe
df= SlNo Size
1 2
2 3
3 1
4 4
I have created a second column- Size cluster based on whether the attribute is less than 2, equal to 2 or greater than 2
df[['attribute']]=0
i want to assign values to the attribute column so that values less than 2 are given V1, equal to 2 are given V2, and greater than 2 are given V3.
SlNo Size attribute
1 2 V2
2 3 V3
3 1 V1
4 4 V3
I have tried the following loop
if df.Size<=1:
df.attribute="V1"
elif df.Size<=2 & df.Size>1:
df.attribute="V2"
else df.attribute= "V3"
This loop is not able to do the job. I am requesting some help here