Friday, 15 August 2014

python - pandas.read_csv named argument na_values default values -



python - pandas.read_csv named argument na_values default values -

pandas automatically converts values nan when importing info csv, excel, sql, etc (e.g. methods in pandas.io.parsers).

my question is, these default values?

i've noticed string "na" gets automatically converted. others have noted, 1 can disable automatic conversion passing keep_default_na=false when calling function imports info (e.g. pandas.io.parsers.read_csv).

that said, not know values other "na" automatically converted. in the docs, can find next description keep_default_na argument:

keep_default_na : bool, default true if na_values specified , keep_default_na false default nan values overridden, otherwise they’re appended to

what i'd know is, aforementioned 'default nan values'?

jeff provided link year ago, since next links cumbersome, moved info here.

['-1.#ind', '1.#qnan', '1.#ind', '-1.#qnan', '#n/a','n/a', 'na', '#na', 'null', 'nan', '-nan', 'nan', '-nan']

source: http://pandas.pydata.org/pandas-docs/stable/io.html#na-values

however

this list not complete.

import pandas pd stringio import stringio sio = stringio() sio.write('"foo","bar"\n"1",""\n"na","4"') sio.seek(0) pd.read_csv(sio, sep=",", quotechar='"') foo bar 0 1 nan 1 nan 4

note how empty string not part of list, still gets parsed nan default?

pd.read_csv(sio, sep=",", quotechar='"', keep_default_na=false, na_values=['-1.#ind', '1.#qnan', '1.#ind', '-1.#qnan', '#n/a','n/a', '#na', 'na' 'null', 'nan', '-nan', 'nan', '-nan']) foo bar 0 1 1 nan 4

if list default, these 2 commands should produce exact same result.

they don't.

if want reproduce default behaviour of pandas.read_csv, list need:

['', '-1.#ind', '1.#qnan', '1.#ind', '-1.#qnan', '#n/a','n/a', 'na', '#na', 'null', 'nan', '-nan', 'nan', '-nan']

pandas version reference:

pd.__version__ '0.15.2'

bug ticket pandas:

https://github.com/pydata/pandas/issues/10700

update

this fixed in pandas 0.17

python pandas

No comments:

Post a Comment