From pandas.read_csv
doc
na_values: scalar, str, list-like, or dict, optional
Additional strings to recognize as NA/NaN. If dict passed, specific per-column NA values.
By default the following values are interpreted as NaN: ‘’, ‘#N/A’, ‘#N/A N/A’, ‘#NA’, ‘-1.#IND’, ‘-1.#QNAN’, ‘-NaN’, ‘-nan’, ‘1.#IND’, ‘1.#QNAN’, ‘’, ‘N/A’, ‘NA’, ‘NULL’, ‘NaN’, ‘n/a’, ‘nan’, ‘null’.
So, NA
will automatically be read as NaN
, but there is additional parameter called keep_default_na
, you can pass False
to this parameter if you want to change that default behavior:
df = pd.read_csv(path, keep_default_na=False)
Contact Product
0 1 NA
1 2 ZE
2 3 HE
3 3
But you may need to specify the values which you want pandas to represent as NaN
, passing a list of such values, or a dictionary where key is the column and value is the values to represent as NaN
.
df = pd.read_csv(path, keep_default_na=False, na_values=[''])
Contact Product
0 1 NA
1 2 ZE
2 3 HE
3 3 NaN