L15 Opening Somebody Else’s File

DATA SCIENCE · CYCLE 2 · L15 · TEXTBOOK CHAPTER

Opening Somebody Else’s File

Somebody else’s data reaches you as a file. The file’s form decides what survives. Today you move a table out of one tool and into another, and you check what arrived.

After this chapter, you can

For your project: it starts with somebody else’s file, kept untouched on RAW. The checkpoint is at the end.

Why It Matters

In the autumn of 2020, labs in England tested people for COVID. The labs sent their results to Public Health England as CSV files. A CSV holds any number of rows.

Public Health England loaded the files into an old Excel format, .xls. An .xls sheet holds 65,536 rows. Rows past the limit were left off.

15,841 positive cases went missing from the daily count over 8 days, 25 September to 2 October 2020. That is about 1,980 cases a day. People still got their own results. Their close contacts were not traced, which means found and warned, until the error was found.

The results were complete when they left the labs. They were lost in the move from one form to another. A count of the rows before the move and after it would have shown the gap. That count is the first of today’s three checks.

The Idea

The file’s form decides what survives

Somebody else’s data reaches you as a file, and the file’s form decides what survives.

The same table, asIt keepsIt breaks when
a spreadsheet (.xlsx)formulas, tabs, colorsan old .xls runs out of rows
a CSV (.csv)only the values, as plain texta value has a comma in it
a document (Doc, PDF)the look, for a readeryou copy numbers out: they come as text
a databasemany tables, linked by an idyou skip the id that links them

An id is a number or code that names one thing, like a student number.

After every import, check three things: the rows, the header, the types.

To export is to save a tab out of a tool as a file. To import is to bring a file’s rows into a tool. A CSV is plain text, so almost every tool can read it. That is why so much data is shared as CSV files.

A CSV opened as text is easy to read. Each row is one line. A separator sits between values: a comma, a tab space or a |. The first line is the header row, the row that names the columns. A value with a comma inside it needs quotes round it.

In Sheets: Out as a CSV, and Back In

Export a tab as a CSV. Sheets saves the tab you are on, and only that tab.

  1. Click the tab you want to send.
  2. File > Download > Comma-separated values (.csv).

Import a file as a new tab.

  1. File > Import > Upload > Browse.
  2. Pick the file.
  3. Import location: Insert new sheet(s).
  4. Separator type: Detect automatically.
  5. Import data.
  6. Right-click the new tab > Rename > a short name, such as 2023.

If Import location stays on Create new spreadsheet, Sheets makes a whole new file. Insert new sheet(s) keeps every import in one file, a tab each.

Three Checks After Every Import

CheckAskIn Sheets
The rowsDid every row arrive? Count the rows of data before the move and after it.Click an empty cell in row 1, to the right of the last column. Type: =COUNTA(A:A)-1 Press Return.
It counts the filled cells in column A and takes off the header row. Title lines above the header row? Take those off too, as in Example 3.
The headerWhich row names the columns?Read the first few rows. A title line pushes the header row down from row 1.
The typesDid each value arrive as what it is: a number, a date or text?A number or a date sits at the right of its cell. Text sits at the left.

Rows of data are the rows under the header row. Types can go wrong in two ways. A price that arrives as text will not add up. A label that arrives as a number loses its front zeros: locker 0731 shows as 731.

Worked Examples

Example 1 · Read a CSV as text. A school store keeps its sales in a Sheet. In the Sheet, column E is a formula: E2 holds =C2*D2. Here is the Sales tab, exported as a CSV and opened as text. How many rows of data does it hold? What did the CSV keep, and what did it drop?

Date,Item,Price ($),Sold,Total ($)
11/2/2026,Pencil,0.25,40,10.00
11/2/2026,"Notebook, wide ruled",1.50,12,18.00
11/3/2026,Eraser,0.50,9,4.50

Create a strategy

Read it the way a tool does. One row a line. A comma between values. Line 1 is the header row.

Apply the idea

The file has 4 lines. Line 1 is the header row, so there are 4 − 1 = 3 rows of data. The header row names 5 columns: Date, Item, Price ($), Sold and Total ($).

The last value on line 2 is 10.00. In the Sheet that cell held =C2*D2. The CSV kept the value, 0.25 × 40 = 10.00. It dropped the formula. It also dropped the colors, the charts and every other tab.

Reflect and check

Count the values on each line: 5, 5, 5 and 5. Every row lines up with the header row. Line 3 needs its quotes for that. “Notebook, wide ruled” has a comma inside it. Without the quotes a tool would read 6 values on line 3, and 1.50 would land under Sold.

Example 2 · The wrong separator. A library sends its book list as a file. Here it is, opened as text. You import it with Separator type: Comma. What lands in the Sheet, and how do you fix it?

Title|Author|Year|Copies
Dune|Herbert, Frank|1965|3
Beloved|Morrison, Toni|1987|2
Holes|Sachar, Louis|1998|5

Create a strategy

Find what sits between the values in the text. Then find the commas, because a comma is where Sheets will cut.

Apply the idea

This file puts a | between values. Its only commas are inside the authors’ names. So Sheets cuts each author in two, and nothing else:

