Redistricting of pandas dataframes
Project description
# pandas-redistrict
Uses 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 identifiers
value1 value2
AGS
05354 4 5
05313 5 6
05334 6 7
15154 8 9
15159 10 11
15151 12 13
15082 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 value2
AGS
05334 15.00 18.00
15001 2.40 2.60
15082 35.44 38.81
15086 0.96 1.04
15091 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 value2
0 05354 2008 4 5
1 05313 2008 5 6
2 05334 2011 6 7
3 15154 2005 8 9
4 15159 2005 10 11
5 15151 2005 12 13
6 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 year
0 15001 2.40 2.60 2005
1 15082 22.44 24.81 2005
2 15086 0.96 1.04 2005
3 15091 4.20 4.55 2005
0 05334 9.00 11.00 2008
0 05334 6.00 7.00 2011
0 15082 13.00 14.00 2013
```
Uses 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 identifiers
value1 value2
AGS
05354 4 5
05313 5 6
05334 6 7
15154 8 9
15159 10 11
15151 12 13
15082 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 value2
AGS
05334 15.00 18.00
15001 2.40 2.60
15082 35.44 38.81
15086 0.96 1.04
15091 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 value2
0 05354 2008 4 5
1 05313 2008 5 6
2 05334 2011 6 7
3 15154 2005 8 9
4 15159 2005 10 11
5 15151 2005 12 13
6 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 year
0 15001 2.40 2.60 2005
1 15082 22.44 24.81 2005
2 15086 0.96 1.04 2005
3 15091 4.20 4.55 2005
0 05334 9.00 11.00 2008
0 05334 6.00 7.00 2011
0 15082 13.00 14.00 2013
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pandas-redistrict-0.0.2.tar.gz
(41.9 kB
view details)
Built Distributions
File details
Details for the file pandas-redistrict-0.0.2.tar.gz
.
File metadata
- Download URL: pandas-redistrict-0.0.2.tar.gz
- Upload date:
- Size: 41.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd1fec48690f624e6c0e0cefa229b26a8b8657d41bbdbdc0e761bc84ca31ca7a |
|
MD5 | f8672e7d48fa59292e706f0602d403cf |
|
BLAKE2b-256 | b58584a888843e0559be0e4b1fad831604303b4fa1b7bc60b2f2b0cb39edd18c |
File details
Details for the file pandas_redistrict-0.0.2-py2.py3-none-any.whl
.
File metadata
- Download URL: pandas_redistrict-0.0.2-py2.py3-none-any.whl
- Upload date:
- Size: 43.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c409bed08e327242165528ff690a24633ab5ab657663c4d98ec77da1e6325dd |
|
MD5 | 587758fbbddd4588811c1c14f4222934 |
|
BLAKE2b-256 | cb78f7dd9651dfe8d5581d758fd15e20b9fc8b3eed9673962fa4b1cb910ecb43 |
File details
Details for the file pandas-redistrict-0.0.2.macosx-10.10-intel.tar.gz
.
File metadata
- Download URL: pandas-redistrict-0.0.2.macosx-10.10-intel.tar.gz
- Upload date:
- Size: 44.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f97b59a0d6705951b86ff587395eeb9b62a5e61e1ea4627b7a47431bc2713cd6 |
|
MD5 | 525a33510ade786e4c74a85976b357bf |
|
BLAKE2b-256 | f7983b9341e1f953e6fc8d7196ab1f1c19e77060fb7919663262142942a74124 |