pak_crops / README.md
junaid008's picture
pakdata 0.1.1: pak_crops
849b949 verified
|
Raw History Blame Contribute Delete
10.3 kB
metadata
license: cc-by-4.0
pretty_name: >-
  Pakistan crop statistics: area, production and yield of 79 crops, 1961-2024
  (FAOSTAT)
language:
  - en
task_categories:
  - tabular-regression
tags:
  - pakistan
  - pakdata
  - tabular
  - agriculture
  - crops
  - faostat
  - food-security
size_categories:
  - 1K<n<10K
configs:
  - config_name: default
    data_files:
      - split: train
        path: data/train.parquet

Pakistan crop statistics: area, production and yield of 79 crops, 1961-2024 (FAOSTAT)

Part of pakdata, a collection of real, openly licensed Pakistan-specific datasets for machine learning. Every value comes from the named public source below; nothing is synthetic or AI-generated.

Rows 4,202
Default target yield_kg_per_ha (regression)
Source FAO (FAOSTAT, Production: Crops and livestock products, QCL)
License CC BY 4.0 (FAO Statistical Database Terms of Use)
Snapshot 2026.11

Load it

# pakdata (scikit-learn style, works offline)   pip install pakdata
from pakdata import load_pak_crops
X, y = load_pak_crops(return_X_y=True)

# Hugging Face datasets (also gives PyTorch / TensorFlow / JAX formats)
from datasets import load_dataset
ds = load_dataset("junaid008/pak_crops", split="train")
torch_ds = ds.with_format("torch")

# pandas / Polars / DuckDB, straight from the Hub
import pandas as pd;  df = pd.read_parquet("hf://datasets/junaid008/pak_crops/data/train.parquet")
import polars as pl;  df = pl.read_parquet("hf://datasets/junaid008/pak_crops/data/train.parquet")
import duckdb;        duckdb.sql("SELECT * FROM 'hf://datasets/junaid008/pak_crops/data/train.parquet'")

Plain CSV (Excel, R, Julia, MATLAB, SPSS, anything): https://huggingface.co/datasets/junaid008/pak_crops/resolve/main/csv/pak_crops.csv

df <- read.csv("https://huggingface.co/datasets/junaid008/pak_crops/resolve/main/csv/pak_crops.csv")

JSON API (JavaScript, mobile apps, any language): https://datasets-server.huggingface.co/rows?dataset=junaid008/pak_crops&config=default&split=train&offset=0&length=100

Features used by pakdata: crop, crop_group, year, area_harvested_ha, area_harvested_flag

Kept in the table but not used as features (ids, raw dates, or columns that would leak the target): fao_item_code, production_tonnes, production_flag, yield_flag

Data card

The full data card (column meanings and units, how it was built, caveats, suggested tasks):

.. _pak_crops_dataset:

Pakistan crop statistics (FAOSTAT), 1961-2024
---------------------------------------------

Harvested area, production and yield of every primary crop FAO reports for
Pakistan, one row per (crop, year), with FAO's data-quality flag on every value.

**Data Set Characteristics:**

:Number of Instances: 4202 (79 crops x up to 64 years)
:Number of Attributes: 5 features (``crop``, ``crop_group``, ``year``, ``area_harvested_ha``, ``area_harvested_flag``) + target; 4 more columns kept in ``frame`` only
:Default target: ``yield_kg_per_ha`` (kg per hectare)
:Time coverage: 1961-2024 (annual; coverage varies by crop, see Caveats)
:Geographic coverage: Pakistan, national totals (FAO area code 165); no provincial breakdown
:Source: Food and Agriculture Organization of the United Nations (FAO), FAOSTAT domain QCL "Production: Crops and livestock products", last updated 2025-12-31. https://www.fao.org/faostat/en/#data/QCL ; bulk file https://bulks-faostat.fao.org/production/Production_Crops_Livestock_E_Asia.zip
:License: CC BY 4.0, complemented by the FAO Statistical Database Terms of Use, https://www.fao.org/contact-us/terms/db-terms-of-use/en/ (redistribution permitted with attribution; no implied FAO endorsement; no commercial promotion)
:Snapshot: 2026.11 (retrieved 2026-11-29)

**Columns:**

