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
- Name four forms a table comes in, and what each keeps.
- Export a tab as a CSV, and import a CSV into Sheets.
- Check the rows, the header and the types after every import.
- Say why more rows is not more of the thing.
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, as | It keeps | It breaks when |
| a spreadsheet (.xlsx) | formulas, tabs, colors | an old .xls runs out of rows |
| a CSV (.csv) | only the values, as plain text | a value has a comma in it |
| a document (Doc, PDF) | the look, for a reader | you copy numbers out: they come as text |
| a database | many tables, linked by an id | you 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.
- Click the tab you want to send.
- File > Download > Comma-separated values (.csv).
Import a file as a new tab.
- File > Import > Upload > Browse.
- Pick the file.
- Import location: Insert new sheet(s).
- Separator type: Detect automatically.
- Import data.
- 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
| Check | Ask | In Sheets |
| The rows | Did 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 header | Which row names the columns? | Read the first few rows. A title line pushes the header row down from row 1. |
| The types | Did 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 strategyRead it the way a tool does. One row a line. A comma between values. Line 1 is the header row.
Apply the ideaThe 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 checkCount 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 strategyFind what sits between the values in the text. Then find the commas, because a comma is where Sheets will cut.
Apply the ideaThis file puts a | between values. Its only commas are inside the authors’ names. So Sheets cuts each author in two, and nothing else:
| A | B |
| 1 | Title|Author|Year|Copies | |
| 2 | Dune|Herbert | Frank|1965|3 |
| 3 | Beloved|Morrison | Toni|1987|2 |
| 4 | Holes|Sachar | Louis|1998|5 |
Cell A1 holds the whole header line. Import the file again and name the separator yourself.
- Right-click the tab > Delete > OK.
- File > Import > Upload > Browse.
- Pick the file again.
- Import location: Insert new sheet(s).
- Separator type: Custom.
- Type | in the box: Shift and \, the key above Return.
- Import data.
Now the tab has 4 columns, Title, Author, Year and Copies, and 3 rows of data.
Reflect and checkThe 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.
| A | B | C |
| 1 | City bike counts, 2025 | | |
| 2 | Counted by sensors on three trails | | |
| 3 | Date | Counter | Bikes |
| 4 | 1/1/2025 | River Trail | 148 |
| … | … | … | … |
| 1,099 | End of report | | |
Create a strategyThe 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 checkWhat 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:
- Get the pandas toolbox and call it pd.
- Open the file as a table called df.
- 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
Nothing in RAW is ever changed. Every fix happens on CLEAN and gets a row on the LOG tab. If you change RAW, the record of what you first had is gone.
A club keeps its members in one table and their payments in another, linked by a member id. Which form is this?
A database keeps many tables, linked by an id. Here the member id links each payment to its member. A spreadsheet keeps formulas, tabs and colors. A CSV keeps only the values of one table. A document keeps the look, for a reader.
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?
A CSV keeps only the values, as plain text. 3.5 × 6 = 21, so the file holds 21. The formula stays behind in the Sheet.
Sheets imports this line with Separator type: Comma. How many values does it read?
"Gate 2, north side",14,6/3/2026
The quotes keep the first comma inside one value: Gate 2, north side. Then 14, then 6/3/2026. That is 3 values. Without the quotes Sheets would read 4.
You import a file with Separator type: Comma. Every line lands whole in column A. What do you do?
The file uses another separator, such as a |. Delete the tab and import again with Separator type: Custom, as in Example 2. Typing the values again takes a long time and adds mistakes. Keeping the tab as it is leaves one column where there should be many.
After an import, a tab starts like this. Which row is the header row?
| A | B | C |
| 1 | Pool visits, summer 2026 | | |
| 2 | North, East and West pools | | |
| 3 | Counted at the gate | | |
| 4 | Date | Pool | Visitors |
| 5 | 6/1/2026 | North | 305 |
Row 4 names the columns: Date, Pool and Visitors. Rows 1 to 3 are title lines. They pushed the header row down from row 1.
After an import, the numbers in column C sit at the left of their cells. What has Sheets read them as?
A number or a date sits at the right of its cell. At the left, Sheets has read the value as text. =SUM and =AVERAGE skip text, so fix the type before you compute anything.
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?
More rows is not more of the thing until you know what a row is. The city may have listed more streets this year, or put one pothole in two rows. The percent is right, but it counts rows. Which streets have the most is a later question.
Project Checkpoint
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.