Min value in a record

17 views
Skip to first unread message

Flavio Pompermaier

unread,
Apr 18, 2019, 10:22:54 AM4/18/19
to openref...@googlegroups.com
Hi to all,
When working in record mode, is there a way to add a columm containig the minimum value of a given column?

Best,
Flavio

Ettore Rizza

unread,
Apr 18, 2019, 10:38:56 AM4/18/19
to OpenRefine Development
Hi Flavio, 

in record mode, the following formula produces an array containing all the elements of the record for the column in question.

row.record.cells['your column name'].value

OpenRefine does not have an array function min(), but we can use a sort() and select the first element:

row.record.cells['your column name'].value.sort()[0]

Perhaps a cleaner solution is to use Python/Jython instead:

array = row.record.cells['your column name'].value
return min(array)


In any case, the result will look like this:

screenshot-127.0.0.1-3333-2019.04.18-16-35-11.png


You can then use an "Edit cells/Blank Down" to store the minimum value only once per record.

Hope this helps,

Ettore



Thad Guidry

unread,
Apr 18, 2019, 10:57:38 AM4/18/19
to openref...@googlegroups.com

OpenRefine does not have an array function min(), but we can use a sort() and select the first element:

row.record.cells['your column name'].value.sort()[0]

Ettore,

Would it be helpful to have that min() function ?

Ettore RIZZA

unread,
Apr 18, 2019, 11:03:27 AM4/18/19
to openref...@googlegroups.com
Hi Thad,

Obviously, it is always interesting to have a maximum of methods for all the data types, but is it worthwhile to waste time on that when we could just switch to Python or use a little trick? Not sure. 

Ettore


--
You received this message because you are subscribed to the Google Groups "OpenRefine Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openrefine-de...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thad Guidry

unread,
Apr 18, 2019, 1:12:06 PM4/18/19
to openref...@googlegroups.com
I was asking "would it be helpful"... in the sense that its an often performed or needed function for folks.  But perhaps we don't know.  I checked our issues and didn't see an ask that was like that previously.

I do know (and we have issues) on making working with Arrays and Records to be easier.  This could be some sub-functionality whenever we work on that.


Reply all
Reply to author
Forward
0 new messages