- ``crop`` (category): FAO item name exactly as published, e.g. ``Wheat``, ``Rice`` (= rice paddy), ``Seed cotton, unginned``, ``Sugar cane``, ``Maize (corn)``, ``Chick peas, dry``, ``Mangoes, guavas and mangosteens``, ``Tangerines, mandarins, clementines`` (FAO's item for kinnow), ``Oranges``, ``Dates``, ``Potatoes``, ``Onions and shallots, dry (excluding dehydrated)``.
- ``crop_group`` (category): pakdata grouping of the FAO item, following FAOSTAT's commodity aggregates: ``cereal`` (6 crops), ``pulse`` (6), ``fibre`` (3), ``sugar`` (2), ``oilseed`` (12, includes coconuts and olives, as in FAO "Oilcrops"), ``root_tuber`` (3), ``vegetable`` (17, includes melons and watermelons), ``fruit`` (22), ``tree_nut`` (4), ``spice`` (3), ``stimulant`` (1, tobacco). This is the only column not taken from FAO.
- ``fao_item_code`` (int): FAOSTAT item code (identifier; excluded from features).
- ``year`` (int): calendar year of the FAO record.
- ``area_harvested_ha`` (hectares): area harvested.
- ``area_harvested_flag`` (category): FAO flag for the area value.
- ``production_tonnes`` (tonnes): production quantity. **Excluded from features**: FAO's yield is production / area, so production and area together give the target exactly.
- ``production_flag`` (category): FAO flag for production (excluded from features).
- ``yield_kg_per_ha`` (kg/ha): yield as published by FAO (target).
- ``yield_flag`` (category): FAO flag for yield (excluded from features, it describes the target).

FAO flag codes: ``A`` = official figure; ``E`` = estimated value (FAO estimate);
``I`` = value imputed by a receiving agency; ``X`` = figure from an external
organization (in this file every ``X`` yield/production value from the early
decades is also annotated by FAO as an "unofficial figure"; that note is not
kept as a column). Counts in this file:

- ``yield_flag``: A 3626, E 365, X 211
- ``area_harvested_flag``: A 3635, E 240, X 218, I 109
- ``production_flag``: A 3639, X 226, E 204, I 133

So about 86% of yields are official figures. Estimated or external yields are
concentrated in minor fruits, vegetables, nuts and spices and in the 1960s-70s;
the staple crops (wheat, rice, seed cotton, sugar cane, chickpeas, mangoes,
potatoes, onions) are official (``A``) in every year; maize and dates have one
non-official year each. Oranges (1961-1990) and tangerines/kinnow (most years)
are mainly ``X``. Filter with ``frame[frame.yield_flag == "A"]`` to use official
figures only.

**How it was built:** ``scripts/build_pak_crops.py`` downloads FAO's QCL bulk file
for Asia (wide format with flags), keeps rows for Pakistan (area code 165) and the
elements Area harvested (5312, ha), Production (5510, t) and Yield (5412, kg/ha),
keeps the 79 items that have an area-harvested element (primary crops) and drops
FAO aggregate items (codes >= 1700, e.g. "Cereals, primary") and livestock. The
wide year columns are reshaped to one row per (crop, year). 438 crop-years for
which FAO publishes no yield were dropped: in all of them FAO reports a zero
harvested area (408, mostly 1961-1981 for vegetables and minor fruits that were not
reported separately then) or no area at all (30, "Other oil seeds" 1961-1990).
No value was filled, interpolated or recomputed. Rows are sorted by ``crop``, ``year``.

**Caveats and known biases:**

- National totals only; reporting conventions changed over time (e.g. many vegetables
  start in 1980, newly reported fruits such as olives, persimmons, strawberries and
  grapefruit appear only after 2016). ``Oranges`` has a gap 1991-2015.
  A crop's first year in the file is where FAO starts reporting it, not when it was first grown.
- Kinnow, Pakistan's main citrus, is recorded by FAO under
  ``Tangerines, mandarins, clementines``; ``Mangoes, guavas and mangosteens`` mixes
  three fruits; ``... n.e.c.`` items are residual groups of many minor crops.
- FAO yields are computed from production and area; for a few small crops with
  rounded areas, ``production_tonnes / area_harvested_ha * 1000`` differs from
  ``yield_kg_per_ha`` by up to ~11%.
- FAO figures can differ from Pakistan Bureau of Statistics / Ministry of National
  Food Security figures (e.g. fiscal-year vs calendar-year attribution); FAO revises
  past values between releases.
- Yields span 219 to 74,252 kg/ha across crops (cereals vs. sugar cane/vegetables),
  so crop identity alone explains most of the variance: a per-crop mean of
  log-yield already gives R^2 ~0.94 under random 5-fold CV. Model ``log(yield)``
  and evaluate with a time-based split (train on earlier years, test on later
  ones) or within crops. A random row split lets the model interpolate between
  neighbouring years of the same crop, which flatters the score.
- No weather, irrigation, fertiliser or price variables are included.

**Suggested tasks:**

1. Regression (beginner): predict ``log(yield_kg_per_ha)`` from ``crop``, ``year`` and
   ``area_harvested_ha``; train on years <= 2014, test on 2015-2024. A
   one-hot + RandomForest baseline gives R^2 ~0.92 on the log scale.
2. Time series (intermediate): forecast wheat, rice or seed-cotton yield one year ahead
   from lagged yields; compare against a naive "last year" forecast.
3. Clustering: build a crop x year matrix of standardised yield trends and cluster
   crops by growth pattern (e.g. Green Revolution cereals vs. stagnant pulses).
4. Classification / data quality: predict whether a value is official (``yield_flag == "A"``)
   from crop group, year and area, and discuss why missing-data mechanisms matter.

**Citation / attribution:**

FAO. 2025. FAOSTAT: Production: Crops and livestock products. Accessed on 29 November 2026. https://www.fao.org/faostat/en/#data/QCL. Licence: CC-BY-4.0.

Use of this data does not imply any endorsement by FAO of pakdata or of any
analysis made with it.

Citation and attribution

FAO. 2025. FAOSTAT: Production: Crops and livestock products. Accessed on 29 November 2026. https://www.fao.org/faostat/en/#data/QCL. Licence: CC-BY-4.0.

Packaged by pakdata (https://github.com/junaidaslam2006/pakData). Build script: scripts/build_pak_crops.py.