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?
import warnings warnings. filterwarnings('ignore') print('The script still runs. ') To suppress any warnings in the script, import the warnings library, and pass the filterwarnings() function the argument ignore .
Generally, to avoid a SettingWithCopyWarning in Pandas, you should do the following: Avoid chained assignments that combine two or more indexing operations like df["z"][mask] = 0 and df. loc[mask]["z"] = 0 . Apply single assignments with just one indexing operation like df.
SettingWithCopyWarning is a warning which means that your code may still be functional. However, it's important not to ignore it but instead, understand why it has been raised in the first place. This way it will be much easier for you to adjust your code accordingly so that the warning is no longer raised.
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)."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With