Intro to Computational Journalism
From datasets to websites
df
Rows and columns inside a dataframe.
<html>
Web pages are structured text too.
The routine
Errors are clues
When something breaks, start with the last line, find the exact error, and change one thing at a time.
What is Python telling us?
df.columns.Group exercise
Use a new dataset and produce one filter, one sort, and one summary statistic.
Not all data arrives as a CSV.
Spreadsheet
Rows and columns in a file.
Dataframe
Python can work with it.
Webpage
Structured text in the browser.
HTML
The blueprint underneath.
A webpage may look visual, but underneath it is structured text.
HTML is the structure behind the page
Anatomy of a webpage
A book card is nested HTML.
What we see as one book card is stored as a set of nested HTML elements.
Scraping begins by finding the repeated container, then extracting fields inside it.
If one card has a pattern, Python can find all of them.
A card is easier to scrape when the pieces repeat in the same order.
Scraping starts by noticing repetition.
Right click → Inspect
Next: turn HTML back into a table
HTML pageText in the browser.
Beautiful SoupFind the pieces we care about.
Rows and columnsTurn the page into data.
DataframeWork with it like a table.