I need to add new columns Label with labels which are dependent on values of another column value.
i.e. if value < -50 so label "Critical" and if it between -50&-40 so it will "Major" and if it between -40&-30 so it will "Standard" and if it >-30 so it will "Normal"
My code is not working
X['Label'][X['Value']>=-30]="Normal"
X['Label'][X['Value']<-30][X['RSLDEV']>=-40]='Standard'
X['Label'][X['Value']<-40][X['RSLDEV']>=-50]="Major"
X['Label'][X['Value']<-50]="Critical"
Note: I don't need to use for loop
Output shall be as following:
Values Label
-52.13446 Critical
-49.782227 Major
-46.363266 Major
-45.591278 Major
-45.591278 Major
-44.51123 Major
-42.430695 Major
-40.330933 Major
-35.779465 Standard
-35.779465 Standard
-29.621201 Normal
It failed with for loop :
X['Label']='Normal'
for x in range(len(X['Value'])):
if X['Value'].iloc[x] >=-6 and X['Value'].iloc[x] <-3:
X['Label']='Standard'
elif X['Value'].iloc[x] >=-12 and X['Value'].iloc[x] <-6:
X['RSLDEVD']='Major'
elif X['Value'].iloc[x] <-12:
X['RSLDEVD']='Critical'
else:
pass