且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何记录 pandas 跳过的坏行

更新时间:2021-07-05 00:59:11

警告显示在标准错误通道中.您可以通过重定向sys.stderr输出将它们捕获到文件中.

Warnings are printed in the standard error channel. You can capture them to a file by redirecting the sys.stderr output.

import sys
import pandas as pd

with open('bad_lines.txt', 'w') as fp:
    sys.stderr = fp
    pd.read_csv('my_data.csv', error_bad_lines=False)