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.


1 Answer 1


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.

  • $\begingroup$ I realise NA is the ISO country code of Namibia, and I am likely to be outputting country codes... $\endgroup$ Jun 7, 2020 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$ Jun 7, 2020 at 6:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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