Openrefine

23 views
Skip to first unread message

Thuta KoKo

unread,
Nov 3, 2022, 9:46:08 AM11/3/22
to OpenRefine
hello I have a problem
I want to transform
from 1 to 100 as 1
from 101 to 200 as 2 with python in openrefine 
my data are 
100
101
102
...
...
...
200
...
300

Owen Stephens

unread,
Nov 4, 2022, 8:14:13 AM11/4/22
to OpenRefine
I don't know the Python off the top of my head but it's straightforward in GREL
If we assume that the value datatype is already a number:
ceil(value/100.0)
or if it's a string:
ceil(value.toNumber()/100.0)

This is dividing by 100 and then finding the ceiling of the result (ceiling is a math function explained at https://en.wikipedia.org/wiki/Floor_and_ceiling_functions - but essentially the lowest integer that is greater than or equal to the input number

Note that I'm dividing by 100.0 (with the decimal) deliberately - this forces a float (a number with a decimal for our purposes) as the result (because of the way OpenRefine handles numbers, you can sometimes get an integer if you simply divide by 100 without the decimal point)

Python will also have a ceiling function if you have to do it with Python

Best wishes

Owen
Reply all
Reply to author
Forward
0 new messages