Created
December 18, 2016 11:38
-
-
Save markqiu/59af9f88e3e1da5fe927f32fab5bbff6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# somewhere to store output | |
err = StringIO.StringIO() | |
# save a reference to real stderr so we can restore later | |
oldstderr = sys.stderr | |
# set stderr to our StringIO instance | |
sys.stderr = err | |
tp = pd.read_csv(f_in, sep=',', chunksize=1000, encoding='utf-8',quotechar='"', error_bad_lines=False) | |
for chunk in tp: | |
chunk | |
# restore stderr | |
sys.stderr = oldstderr | |
# print(or use) the stored value from previous print | |
print err.len + 'lines skipped.' | |
print err.getvalue() | |
err.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment