Pandas read_csv: ignore trailing lines with empty data
I would like to read the following data from a csv file:
id;type;start;end
Test;OIS;01/07/2016;01/07/2018
;;;
;;;
However, pandas read_csv will try to read empty lines as well ;;;
. Is there a way to automatically ignore these trailing blank data lines?
These lines are causing a problem because I am using read_csv
c converters
, and the functions in the converters dutifully throw an exception when they encounter invalid data, which means I don't even get to a valid dataframe. I could change the functions to convert invalid data to NaN
and then discard NaN
from the dataframe, but then I would be silent about discarding the erroneous data as well as those blank lines.
Some clarifications:
- Blank data lines will always end, this is a common problem with csv files generated from Excel.
- The data is user generated, so manual cleaning is not an option.
source to share