Currently using Pandas and Numpy. I have a dataframe named 'df'. Lets say I have the below data, how can I give the third column a value based on a between clause? I'd like to treat this as a vectorised approach if possible to maintain the speed of what I already have.
I've tried lambda functions, but frankly I don't understand what I'm doing and I'm getting errors such as the object has no attribute 'between'.
General approach - using a non vectorised approach:
NOTE: I am looking for a way to make this vectorised.
If df.['Col2'] is between 0 and 10
df.['Col 3'] = 1
Elseif df.['Col2'] is between 10.01 and 20
df.['Col3'] = 2
Else if df.['Col2'] is between 20.1 and 30
df.['Col3'] = 3
Sample set
+------+------+------+
| Col1 | Col2 | Col3 |
+------+------+------+
| a | 5 | 1 |
| b | 10 | 1 |
| c | 15 | 2 |
| d | 20 | 2 |
| e | 25 | 3 |
| f | 30 | 3 |
| g | 1 | 1 |
| h | 11 | 2 |
| i | 21 | 3 |
| j | 7 | 1 |
+------+------+------+
Many thanks
