在熊猫中消除警告

时间:2014-02-18 22:33:57

标签: python pandas warnings

运行时:

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

我得到的内容如下:

...
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
...

我怎样才能使这些警告沉默?如何在Pandas中找到警告类列表?

1 个答案:

答案 0 :(得分:8)

看起来read_csv有一个warn_bad_lines kwarg,所以你应该能够做到以下几点:

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

  

"如果error_bad_lines为False,并且warn_bad_lines为True,则每个“坏行”的警告将>>输出。 (仅对C解析器有效)。"