Skip to main content

Ayoub_Allali_HCP_Data

PyPI version Python 3.8+ License: MIT

A Python library that gives data scientists and analysts instant access to Morocco's official demographic data published by the Haut-Commissariat au Plan (HCP) – General Population and Housing Census RGPH 2024.

Data source: hcp.ma – Recensement Général de la Population et de l'Habitat 2024.


Installation

pip install Ayoub-Allali-HCP-Data

Quick Start

import ayoub_allali_hcp_data as hcp

# Discover all datasets
hcp.info()

# --- Scalar values ---
print(hcp.get_population_legale())     # 36828330
print(hcp.get_nombre_menages())        # 9275038
print(hcp.get_taux_urbanisation())     # 0.628

# --- DataFrames ---
df = hcp.get_population_historique()
print(df)

Available Datasets

Function Description
get_population_legale() Official legal population – 2024 (int)
get_nombre_menages() Total number of households – 2024 (int)
get_taux_urbanisation() Urbanisation rate – 2024 (float, e.g. 0.628)
get_population_historique() Population & growth rate per census (1960–2024)
get_population_urbaine_rurale() Urban / Rural counts & urbanisation rate (1960–2024)
get_structure_age() Age-group distribution % – Ensemble / Urban / Rural (2024)
get_fecondite() Total Fertility Rate by milieu (2024)
get_acces_reseaux_publics() % HH with access to water, electricity, sanitation (2024)
get_taille_menage() Average household size – Ensemble / Urban / Rural (2004–2024)

You can also use the generic load() function:

df = hcp.load("structure_age")

And list all dataset names:

hcp.list_datasets()
# ['acces_reseaux_publics', 'fecondite', 'nombre_menages', ...]

Detailed Examples

Population history

import ayoub_allali_hcp_data as hcp
import matplotlib.pyplot as plt

df = hcp.get_population_historique()
print(df)
#    Année    Population  Taux d'accroissement
# 0   1960  1.162647e+07                   NaN
# 1   1971  1.537926e+07                  2.58
# 2   1982  2.041956e+07                  2.61
# 3   1994  2.607372e+07                  2.06
# 4   2004  2.989171e+07                  1.38
# 5   2014  3.384824e+07                  1.25
# 6   2024  3.682833e+07                  0.85

plt.plot(df["Année"], df["Population"] / 1e6, marker="o")
plt.title("Population du Maroc (millions)")
plt.xlabel("Année"); plt.ylabel("Population (M)")
plt.show()

Urban vs Rural breakdown

df = hcp.get_population_urbaine_rurale()
print(df)
#    Année    Urbain     Rural   Ensemble  Taux d'urbanisation (%)
# 0   1960   3389613   8236857  11626470                      29.2
# ...
# 6   2024  23110108  13718222  36828330                      62.8

Access to public utilities

df = hcp.get_acces_reseaux_publics()
print(df)
#        Réseaux publics  Urbain  Rural  Ensemble
# 0         Eau courante    97.1   54.6      82.9
# 1          Electricité    98.6   91.8      96.3
# 2       Assainissement    93.4    9.6      65.4

Fertility rate

df = hcp.get_fecondite()
print(df)
#       Milieu  Indice synthétique de fécondité
# 0   Ensemble                              2.0
# 1     Urbain                              1.8
# 2      Rural                              2.4

License

MIT © Ayoub Allali

Data is published by HCP Morocco and is used here for educational and research purposes.

Release files for Ayoub-Allali-HCP-Data 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Ayoub-Allali-HCP-Data 1.0.0
File Size Uploaded
ayoub_allali_hcp_data-1.0.0.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Ayoub-Allali-HCP-Data 1.0.0
File Interpreter ABI Platform
ayoub_allali_hcp_data-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.4 kB

Release files / ayoub_allali_hcp_data-1.0.0.tar.gz

Download URL ayoub_allali_hcp_data-1.0.0.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
fe9ec23a35660a6279fff578dc1c42026834e38b1b306d2c62fda4ba9c381fc5
BLAKE2b-256 checksum
How to use checksums
263b6fc4636f0b9a2419794f1e8a03346b75af8cd9a0db49840b93f752ea3e7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.3

Release files / ayoub_allali_hcp_data-1.0.0-py3-none-any.whl

Download URL ayoub_allali_hcp_data-1.0.0-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
31bd8d42cdabd328cafcad6a0537e14852cc26b69d692625ab0446c7cd850d5e
BLAKE2b-256 checksum
How to use checksums
ada2a7f3231bc10929c0da01ef791e226d52b48c9b78e5127ad8db1211c9db14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.3

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page