Read NULL as missing in dataframe

Hi,

I’m reading a csv file (originally obtained from SQL) that has the string “NULL” to signify no value. This is not an empty string (although I am curious how that gets tackled too).

How do I read this string as a missing type in Julia?

df = DataFrame( CSV.File( “file1.csv” ) )

I was hoping there would be a argument in CSV.File or DataFrames I could use to declare missing values. Coming from an R background, in the data.table R package you could do something like:

df = fread( “file.csv”, na.strings = “NULL”)

Any tips?

You’re looking for CSV.jl Documentation · CSV.jl

By default, you get a missing value if and only if the field is empty in the CSV file.

To get missing both for empty fields and NULL, you can use CSV.File(..., missingstrings=["NULL", ""]).

2 Likes