I have a CSV file in which I am using Python to parse. I found that some rows in the file have different number of columns.
001;Snow,Jon;19801201
002;Crom,Jake;19920103
003; ;Wise,Frank;19880303 <-- Invalid row
004;Wiseau,Tommy;4324;1323;2323 <-- Invalid row
I would like to write these invalid rows into a separate text file.
I used this line of code to read from the file.
df = pd.read_csv('names.csv', header=None,sep=';')
One solution I found here was to skip the problematic rows using the following code:
data = pd.read_csv('file1.csv', on_bad_lines='skip')
I could change from 'skip' to 'warn', which will give the row number of the problematic row and skip the row. But this will return warning messages and not the row itself.