Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Data Collection  ›  Lesson

CSV Files

CSV Files 12 minA CSV file is plain text with one record per line and fields separated by commas, so its structure is only as reliable as the program that wrote it.

CSV Files

Nisha's delivery partner emails a weekly file called deliveries.csv. It opens in a spreadsheet, a database, Python or R, which is exactly why every system can export one. That same simplicity is why CSV files cause some of the most confusing bugs an analyst meets.

The rule

A CSV is just text: one line per row, commas between fields.

Open one in a plain text editor and you see this:

order_id,order_date,customer,item_code,qty,amount
1001,2025-06-02,Asha Rao,C01,2,240
1002,2025-06-02,Vikram Shah,C02,3,120
1006,2025-06-05,"Rao, Kiran",B01,1,90
  • The first line is usually the header: the column names.
  • Each following line is one row; each comma starts a new field.
  • A field that itself contains a comma is wrapped in double quotes, as in "Rao, Kiran". A double quote inside a quoted field is written twice: "".

What a CSV does not store matters just as much:

  • No data types. 00123, 2025-06-02 and 1e5 are all just characters. The program opening the file guesses what they are.
  • No formatting, formulas or multiple sheets. Only the values.
  • No declared encoding or separator. Most files are UTF-8 with commas, but some regions use semicolons, and a wrong encoding turns ₹ into junk like ₹.

The shortcut

When a CSV import looks wrong, open the raw file as text before blaming the data. Then check the three usual suspects: quotes, types, encoding.

Diagnosing a broken importStep 1 of 4
  1. Symptom

    One row has its amount in a new, unnamed column, and the IDs show as 1234 instead of 01234.

A quick sanity check after any import: count the rows, look at the first and last few, and make sure every row has the same number of columns.

Drills

Answer fast — trust the rule.

quick drill

How many fields does the line 1006,2025-06-05,"Rao, Kiran",B01,1,90 contain?

quick drill

A file has 501 lines, including one header line. How many data rows should the import show?

quick drill

Why do product codes like 00123 become 123 after opening a CSV?

quick drill

The ₹ sign shows up as ₹ after import. What is the most likely cause?

Remember

  • A CSV is just text: one line per row, commas between fields.
  • Shortcut: open the raw text, then check quotes, types and encoding.
  • Trap: the program guesses types; set ID and code columns to text yourself.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainWhy did the import break?

A CSV export of customers opens with some rows shifted one column to the right, and order IDs like 00123 now show as 123. Explain the two likely causes and how you would import the file safely.