Python packages / tossd-reader / How-to guides
Rank providers by disbursement
Rank official providers by total disbursement with df.tossd.rank_entities(), which excludes aggregate summary rows by default so the ranking reflects individual reporting institutions.
Steps
-
Query data for the target year.
rank_entitiesneeds{dimension}_code,{dimension}_name, and the value column it sums, all present in the"analysis"preset.import tossd_reader as tossd df = tossd.get_tossd(years=2024, columns="analysis", units="usd_million") -
Inspect the effect of aggregate rows. Published TOSSD files bundle summary rows (
provider_code == 0,provider_name == "Aggregate") alongside the providers that fund them. Passinclude_aggregates=Trueto observe their impact.cols = ["provider_code", "provider_name", "usd_disbursement", "share_pct", "rank"] print( df.tossd.rank_entities(top=3, include_aggregates=True)[cols].to_string(index=False) )provider_code provider_name usd_disbursement share_pct rank 0 Aggregate 99379.609718 19.968737 1 302 United States 67695.935324 13.602412 2 918 EU Institutions 58667.476757 11.788288 3Aggregate rows outrank individual providers because they summarise total reporting. By default,
rank_entitiessetsinclude_aggregates=Falseto exclude them from the ranking.print(df.tossd.rank_entities(top=3)[cols].to_string(index=False))provider_code provider_name usd_disbursement share_pct rank 302 United States 67695.935324 16.996373 1 918 EU Institutions 58667.476757 14.729604 2 4 France 25444.627005 6.388365 3share_pctshifts too. United States's share rises from 13.6% to 17.0% once Aggregate's USD 99.4 billion drops out of the total each share is measured against. -
Show every field the ranking adds. Drop the column subset to inspect every field
rank_entitiesadds, includingn_activities.print(df.tossd.rank_entities(top=5).to_string(index=False))provider_code provider_name usd_disbursement n_activities share_pct rank 302 United States 67695.935324 61832 16.996373 1 918 EU Institutions 58667.476757 85406 14.729604 2 4 France 25444.627005 14066 6.388365 3 915 Asian Development Bank Group 18558.332668 4671 4.659428 4 701 Japan 17339.414452 17981 4.353395 5n_activitiescounts distincttossd_idvalues per provider, excluding the"0000"placeholder that marks bundled lines with no activity identifier of their own.
rank_entities works for any dimension with a matching {dimension}_code/{dimension}_name pair. Pass dimension="recipient" (or "sector", "purpose", "channel") to rank a different one.
Verify it worked
share_pct is each provider's share of the ranked total, so the full, untruncated ranking should sum to 100.
print(df.tossd.rank_entities()["share_pct"].sum())
100.0
See also
- Pillars and aggregate rows for how aggregate rows are built and the bilateral/multilateral double-counting risk.
- Columns, presets, and units for what the
"analysis"preset includes.