Losing a column in read_csv when the first row has no value in that column
Pretty much what’s in the title. I’m trying to read a group of CSVs into a dataframe, but one column is giving me trouble. It works as intended when this column has a value in the first row, but if there is no value, everything gets shifted over.
If I use the datatable package, the file is be read correctly regardless, but there are some features in the pandas to_csv method I need, and converting back and forth introduces other issues.
I’ve read through the documentation and done quite a bit of searching online without any luck so far. Any ideas how I can fix this?
Posted Mar 27, 2023, 12:14 AM UTC
Check your file first and ensure that you actually have delimiters where you think you do.
Apologies for the late reply, this ended up being the issue. The input file was created with an extra delimiter in the last row if that field was empty. Pandas was able to figure it out when the first row had data in that column, but not otherwise.
I was able to resolve the issue by setting index_col to False in my read_csv call.