gpt4 book ai didi

python - 消除 Pandas 中的警告

转载 作者:太空狗 更新时间:2023-10-30 02:11:30 30 4
gpt4 key购买 nike

运行时:

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 中的警告类列表?

最佳答案

看起来 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

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

关于python - 消除 Pandas 中的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21866939/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com