JU2602 Data journalism and visualization
This page contain Python code and Jupyter Notebooks for the course JU2602 Data journalism and visualization, part of the master programme in investigative journalism at JMG, Sweden.
The goal is to learn the basics of programming in general and Python in particular. No previous programming knowledge is required. The goal is to build a news robot that can scrape the web and automatically write a news article.
Please bring your computer!
Contact Peter M. Dahlgren if you have any questions.
Overview of what we'll do, apart from the lectures:
- Install Anaconda (choose Python version 3+) that contains Python and Jupyter Notebooks.
- Get familiar with Jupyter Notebooks.
- Do the exercises.
- Learn to control program flow with
- Write fuctions with
defthat group code into reusable blocks.
- End with some bigger web scraping projects: e.g., news robot.
|Exercise 1: Variables||Create, change and combine variables.|
|Exercise 2: Strings||Manipulate text strings.|
|Exercise 3: If-statements||Control program flow with if, elif and else.|
|Exercise 4: For-loops||Use for-loops to control how lists are presented on the screen.|
|Exercise 5: Functions (def)||Create functions that take input, change the input, and then return some new value.|
|Exercise 6: Error handling||Understand common error messages, and how to solve them.|
|Scrape Court Rulings from InfoCuria||Scrape most recent judgments and opinions from InfoCuria.|
|Web Scraping Examples||Example code for scraping Internet Movie Database, Washington Post and Wikipedia.|
|Model Scraper||Student project that scrape body measurements from women models.|
|Facebook API||Get Facebook status messages from any Facebook page.|
|BeautifulSoup Examples||Example code to help you scrape HTML from web pages using BeautifulSoup.|
|Movie Review News Robot||News robot that writes a news article based on movie data.|
|Earthquake News Robot||News robot that writes a news article based on (fictitious) earthquake data.|
|Weather News Robot||News robot that scrapes tomorrows weather and writes a short text complaining about how cold it is.|
Jupyter Notebooks - keyboard shortcuts
Ctrl+Enter= run cell
ESC= exit out of a cell
a= insert cell above
b= insert cell below
dd= delete cell
Jupyter Notebook files are saved on your computer, typically in your Users folder (i.e.,
/Users/<username>). Read more at 28 Jupyter Notebook tips, tricks and shortcuts.