Pandas Read_csv And Setting Na_values To Any String In The Csv File
data.csv 1, 22, 3432 1, 23, \N 2, 24, 54335 2, 25, 3928 I have a csv file of data that is collected from a device. Every now and then the device doesn't relay information and out
Solution 1:
You have to manually pass all the keywords as a list or dict to na_values
na_values : list-like or dict, default None
Alternatively, use pd.to_numeric and set errors to coerce
to convert all values to numeric after reading the csv file.
sample input df
:
A B
0 1 2
1 0 \N
2 \N 8
3 11 5
4 11 Kud
df = df.apply(pd.to_numeric, errors='coerce')
output:
A B
01210NaN2NaN83115411NaN
Post a Comment for "Pandas Read_csv And Setting Na_values To Any String In The Csv File"