01 / 32

Intro to Computational Journalism

How coding can help journalists

We are going to use code as a reporting tool.

MARKDOWNWelcome.md
You don't need to memorise everything, and expect your code to fail regularly. The important skill is learning how to understand what happened and what to try next.
Session 1Notebook ready
01

What is computational journalism?

Structured methods · data · codeIn [1]
MARKDOWNIn [1]

Computational journalism means using structured methods, data and code to support reporting.

The code is useful only because it helps us ask or answer a journalistic question.
What the code is forExecuted

When we want to work at a different scale

01 / SCALE

10 → 5,000

Checking ten company filings manually may be manageable; checking 5,000 requires automation.

02 / REPETITION

Every month

A script can download the same monthly table every time it is updated.

In newsrooms, we use it when we want to…In [2]
CONSISTENCY

Apply the same cleaning rule to every row rather than relying on manual edits.

REPRODUCIBILITY

A colleague can rerun the notebook and see how the result was produced.

DISCOVERY

Expose outliers that become reporting leads.

ACCOUNTABILITY

Audit public claims, procurement data and company disclosures.

Four newsroom advantagesOut [2]
Code does not replace reporting.

It helps us decide where to report, what claim to test and what evidence to request. Computational work does not remove journalistic judgement.

Code supports judgementIn [3]
02

The anatomy of a dataset

Rows · columns · variablesIn [4]

One row

One observation

Depending on the dataset, that observation might be one company, one person, one district, one transaction or one financial year.

companyyearprofit
0Aruna Power2024₹84m
1Nila Energy2024₹51m
2Vaigai Solar2024₹73m
A dataset is organised into rows and columnsOut [4]

One column

One variable

A variable is one characteristic recorded about each observation. In tables, variables appear as columns.

companyyearprofit
0Aruna Power2024₹84m
1Nila Energy2024₹51m
2Vaigai Solar2024₹73m
Variables appear as columnsIn [5]

Variables can be different types

84

Numeric

Numbers that we may calculate with.

"solar"

Categorical

Groups observations into labels.

2026-07-28

Date

Records time.

TN-0042

Identifier

Distinguishes one record from another.

Type changes what a variable can doOut [5]

How to read a dataset

A data dictionary explains what each variable means, how it was measured, what format it uses and what its possible values represent.

Without one, an obvious column name can still mislead.

README for the dataIn [6]

What does profit mean?

operating profitprofit before taxnet profitquarterly profitannual profit
Column names need definitionsOut [6]

At minimum

  1. What does each row represent?
  2. What does each column mean?
  3. What unit is being used?
  4. Which time period does the value cover?
MORE ROBUSTdictionary.md
  1. Are the figures estimates, provisional values or final figures?
  2. How are missing values recorded?
  3. Have definitions changed over time?
Questions before calculationsIn [7]

No data dictionary? That becomes a reporting problem.

  1. Look for methodology notes.
  2. Inspect the source website.
  3. Contact the data provider.
  1. Compare the data with published reports.
  2. Create your own working dictionary as you investigate.
Missing context is a leadOut [7]

Data

The file extension is a clue: it tells us what a file can preserve, how it is structured and how we might open it.

Data
CSVcompanies.csv
XLSXsurvey.xlsx
SHPdistricts.shp
PDFreport.pdf
JSONapi.json
HTMLtable.html
ZIParchive.zip
?README.md
Seven common formatsIn [8]
CSV

Plain-text table

Portable and easy to analyse. Does not preserve highlight colours, formulas or multiple sheets when exported.

XLSX

Excel workbook

May include several sheets, formulas, merged cells and formatting.

PDF

Document, not data

Tables may look structured but be difficult to extract reliably if they are not machine readable.

HTML

Webpage language

Useful when collecting tables or repeated page elements.

What the format preservesOut [8]
api.json

Structured data commonly returned by APIs.

archive.zip

A compressed container that may hold one or many data files.

districts.shp

Commonly used to store geographic boundaries. It is both data and geometry.

JSON · ZIP · ShapefileIn [9]
03

Trying out Google Colab

A notebook in the browserIn [10]

A workspace and a record

The same notebook can later become a transparent record of the analysis.

New tabsession_1.ipynb
colab.research.google.com
  1. It runs in the browser.
  2. You don’t need to install Python.
  3. Notebooks combine code, notes and output in one document.
Google ColabOut [10]

Say hello to the newsroom

CODEIn [11]
print("Hello, newsroom")
Hello, newsroom
First code cellExecuted in 0.02s
CODEIn [12]
print("Hello, newsroom")
print

A function: a named instruction Python already knows.

"Hello, newsroom"

The text inside quotation marks is a string.

( )

Parentheses hold the information being passed to the function.

OUTPUT

The output appears directly below the cell.

publication = "The Hindu"
print(publication)
Then demonstrate a variableOut [12]
04

Your first Pandas exercise

Open a dataset · ask what is insideIn [13]

A library for tabular data

A library is reusable code written by other people. We import it rather than rebuilding its functions ourselves.

Python library
PANDASread_csv()
head()
shape
columns

# tools we can reuse

Python + tabular dataIn [14]

Read one line,
one part at a time

CODEIn [15]
importloadpandasthe libraryaspdshorter nickname
import pandas as pdExecuted

Open a dataset

url = ...

Store the dataset address in a variable.

pd.read_csv(url)

Read the CSV and turn it into a dataframe.

df

A conventional short name for the dataframe.

Address → reader → dataframeIn [16]

Ask what is inside

CODEIn [17]
df.head()
df.shape
df.columns

head() shows five rows. shape returns rows and columns. columns lists names exactly as Python sees them.

Journalistic inspection

  1. What does one row represent?
  2. How many records are present?
  3. Which columns might answer a reporting question?
  4. Do the column names make sense?
  5. Do any values immediately look suspicious?
  6. What information would we need from a data dictionary or source note?

Optional final command if the class is moving comfortably.

Look before analysingOut [17]
05

Errors and debugging

Errors are informationIn [18]
CODEIn [18]
df.heed()
ERRORTraceback
-------------------------------------------------------------------
AttributeError: 'DataFrame' object has no attribute 'heed'
Did you mean: head() ?