Dromo WebinarLearn how Dromo can solve your data importing problems

Register now

Flagging Invalid Rows

Identifying and marking rows that do not meet certain validation criteria.

Definition

Flagging invalid rows in your dataset is a process that involves identifying and marking rows that do not meet certain validation criteria. Rather than removing these rows outright, flagging allows you to note potential issues while retaining the data for further investigation.

This process can be crucial in maintaining data integrity, as it allows for the identification of systemic data issues or patterns of bad data.

Example of Flagging Invalid Rows using JavaScript

Here's an example of flagging invalid rows in JavaScript:

let data = [
  { name: "John", email: "john@email.com", age: "30" },
  { name: "Jane", email: "jane@email", age: "25" },
  { name: "Bob", email: "bob@email.com", age: "40" },
  { name: "Alice", email: "alice@email.com", age: "forty" },
];
function validateEmail(email) {
  let re = /\S+@\S+\.\S+/;
  return re.test(email);
}
function validateAge(age) {
  return !isNaN(age);
}
data = data.map((row) => {
  let errors = [];
  if (!validateEmail(row.email)) {
    errors.push("Invalid email.");
  }
  if (!validateAge(row.age)) {
    errors.push("Invalid age.");
  }
  row.errors = errors.join(" ");
  return row;
});

In this example, we iterate over each row of the data array. We run each row's email and age fields through validation checks. If a field does not pass its respective validation check, we add an error message to an array of errors for that row. We then join all error messages for a row into a single string and assign that string to a new ‘errors' field in the row.

Before:

NameEmailAge
Johnjohn@email.com30
Janejane@email25
Bobbob@email.com40
Alicealice@email.comforty

After:

NameEmailAgeErrors
Johnjohn@email.com30
Janejane@email25Invalid email.
Bobbob@email.com40
Alicealice@email.comfortyInvalid age.

Considerations

  • Flagging invalid rows is not a replacement for cleaning your data, but it is a useful tool for identifying where your data may have issues.
  • You may wish to establish a standard error message format to ensure consistency in how errors are reported.
  • Be aware that the presence of many flagged rows may indicate systemic issues with your data collection or entry processes.
  • Dropping Invalid Rows: Rather than simply flagging them, some situations may call for removing invalid rows altogether.
  • Trimming Fields: In some cases, it might be possible to correct the issues that lead a row to be flagged as invalid. For instance, leading/trailing spaces are a common culprit that that causes a validation check to fail.