Reading a CSV file with an unconventional string for missing values using TextParse


I am trying to read a CSV file with two columns (Date, Float64) using TextParse. Unfortunately missing values are coded as “-” in that file. When TextParse encounters one of those “-” one gets the following error message:

MethodError: Cannot `convert` an object of type Float64 to an object of type TextParse.StrRange
This may have arisen from a call to the constructor TextParse.StrRange(...),
since type constructors fall back to convert methods.
ERROR: LoadError: CSV parsing error at line 1539 char 12:
column 2 is expected to be: TextParse.Field{Float64,TextParse.Numeric{Float64}}(<Float64>, true, true, true)

I have been unable to add “-” to the set of strings that are to be considered NA by TextParse. Which would be the best approach to solve this problem?

Thank you for your help!


I am not an expert here, but I would first read the file and then do the missing substitution. this is because it would be difficult to determine where your unusual character sits, and whether it is inside a quote or not. csv is a nasty format!



Looks like the same bug as


JuliaDB.loadtable("myfile.csv", colparsers = [Date], nastrings=["-"]) works

Input: myfile.csv

Table with 3 rows, 2 columns:
1           2

but couldn’t find an equivalent argument to - nastrings - for TextParse (also get this CSV file from a remote URL)


Got it for TextParse:

TextParse.csvread("myfile.csv", colparsers = [Date, TextParse.NAToken(TextParse.Numeric(Float64), nastrings = ["-"])])