The R readr read_csv
function allows passing quoted_na=FALSE
, which allows the parser to distinguish between the unquoted NA
meaning a missing value, and a quoted "NA"
meaning a string that happens to equal NA
.
Is there a way for the read_csv
function from Python Pandas to have similar behaviour?
For example, the CSV
var_1,var_2
"NA",NA
I would like to ideally be parsed as
var_1 var_2
0 NA NaN
The argument na_values
does not appear to be relevant: it appears to be applied to the strings after CSV parsing that removes the quotes.
For example, something like the below seems to still not be able to distinguish the two cases:
pd.read_csv('na.txt', na_values=['NA'], keep_default_na=False)
as in, both values are parsed as NaN
.