Read all but last line of CSV file in pandas

You can leave out the last n lines when reading in a csv by using the skipfooter argument:

df = pd.read_csv(filename, skipfooter=3, engine='python')

In this example the last 3 lines are ommited.


Read http://pandas.pydata.org/pandas-docs/version/0.16.2/generated/pandas.read_csv.html. Here 'skipfooter' argument can be used to specify no of lines that you don't want to read from .csv file from the end. May be It may help you.


pass error_bad_lines=False and it will skip this line automatically

df = pd.read_csv(filename, error_bad_lines=False)

The advantage of error_bad_lines is it will skip and not bork on any erroneous lines but if the last line is always duff then skipfooter=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.