Pandas fillna exception for 'NA' string
Pandas read_csv functiomn already defines a set of strings that will be interpreted as NaNs when you load a csv file. Here you have the option to either extend that list with other strings or to also completely overwrite it. In your case you have to overwrite it, as NA is one of the default values used by pandas. To do so, you could try something like
df = pd.read_csv('sample_file.txt', dtype='str', sep='|',
names=['upc_cd', 'chr_typ', 'chr_vl','chr_vl_typ'],
na_values=[''], keep_default_na=False)
...
This will only interpret the empty string as NA as we have set keep_default_na
to False
and have only given ''
as a NA value with na_values
argument.
If you want to learn more, have a look at the pandas docs.