Handling malformed CSV rows with Pandas read_csv while maintaining data integrity
I'm sure I'm missing something obvious here, but I'm working on a project where I need to import a large CSV file using Pandas, specifically version 1.3.2. The scenario arises when I encounter rows that have extra commas, which causes `read_csv` to misinterpret the number of columns. For example, I have a row that looks like this: ```csv ID,Name,Age,Occupation, 1,Alice,30,Engineer, 2,Bob,25,Teacher 3,Charlie,35,Doctor,, ``` When I try to read this CSV with the following code: ```python import pandas as pd df = pd.read_csv('data.csv') ``` Pandas raises an behavior: `ParserError: behavior tokenizing data. C behavior: Expected 4 fields in line 4, saw 5`. I want to ignore these malformed rows while still keeping the well-formed data intact. I have attempted using the `error_bad_lines=False` and `warn_bad_lines=True` options, but I've noticed that it just skips the malformed rows without providing any warning in the terminal, which isn't ideal for tracking issues. Is there a way to handle this situation better? Ideally, I'd like to log the malformed rows to a separate file or variable for later review, while still loading the valid rows into the DataFrame. Any suggestions on how to do this efficiently? I'm working on a application that needs to handle this. I'd really appreciate any guidance on this.