Skip to main content
BIG DATA ANALYTICS WITH PYTHON
ENSEA, Abidjan, Côte d’Ivoire · 30 November – 4 December 2026
<span style="background: #F2A65A; color: #14213D; font-weight: 700; font-size: 13px; padding: 4px 10px; border-radius: 12px;">Module 6 · Spark DataFrames and Pipelines</span>
<span style="background: #D7E6E4; color: #14213D; font-weight: 600; font-size: 13px; padding: 4px 10px; border-radius: 12px; margin-left: 6px;">⏱ about TODO minutes</span>

Description of the Household Dataset

Objective Describe the census household dataset used in this module: its columns, their codes and the analysis questions.
You will Learn what each column in the household data means · Load a sample of the data with pandas · Check the values of a column with value_counts()
Data data/raw/hh-data-ml.csv (3.1 GB, pipe-separated, USB drive)
Core packages pandas

In order to explore these Spark API, we use the following dataset. The data is from a population and housing census of some country X not identified for privacy reasons although this data is a very small subset of the actual data. Each row in the data represent a single individual in the population. A summary of column description is provided below:

  • Geographic identifiers: province, region, district represented by prov_id, reg_id, dist_id and adm4 (administrative region level 4-which comes after district) respectively. Also, these same variables are embsedded in the hh_id column which represents unique id of each household.

  • urban_rural: A classification iof whether this person lived in urban or rural area

  • Sex. P05==>[1 - Masc 2 - Fém]

  • P03: whether the person is the head of the household, wife. child etc==>[0- Chef de Ménage (CM) 1- Conjoint(e) (CJ) 2- Fils/Fille3- Père/Mère 4- Beau-Père/Belle-Mère 5- Beau-Fils/Belle-Fille 6- Petit fils/Petite-fille Autre Proche du CM 8- Autre proche du CJ 9 -Sans lien de parenté]

  • Age:. Person’s date of birth is given by column P07M (month of birth), P07A (year of birth) and P08 (age)

  • Marital status: P28 (whether the person is married or not)==>[1- Célibataire, 2- Marié(e), 3- Divorcé(e)/Séparé(e), 4- Veuf(ve)] while P29 (age at marriage).

  • School attendance: P21 ==>[0 N’a Jamais fréquenté 1-A fréquenté 2- Fréquente actuellement]

  • Highest school level attended:P22N (see screenshot below for interpretation of values). All persons 3 years and older are supposed to have a response to this question. You can use this to determine when data is missing or its Not applicable.

  • Whether the person worked or not: P23==> [1- 0ccupé 2- Chômeur 3- En quête du 1er emploi 4- Ménagère 5- Elève/Etudiant 6- Retraité 7- lncapacité à travailler 8- Autre]

  • Languages. The following variables provide information about the languages the person speak fluently and whether they can read and write in that language. For each language a value of 1 means yes while 2 means no. There are are 4 languages: English (en), French (fr), a local language and other. The full list of varibles is provide below: >‘lan_spoken_local’, ‘lan_spoken_fr’, ‘lan_spoken_en’, ‘lan_spoken_other’, ‘lan_read_write_local’, ‘lan_read_write_fr’, ‘lan_read_write_en’, ‘lan_read_write_other’

  • P25. Is a question about the person employment/working statu. The possible values are provoded by the following categories: 1- Indépendant 2- Employeur 3- Salarié Public 4- Salarié Privé 5- Travailleur à la tâche 6- Apprenti- Travailleur familial 8- Autre

  • change_log.. A metadata column indicating when I last made changes to the data file.

Description of the data science task

We would like to find out the following from the data:

  1. What is the mean age in the country?
  2. Which province has the largest population
  3. Whats the mean household size in the country?

Open In Colab
Requirements: pandas.
Data: hh-data-ml.csv in data/raw/.

## Python setup
# Standard library: paths
from pathlib import Path

# Data and display
import pandas as pd
from IPython.display import Image

0. Setup and Configuration

Working Directory and Input Files

# ============================================================
# BASE WORKING DIRECTORIES
# ============================================================
# The course folder is the closest folder, going upwards, that contains environment.yml
DIR_COURSE = next(
    (p for p in [Path.cwd(), *Path.cwd().parents] if (p / "environment.yml").exists()), None
)
if DIR_COURSE is None:
    DIR_COURSE = Path.cwd()
    print("Running outside the course folder (e.g. Colab): upload the datasets to data/raw/.")
DIR_DATA = DIR_COURSE / "data" / "raw"

# ============================================================
# INPUT FILES
# ============================================================
# Census microdata subset, one row per person (pipe-separated, 3.1 GB)
FILE_HH_DATA_ML = DIR_DATA / "hh-data-ml.csv"

# Codes for the P22N column (same location as the old "../DOCS/images/" path;
# TODO: this image is not in the repository yet)
DIR_IMAGES = DIR_COURSE / "notebooks" / "DOCS" / "images"
FILE_IMG_P22N = DIR_IMAGES / "P22N.png"

Global Variables for Processing

# ============================================================
# SETTINGS
# ============================================================
# No column names or settings are repeated in this notebook.
# You can download this image from here: https://drive.google.com/file/d/1fSG0drbRiRiHZGgDF_NGEyZeDdrhrKrb/view?usp=sharing
Image(str(FILE_IMG_P22N))

hh_data = pd.read_csv(FILE_HH_DATA_ML, sep="|", nrows=500000)
hh_data.P22N.value_counts()
3    195257
2    126521
5     96464
      47138
1     20980
4     13640
Name: P22N, dtype: int64

Summary

  • TODO
  • TODO
  • TODO

Next: Spark Structured APIs