I have a 200000 row dataframe that looks like this df =
index | name | d2b(m) |
---|---|---|
0 | Jon | 199.9 |
1 | Amy | 29 |
2 | Fyn | 19 |
3 | Luc | 30 |
4 | And | 76 |
5 | Pia | 90 |
I am writing a function to classify the "distance to bus stop (d2b)" column into a new column for every 10 meters, expecting:
index | name | d2b (m) | class (<= x meters) |
---|---|---|---|
0 | Jon | 199.9 | 200m |
1 | Amy | 29 | 30m |
2 | Fyn | 19 | 20m |
3 | Luc | 33 | 40m |
4 | And | 76 | 80m |
5 | Pia | 90 | 90m |
Code that works (updated):
numpy.ceil(data["d2b (m)"]/10)*10
CodePudding user response:
This is one way of achieving this:
import math
df['class (<= x meters)'] = math.ceil(df[d2b(m)]/10)*10