Paul's Python CoursePPC

Project 2 of 12, for Yahya

Census Explorer

A census explorer for Yahya's Archive: ninety years of census returns for the streets round the Clocktower in one pandas table, and the usual questions answered in a line each.

About 70 minutes, in 15 steps.

Sign up free to open itLog in

Act 5 needs a free account, so your work is saved as you go. Act 1 is open to everyone.

The brief

  • YahyaOne drawer in the Archive is census returns for the streets round here, 1921 to 2011.
  • YahyaSomeone typed up one household in three, and anyone they found interesting.
  • YahyaI keep asking it the same things, how many on the Hill, who fished, and I'd like each answer in a line.
  • PaulA table with names on its columns is exactly what pandas is for.

census.csv has one row per person: year, parish, household, name, relation, age and occupation. The years are 1921, 1951, 1981 and 2011.

Write five functions. Each takes the whole census as a DataFrame, and leaves it as it was.

  • census_year(census, year): every row from that year, as a DataFrame.
  • parish_count(census, year, parish): how many people lived in that parish that year.
  • trade(census, year, occupation): a DataFrame of the name, parish and age of everyone in that occupation that year, oldest first.
  • oldest(census, year): the name of the oldest person that year.
  • parish_sizes(census, year): a Series of how many people lived in each parish that year, largest first.

The report at the bottom of the file is written for you.

What it prints
Census of 1951: 98 people
By parish: Bankside 35, Church Street 31, Hill 18, Northgate 14
On the Hill: 18
Fishermen: 6
Oldest of all: Walter Rook

What you learn

What's in it

  1. A table with names on its columns
  2. Rows, then columns
  3. Keep the rows that match
  4. Under forty
  5. Sorting and counting
  6. How many parishes?
  7. The census as a table
  8. Two conditions at once
  9. Two conditions
  10. Labels and positions
  11. Row nought
  12. How Paul would do it
  13. Make the census answers
  14. Ship it