Is there a way in Pandas to capture the warning generated by setting error_bad_lines = False and warn_bad_lines = True? For example, the following script:
import pandas as pd
from StringIO import StringIO
data = StringIO("""a,b,c
1,2,3
4,5,6
6,7,8,9
1,2,5
3,4,5""")
pd.read_csv(data, warn_bad_lines=True, error_bad_lines=False)
gives a warning:
Skipping line 4: expected 3 fields, saw 4
I would like to keep this output in a line so that I can eventually write it to a log file in order to keep track of missing entries.
I tried to use the warning module , but it does not look as if this “warning” has traditional meaning. I am using Python 2.7 and Pandas 0.16.
Any help would be greatly appreciated.
source
share