liveBook · Manning

Percentage change

As explained in Data Storytelling with Altair and AI

A percentage increase is a measure of relative growth calculated by dividing the change in a quantity by its original value and expressing the result as a percentage.

Percentage change expresses movement relative to a starting value rather than as an absolute difference. Calculate it as (final value − starting value) / starting value × 100. This makes series with different arrival totals comparable: a country with fewer arrivals can still show stronger relative growth. section 2.3.1

For tourist arrivals, use each country’s 1994 total as the baseline. For every later year, subtract that baseline, divide by it, and store the result as a percentage-increase field. A line chart of that field answers how much each country has grown since 1994 more directly than a chart of raw arrivals. section 2.3.1

A practical workflow is:

  • Clean and aggregate arrivals by year and country before calculating the measure. section 2.3.1
  • Calculate a percentage-increase value separately for each country using its 1994 arrival total. section 2.3.1
  • Plot percentage increase by year, then visually emphasize the country the audience needs to examine. section 2.3.1
  • Label the final-year values so viewers can read the comparison without estimating from the lines. section 2.3.1

Comparing Portugal and Germany

Raw tourist-arrival totals do not immediately reveal which country grew more since 1994. Replacing totals with percentage increase puts Portugal and Germany on a comparable scale. Build a new dataset containing those values, then use it as the input to the chart. section 2.3.1 section 2.4.2

Listing 2.11 Calculating the percentage increase for each country
for country in df['Country'].unique():
    current = df[df['Country'] == country]['Tourist Arrivals']
    base = df[(df['Country'] == country) & (df['Year'] == 1994)]['Tourist Arrivals'].values[0]
    df.loc[df['Country'] == country, 'PI'] = (current - base)/ base*100   #1

This implementation loops through countries, retrieves each country’s 1994 baseline, and writes the calculated percentage increase into the PI column. section 2.3.1

When generating the workflow with GitHub Copilot, describe the calculation precisely: create a new dataset, use 1994 as the reference year, and calculate percentage increase for the requested countries. Review proposed code and refine the request or implementation when needed. section 2.4.2 section 2.4

How Data Storytelling with Altair and AI covers it

How deep it goes
Defines the formula and implements a per-country 1994-baseline calculation, then plots and labels the resulting values.
Examples
Uses tourist arrivals for Portugal, Germany, and other countries from 1994 through 2018.
What it assumes
Assumes a cleaned country-by-year DataFrame and introduces the percentage-increase calculation from its formula.
What you can do after
Apply it via pandas and Altair to calculate baseline-relative growth and communicate it in a focused line chart.
How it connects
Connects percentage change with pandas DataFrames, Altair line charts, data cleaning, annotations, and GitHub Copilot.

Also explained in

Compare how 3 books explain percentage change →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Storytelling with Altair and AI. The section links point to the parts of the book it draws on.