TROUBLESHOOT

Dealing with the common problems with CSV files

CSV Troubleshoot
When you open (import) CSV files, there are some very common problems that, regardless of the data in your file, you may encounter and that you will have to deal with.

CSV is not yet a fully standardized format and there are quite a few different ways of creating a CSV. You have a choice of delimiters, encoding, etc.

It is important to know that first way to avoid errors in CSV is to make sure that each row of data has the same structure. This means that each row must have the same number of fields, arranged in the same order (according to the header order), and the same delimiters used.

So, what are most common problems with CSV files?

Encoding problems

If you import your data into a spreadsheet or program and find question marks or unreadable text in place of your special characters, it's almost always an encoding issue. Return to the CSV file and ensure that it is UTF-8 encoded.

Empty columns and rows

This can also be the result of extra columns in the worksheet if you have created a CSV in Excel, and Excel may mistakenly think there is data there - even if you only see a blank. You can fix this by removing the extra columns from the file and making sure the remaining columns contain headers and data.

On the other hand, if you have an empty row error, you can check to see if your file has any extra rows without data - just delete them!

If you're using Excel or another spreadsheet program, you may need to check for additional potential error causes, such as hidden columns, merged cells, and so on.

File type errors

You may have created a file in a text editor and forgotten to save it as a ".CSV" file (it may be a ".TXT" file instead). Or perhaps you used Excel and didn't save the file as CSV, but just left it as ".XLS". It's a simple fix: save your file with the.csv extension.

Invalid or missing header

You will likely face this problem in the form of "missing header columns", "invalid header" or "header not found", etc. This means that the header line in your file is either missing or improperly formatted. The latter is the more common. Things like extra spaces, a mismatch in the number of header columns and columns with data in them, etc. will cause this error to occur.

Basically, make sure you have a header row and that it's accurate. This means that you should try to avoid using symbols other than letters, numbers, and underscores in the header. And make sure that the header line is delimited in the same way as the rest of the file. Remember that your CSV file has a simplified structure. Each row should follow a pattern: text, delimiter, text, delimiter, text, delimiter.