When importing a csv file with empty fields as a Dataset, the empty fields are set to zero-length strings (""). There is an option, EmptyField, which replaces the zero-length string with an arbitrary string, but I don't see a way to set empty fields to Missing[] or some other value indicating missing data.

The import code is:

data = Import["file.csv",{"CSV","Dataset"},"HeaderLines"->1, "EmptyField"->""]

The result is the same as leaving EmptyField out since "" is the default. However, all attempts at setting EmptyField to Missing[], Null, or None fail. For example:

enter image description here

Is there a way to set empty fields to Missing[]?


I don't think there is a way to do this using the "EmptyField" option. I post process after Import.

data /. "" -> Null


data /. "" -> Missing["NotAvailable"]
  • $\begingroup$ That works perfectly, thank you. It would be nice to have a more flexible option to handle missing data on import. $\endgroup$
    – Lee
    Mar 21 '19 at 10:47

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.