Skip to main content

A package for aggregating and merging US geographic data frames.

Project description

USAggregate

USAggregate is a Python package for aggregating and merging US relational data frames. Current version is 1.1.1.

Example Use Case

Merging demographic data at the zip code level with ice cream sales data at the city level to measure the correlation between demographics and ice cream sales at the county level.

Installation

You can install the package using pip:

pip install USAggregate

Use Notes

Users will need to manually change geographic identifier columns to 'zipcode', 'city', 'county', 'COUNTYFP' or 'state'. Zip codes can be aggregated to the city-state levels without additional info. Data at the city our county levels will need state information as well due to duplicate names. If each data frame you wish to aggregate has a year identifier and would like to group by year, name the column 'Year'. If you would like to group by other timeframes (day, week, month, and quarter are available options) label your columns 'Date'. In this version, users can also specify specific columns they would like to be aggregated using a method differing from the global option set.

Below is an example of package usage.

import pandas as pd
from USAggregate import usaggregate

data_zip = pd.DataFrame({
    'zipcode': ['98199', '98103', '98001', '98002', '91360', '91358', '93001', '93003', '98199', '98103', '98001', '98002', '91360', '91358', '93001', '93003'],
    'value1': [1, 2, 3, np.nan, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8],
    'chr1': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'],
    'Year': [2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011]
})

data_city = pd.DataFrame({
    'city': ['Seattle', 'Auburn', 'Thousand Oaks', 'Ventura', 'Seattle', 'Auburn', 'Thousand Oaks', 'Ventura'],
    'state': ['WA', 'WA', 'CA', 'CA', 'WA', 'WA', 'CA', 'CA'],
    'value2': [np.nan, '2', '3', '4', '1', '2', '3', '4'],
    'chr2': [np.nan, 'J', 'K', 'L', 'I', 'J', 'K', 'L'],
    'Date': ['1/1/2010', '1/1/2010', '1/1/2010', '1/1/2010', '1/1/2011', '1/1/2011', '1/1/2011', '1/1/2011']
})

data_county = pd.DataFrame({
    'county': ['King County', 'Ventura County', 'King County', 'Ventura County'],
    'state': ['Washington', 'California', 'Washington', 'California'],
    'value3': [5, 6, 5, 6],
    'chr3': ['M', 'N', 'M', 'N'],
    'Year': ['2010', '2010', '2011', '2011']
})

df = usaggregate(
    data=[data_city, data_zip, data_county],
    level='county',
    agg_numeric_geo='sum',
    agg_character_geo='first',
    col_specific_agg_num_geo={'value1': 'mean'},
    col_specific_agg_chr_geo={'chr1': 'last'},
    time_period='year'
)

print(df)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

usaggregate-1.1.2.tar.gz (643.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

USAggregate-1.1.2-py3-none-any.whl (643.5 kB view details)

Uploaded Python 3

File details

Details for the file usaggregate-1.1.2.tar.gz.

File metadata

  • Download URL: usaggregate-1.1.2.tar.gz
  • Upload date:
  • Size: 643.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for usaggregate-1.1.2.tar.gz
Algorithm Hash digest
SHA256 dda10c91f80bd7649c03901ef46760e34bf5f9539d743a92ae618ea41423a0f6
MD5 7a6430d6c39cf57eac95e630bde4f61d
BLAKE2b-256 8439da7e9a9588a8e22b20d1ef67d042e04366585b59269042df225161ecafc0

See more details on using hashes here.

File details

Details for the file USAggregate-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: USAggregate-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 643.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for USAggregate-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1c56e67d5107eea0c4af1a4f7f18747d905da50dd8652470257e9d063a388b23
MD5 3b354726193ada8c9e6be841ac6b44e7
BLAKE2b-256 db921587bee7bac62916538a4a2626453f5fba39633308ef28e62f1ac2d73be8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page