私は、Apacheログファイルを解析し、それをさらに調査するためにpandasデータフレームに保存しています。Python: 'python'エンジンで悪い行をスキップする方法
しかし、ログファイルに、私はいくつかの悪いラインを持っているので、次のエラーが発生します。ファイルの読み取り中に
ValueError: Expected 11 fields in line 4320, saw 27
この問題を克服するために、私はerror_bad_lines = False
が含まれています。
ValueError: The 'error_bad_lines' option is not supported with the 'python' engine
注:私は正規表現としてのセパレータを持っているように、私は明示的にpython engine
を使用しています、私は次のエラーを取得していますので、これは役立ちません。
コードスニペットは:
data = pd.read_csv(
log_file,
sep=r'\s(?=(?:[^"]*"[^"]*")*[^"]*$)(?![^\[]*\])',
engine='python',
na_values='-',
header=None,
usecols = use_cols,
skiprows =1,
converters={time_taken_index[0]:parse_sec, time_index[0]:parse_datetime, req_index[0]:parse_str,status_index[0]:parse_str},
error_bad_lines = False
)
私は、任意の提案に感謝するだろう。ありがとうございました。
あなたが話しているログファイルの一部を添付できますか? – jjj