Linked Questions

Popular Questions

In my df I have a column of results:

Results 
755
1065
2733
40
116
241
345
176
516
5000

What I would like to do is replace all values <=55 with the string Low and all values >=3500 with the string High, retaining all other values. So the end result would be:

Results 
755
1065
2733
Low
116
241
345
176
516
High

The issue is if you do a simple RM.loc[RM["Result"]<=55,"Result"]="Low", then it sets the entire column as strings and won't allow you to filter based on the second condition result>=3500. So I accomplished what I wanted by doing

RM.loc[RM["Result"]<=55,"Result"]=-111
RM.loc[RM["Result"]>=3511,"Result"]=999

RM.loc[RM["Result"]==-111,"Result"]="Low"
RM.loc[RM["Result"]==999,"Result"]="High"

But there must be a concise, one-line way of doing this I just can't think of it?

Related Questions