AB
1Title|Author|Year|Copies
2Dune|HerbertFrank|1965|3
3Beloved|MorrisonToni|1987|2
4Holes|SacharLouis|1998|5

Cell A1 holds the whole header line. Import the file again and name the separator yourself.

  1. Right-click the tab > Delete > OK.
  2. File > Import > Upload > Browse.
  3. Pick the file again.
  4. Import location: Insert new sheet(s).
  5. Separator type: Custom.
  6. Type | in the box: Shift and \, the key above Return.
  7. Import data.

Now the tab has 4 columns, Title, Author, Year and Copies, and 3 rows of data.

Reflect and check

The rows: the text has 4 lines, and 4 − 1 = 3 rows of data arrived. The header: row 1 names 4 columns. The types: Year and Copies sit at the right of their cells, as numbers do. The library chose | because its authors’ names have commas in them.

Example 3 · Three checks on a new file. A city’s page says its bike count file for 2025 has 1,095 records. You import the file as a new tab. These are its first and last rows. Run the three checks.

ABC
1City bike counts, 2025
2Counted by sensors on three trails
3DateCounterBikes
41/1/2025River Trail148
…………
1,099End of report
Create a strategy

The three checks, in order: the rows, the header, the types.

Apply the idea

The rows. Click cell E1. Type: =COUNTA(A:A) Press Return. It shows 1,099, the filled cells in column A. Take off what is not data: 2 title lines, 1 header row and the End of report line.

1,099 − 2 − 1 − 1 = 1,095

The city’s page said 1,095. Every row arrived.

The header. Row 3 names the columns: Date, Counter and Bikes. Rows 1 and 2 are title lines.

The types. The dates and the bike counts sit at the right of their cells, so Sheets read them as dates and numbers. The counter names sit at the left, as text does.

Reflect and check

What is one row here? One counter on one day. Three counters for 365 days is 3 × 365 = 1,095 rows. Suppose the city adds a fourth counter next year: 4 × 365 = 1,460 rows. That is (1,460 − 1,095) ÷ 1,095 × 100 = 33.3% more rows, from one new sensor and no new riders. More rows is not more of the thing.

Try It: Change the Separator

The lab starts on Example 2’s file, cut at the commas. Click each separator button and watch the table. Which one gives 4 columns?

Then try your own lines. Copy a few cells from any Sheet and paste them over the text. Sheets puts a tab space between copied values, so click the Tab button.

The Same in Python

Python comes in L19b. Once you have read it, come back and open VDOT’s 2023 file here, the one you imported in class.

1import pandas as pd 2df = pd.read_csv("L15-VDOT-traffic-2023.csv") 3print(len(df), "rows")

In Sheets this is: File > Import the CSV, then =COUNTA(A:A)-1.

In English:

  1. Get the pandas toolbox and call it pd.
  2. Open the file as a table called df.
  3. Print how many rows.

Predict: pandas takes the file’s first line as the header row and does not count it. How many rows will it print? Your 2023 tab has the number.

Can’t run it here? Show what it prints
864 rows

The same as your 2023 tab, where =COUNTA(A:A)-1 shows 864. Same rows, counted by a new tool.

Want to type your own? The Python practice page has tasks and a notebook.

In your project

Your Cycle 2 project is one Google Sheet with RAW, CLEAN, LOG, ABOUT and ANALYSIS tabs, and a one-page memo. It starts with somebody else’s file. Import the file as a new tab and name the tab RAW. Leave it exactly as it was downloaded. Keep the title lines and the headers as they are. Run the three checks. Then type the number of rows of data on your LOG tab, so anyone can check that nothing went missing. Every fix after that happens on CLEAN.

Check Yourself

Answer each one before you look. The first one is from an earlier lesson.

You find a typing mistake in your project file. Where do you fix it? L6

A club keeps its members in one table and their payments in another, linked by a member id. Which form is this?

Cell D2 of a tab holds the formula =B2*C2. B2 holds 3.5 and C2 holds 6. You export the tab as a CSV. What does the CSV hold for D2?

Sheets imports this line with Separator type: Comma. How many values does it read?
"Gate 2, north side",14,6/3/2026

You import a file with Separator type: Comma. Every line lands whole in column A. What do you do?

After an import, a tab starts like this. Which row is the header row?

ABC
1Pool visits, summer 2026
2North, East and West pools
3Counted at the gate
4DatePoolVisitors
56/1/2026North305

After an import, the numbers in column C sit at the left of their cells. What has Sheets read them as?

A city’s pothole file had 400 rows last year and 460 this year: 15% more rows. A headline says potholes rose 15%. What do you check first?

Project Checkpoint

P1 · due Mon 30 Nov

Your claim stands on a file somebody else made. Before you change anything, your Sheet keeps that file exactly as it came, so anyone can check your work against it.

Tick each step once it is in your Sheet. Your ticks go into the PDF you hand in. Where everything goes: your Sheet, tab by tab.

Read More

Google Docs Editors Help, “Import data sets & spreadsheets”. Google’s own page for File > Import. It lists the file types Sheets can import, the six import locations, and the four separator choices: Detect automatically, Tab, Comma and Custom.

Stuck on any of this? Ask Mr. Case in class or send him a message in Canvas. Name the example or the question number, and say which step lost you.