Last updated:
0 purchases
pandasredistrict 0.0.3
# pandas-redistrictUses data on redistricting to apply redistricting to older datasets to represent the districts in their current state.Supports merging and splitting of districts:- Merged districts are summed up under new identifier- Split districts are distributed by population-based ratio.Data on redistricting is in `data/` directory. Currently only available for German *Kreise* (containing reforms in NRW, Sachsen, Sachsen-Anhalt and Mecklenburg-Vorpommern).Install like this: pip install pandas-redistrict## Usage``` python>>> df # Values indexed by German district identifiersvalue1 value2AGS05354 4 505313 5 605334 6 715154 8 915159 10 1115151 12 1315082 13 14>>> # Port old identifiers to new versions. Sum and distribute values on the way>>> from redistrict import redistrict>>> redistrict(df, 'de/kreise', drop=True, splits=True)value1 value2AGS05334 15.00 18.0015001 2.40 2.6015082 35.44 38.8115086 0.96 1.0415091 4.20 4.55```When you want to preserve groups inside districts, you can use ``redistrict_grouped``:``` python>>> # Specify district column (e.g. AGS)>>> # Also specify groups to preserve, in this case year>>> df AGS year value1 value20 05354 2008 4 51 05313 2008 5 62 05334 2011 6 73 15154 2005 8 94 15159 2005 10 115 15151 2005 12 136 15082 2013 13 14>>> from redistrict import redistrict_grouped redistrict_grouped(df, 'de/kreise', ['year'], district_col='AGS', value_cols=['value1', 'value2'], drop=True) AGS value1 value2 year0 15001 2.40 2.60 20051 15082 22.44 24.81 20052 15086 0.96 1.04 20053 15091 4.20 4.55 20050 05334 9.00 11.00 20080 05334 6.00 7.00 20110 15082 13.00 14.00 2013```
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.