Count rows in a record

654 views
Skip to first unread message

olivia solis

unread,
Dec 4, 2019, 9:38:46 AM12/4/19
to OpenRefine
Hi all,

Apologies if I am missing something obvious or this has been answered elsewhere, but I am trying to count the number of rows in a record and add that count in a new column. For example, in the following data:

Section Box
1 2.325/A142
  2.325/A143
2 2.325/B55
  2.325/B56
  2.325/B57
  2.325/B58
  2.325/B93

I am trying to count the number of boxes in each section. I would like the count to appear in the the first row of a new column in the project. I looked through some of the posts in this group but wasn't able to find the answer.

Thanks!
Olivia

Thad Guidry

unread,
Dec 4, 2019, 9:50:43 AM12/4/19
to openr...@googlegroups.com
You can just use our nice Text Facet on the column you want to inspect. (Make sure you are in Records mode)
It has a row counter built in.
Additionally, you can click on the "X choices" blue link in the top right corner of it to get a text box that you can copy/paste all the count values and paste into whatever you need.



--
You received this message because you are subscribed to the Google Groups "OpenRefine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openrefine+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openrefine/9c042d7d-8c08-4f5f-b18d-e41ea034be6e%40googlegroups.com.

wl

unread,
Dec 4, 2019, 2:12:46 PM12/4/19
to OpenRefine
Hi!

You can get the result with help of some temporary columns.
In records mode, create a new column based on "Box", name "from", GREL "row.record.fromRowIndex".
Another new column based on "from", name "to", GREL "row.record.toRowIndex".

Result column "nr", based on "to", GREL "value-cells.from.value"

Then you should have a table as below and you can still move the "nr" column to the left.

Wolf

Section	Box		from	to	nr
1	2.325/A142	0	2	2
	2.325/A143	0	2	2
2	2.325/B55	2	7	5
	2.325/B56	2	7	5
	2.325/B57	2	7	5
	2.325/B58	2	7	5
	2.325/B93	2	7	5

magdmartin

unread,
Dec 4, 2019, 9:44:26 PM12/4/19
to OpenRefine
First create a new column count with the following GREL to count the number of row in each record with row.index - row.record.fromRowIndex+1  (see more details here regarding the index founction

Then select the last value for each in the column count with  row.record.cells["count"].value[-1]

Regards
Martin

Thad Guidry

unread,
Dec 5, 2019, 12:00:11 AM12/5/19
to openr...@googlegroups.com
I missed the point that Olivia wanted to insert row count into a new column.
In that case, we should probably make this easier for users and add a new field to record and call it something like...

row.record.count

So I'm created an enhancement request:  https://github.com/OpenRefine/OpenRefine/issues/2237



--
You received this message because you are subscribed to the Google Groups "OpenRefine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openrefine+...@googlegroups.com.

wl

unread,
Dec 5, 2019, 12:16:11 AM12/5/19
to OpenRefine
EDIT: My solution can be simplified without any steps in between:
row.record.toRowIndex-row.record.fromRowIndex 
Wolf

Tom Morris

unread,
Nov 23, 2022, 10:12:19 PM11/23/22
to OpenRefine
The easiest way to do this is:

row.record.rowCount

It looks like it was implemented in the summer of 2011, but perhaps it's not documented.

Tom
Reply all
Reply to author
Forward
0 new messages