0
$\begingroup$

If supplying data (that can be either string or numeric) via CSVs, what's a good strategy for marking that a value is missing?

  • Some non-empty sentinel, like NA
  • Some non-empty sentinel, but quoted like "NA"
  • The empty string, e.g. in the CSV the value will be 0 characters long.
  • The quoted empty string ""
  • Something else / depending on case?

If it makes a difference, would like the CSVs to behave reasonably when read using R readr, Python Pandas, and Excel.

$\endgroup$
2
$\begingroup$

Both pandas and readr allow flexibility on the marker used to indicate missing values, allowing to specify values that should be treated as missing when reading csvs:

given that, maybe you can handle missing data in your code rather than replacing values in the original csvs.

If you get to choose, maybe NA (no hyphens) is a sensible default as it's handled as missing value by both libs by default.

| improve this answer | |
$\endgroup$
  • $\begingroup$ I realise NA is the ISO country code of Namibia, and I am likely to be outputting country codes... $\endgroup$ – Michal Charemza Jun 7 at 6:16
  • $\begingroup$ OK, maybe you have a case to override the default NA values (in pandas, stackoverflow.com/questions/33952142/…) and indeed use another symbol to avoid that conflict. $\endgroup$ – Davide Fiocco Jun 7 at 6:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.