Pass on_bad_lines="skip"
and it will skip this line automatically
df = pd.read_csv(filename, on_bad_lines="skip")
-
The advantage of
on_bad_lines="skip"
is it will skip and not bork on any erroneous lines. But if the last line is always duff thenskipfooter=1
is better. -
Thanks to @DexterMorgan for pointing out that
skipfooter
option forces the engine to use the python engine which is slower than the c engine for parsing a csv.
and here is an old version (don’t use – it is removed from pandas2.0):
df = pd.read_csv(filename, error_bad_lines=False)
Deprecated since version 1.3.0: The on_bad_lines parameter should be used instead to specify behavior upon encountering a bad line instead.