Omniscope Custom Blocks › Preparation/Add-row-ID-field

Add row ID field

Adds a field numbering the records 1, 2, 3 and so on, in the order they arrive, working through the data in chunks so large inputs never have to fit in memory.

Preparation Python

Open the demo in Omniscope Download demo.ioz Sample data: feedback-cards.csv Source on GitHub

Omniscope custom block · Preparation

Records with no key of their own? Number them 1, 2, 3 in the order they arrive, and keep that order and that key through the rest of the workflow.

Python · pandas · nothing extra to install

The problem it solves

Customer feedback cards are typed in as they arrive: date, branch, rating and a comment, with no reference number. To follow up a card, quote it in a report, or put the cards back in their original order after sorting by rating, each one needs an identifier.

This block adds a field numbering the records in the order they arrive.

How it works

What goes in

Feedback cards

15 invented feedback cards from three branches of a café chain.

Received Branch Rating Comment
2025-04-01 Harrogate 5 Quick service and friendly staff
2025-04-01 York 3 Had to wait for a table
2025-04-01 Harrogate 4
2025-04-02 Leeds 2 Order was wrong

15 rows in the sample file.

The options

Option Demo setting What it does
ID field name Card No Name of the new field; blank gives Row ID.
Start at 1001 The number given to the first record.
Put the ID field first ticked Make the ID the first field rather than the last.

What comes out

Numbered records (first rows)

Card No Received Branch Rating Comment
1001 2025-04-01 Harrogate 5 Quick service and friendly staff
1002 2025-04-01 York 3 Had to wait for a table
1003 2025-04-01 Harrogate 4
1004 2025-04-02 Leeds 2 Order was wrong

15 records in all, numbered 1001 to 1015. Card 1010 is the one-star "Cold food" card.

Where it pays off

Customer feedback: A reference for every response

Give survey responses, complaints or feedback cards a number staff can quote when they follow one up.

Before a sort or aggregate: Keep the original order

Number the records first, sort or filter them for analysis, and sort by the ID to get the original order back.

Before a join: Check nothing was lost or doubled

Number the records before a join, then count the IDs afterwards: a missing ID was dropped, a repeated one matched twice.

Log and sensor files: Line numbers

Keep each line's position in the file, so an odd reading can be found in the original file.

Use cases describe typical scenarios and are illustrative; the sample data is invented.

Why do this in Omniscope

How it fits into an Omniscope workflow

Feedback cards (File) → Add row ID field → Sort (lowest rating first) → Report

The ID stays with each card through the sort, so the report can list cards by rating and still quote each card's number.

Try it

  1. Open the demo project (demo.iox on the demo server, or import demo.ioz from this folder): 15 feedback cards with no reference.
  2. The question: how do we refer to a single card?
  3. Open Add row ID field: name Card No, start at 1001, put first ticked. Run it.
  4. Look at the output: 15 records, Card No 1001 to 1015 as the first field; 1010 is the "Cold food" card.
  5. Clear the name, set Start at back to 1 and untick Put first: the cards get a Row ID from 1 to 15 as the last field.

Running in Omniscope

Omniscope workflow
Omniscope workflow

The demo project's workflow: the sample data, the block, and a Validate data check on its output.

Language and libraries

Python. It uses pandas.

pandas is part of Omniscope's Python environment. It needs nothing else installed.

Tested

The block is covered by automated tests that run its script against a stand-in for Omniscope's Python API: the sample data, a chosen name, start number and position, blank names, an existing field of the same name, numbering that runs on across chunks with no gaps or repeats, every field type passed through, empty input, a bad start number, and 1,000,000 records. On an Omniscope server, 300,000 records were numbered 1 to 300,000 with no gaps or repeats.

Reference

Options

NameTypeWhat it does
ID field nameTextName of the new field. Left empty, it is Row ID. An existing field of this name is replaced.
Start atWhole numberThe number given to the first record.
Put the ID field firstYes / noMake the ID the first field. Unticked, it is added as the last field.

Outputs

OutputWhat it holds
NumberedThe input records with the ID field added.