My question is the inverse of this question: How to check if any value of a column is in a range (in between two values) in Pandas?
Instead of having a value in the column that I am trying to compare to a specific range, I actually have a range in the column and I'm trying to get all the rows from the DataFrame for a specific value.
data = {'Reward_Level':['0-4','0-4', '5-10', '5-10', '11-16'],
'reward' :['1', '2', '3', '4', '10']}
df = pd.DataFrame(data)
value = 2 # want to return all the rows whose range in 'Reward_Level' covers this value
df = df["How do I do this part?"]
# df >> gives me the rows for ['0-4', '1'] and ['0-4', '2']
The way I know how to do it is to break out Reward_Level
into two separate columns and compare against the minimum and then also compare against the maximum, but is there a way to do this without breaking these into new columns?