سؤال

When running:

mydf = pd.read_csv(p_file, sep=',', error_bad_lines=False, index_col=False)

I get many lines like the following:

...
Skipping line 77432: expected 15 fields, saw 16
Skipping line 77497: expected 15 fields, saw 16
Skipping line 77528: expected 15 fields, saw 16
Skipping line 77560: expected 15 fields, saw 16
Skipping line 77625: expected 15 fields, saw 16
Skipping line 77656: expected 15 fields, saw 16
...

How can I silence these warnings? How can I find the list of warning classes in Pandas?

هل كانت مفيدة؟

المحلول

Looks like read_csv has a warn_bad_lines kwarg, so you should be able to do the following:

mydf = pd.read_csv(p_file, sep=',', error_bad_lines=False, index_col=False, warn_bad_lines=False)

http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html#pandas.read_csv

"If error_bad_lines is False, and warn_bad_lines is True, a warning for each “bad line” will > be output. (Only valid with C parser)."

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top