3
$\begingroup$

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[]?

$\endgroup$

1 Answer 1

5
$\begingroup$

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

data /. "" -> Null

or

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

Your Answer

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

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