{"id":13936565,"url":"https://github.com/jsvine/weightedcalcs","last_synced_at":"2025-04-04T15:09:58.547Z","repository":{"id":60721922,"uuid":"77199381","full_name":"jsvine/weightedcalcs","owner":"jsvine","description":"Pandas-based utility to calculate weighted means, medians, distributions, standard deviations, and more.","archived":false,"fork":false,"pushed_at":"2024-11-10T18:51:05.000Z","size":1649,"stargazers_count":108,"open_issues_count":3,"forks_count":7,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-28T14:05:57.515Z","etag":null,"topics":["pandas","statistics"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jsvine.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-23T05:09:36.000Z","updated_at":"2025-03-07T14:15:05.000Z","dependencies_parsed_at":"2025-01-19T06:06:31.382Z","dependency_job_id":"2e924fdc-a805-4631-9a66-80f099ea9cd2","html_url":"https://github.com/jsvine/weightedcalcs","commit_stats":{"total_commits":18,"total_committers":2,"mean_commits":9.0,"dds":0.05555555555555558,"last_synced_commit":"f70fe2d3e39b928b283667b9e51e233a540655b3"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsvine%2Fweightedcalcs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsvine%2Fweightedcalcs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsvine%2Fweightedcalcs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsvine%2Fweightedcalcs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsvine","download_url":"https://codeload.github.com/jsvine/weightedcalcs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247198463,"owners_count":20900080,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pandas","statistics"],"created_at":"2024-08-07T23:02:47.605Z","updated_at":"2025-04-04T15:09:58.531Z","avatar_url":"https://github.com/jsvine.png","language":"Python","readme":"[![Version](https://img.shields.io/pypi/v/weightedcalcs.svg)](https://pypi.python.org/pypi/weightedcalcs) [![Build status](https://travis-ci.org/jsvine/weightedcalcs.png)](https://travis-ci.org/jsvine/weightedcalcs) [![Code coverage](https://img.shields.io/coveralls/jsvine/weightedcalcs.svg)](https://coveralls.io/github/jsvine/weightedcalcs) [![Support Python versions](https://img.shields.io/pypi/pyversions/weightedcalcs.svg)](https://pypi.python.org/pypi/weightedcalcs)\n\n# weightedcalcs\n\n`weightedcalcs` is a `pandas`-based Python library for calculating weighted means, medians, standard deviations, and more.\n\n## Features\n\n- Plays well with `pandas`.\n- Support for weighted means, medians, quantiles, standard deviations, and distributions.\n- Support for grouped calculations, using `DataFrameGroupBy` objects.\n- Raises an error when your data contains null-values.\n- Full test coverage.\n\n## Installation\n\n```sh\npip install weightedcalcs\n```\n\n## Usage\n\n### Getting started\n\nEvery weighted calculation in `weightedcalcs` begins with an instance of the `weightedcalcs.Calculator` class. `Calculator` takes one argument: the name of your weighting variable. So if you're analyzing a survey where the weighting variable is called `\"resp_weight\"`, you'd do this:\n\n```python\nimport weightedcalcs as wc\ncalc = wc.Calculator(\"resp_weight\")\n```\n\n### Types of calculations\n\nCurrently, `weightedcalcs.Calculator` supports the following calculations:\n\n- `calc.mean(my_data, value_var)`: The weighted arithmetic average of `value_var`.\n- `calc.quantile(my_data, value_var, q)`: The weighted quantile of `value_var`, where `q` is between 0 and 1.\n- `calc.median(my_data, value_var)`: The weighted median of `value_var`, equivalent to `.quantile(...)` where `q=0.5`.\n- `calc.std(my_data, value_var)`: The weighted standard deviation of `value_var`.\n- `calc.distribution(my_data, value_var)`: The weighted proportions of `value_var`, interpreting `value_var` as categories.\n- `calc.count(my_data)`: The weighted count of all observations, i.e., the total weight.\n- `calc.sum(my_data, value_var)`: The weighted sum of `value_var`.\n\nThe `obj` parameter above should one of the following:\n\n- A `pandas` `DataFrame` object\n- A `pandas` `DataFrame.groupby` object\n- A plain Python dictionary where the keys are column names and the values are equal-length lists.\n\n### Basic example\n\nBelow is a basic example of using `weightedcalcs` to find what percentage of Wyoming residents are married, divorced, et cetera:\n\n```python\nimport pandas as pd\nimport weightedcalcs as wc\n\n# Load the 2015 American Community Survey person-level responses for Wyoming\nresponses = pd.read_csv(\"examples/data/acs-2015-pums-wy-simple.csv\")\n\n# `PWGTP` is the weighting variable used in the ACS's person-level data\ncalc = wc.Calculator(\"PWGTP\")\n\n# Get the distribution of marriage-status responses\ncalc.distribution(responses, \"marriage_status\").round(3).sort_values(ascending=False)\n\n# -- Output --\n# marriage_status\n# Married                                0.425\n# Never married or under 15 years old    0.421\n# Divorced                               0.097\n# Widowed                                0.046\n# Separated                              0.012\n# Name: PWGTP, dtype: float64\n```\n\n### More examples\n\n[See this notebook to see examples of other calculations, including grouped calculations.](examples/notebooks/example-usage.ipynb)\n\n[Max Ghenis](https://github.com/MaxGhenis) has created [a version of the example notebook that can be run directly in your browser](https://colab.research.google.com/gist/MaxGhenis/4c96163eacebc1005419c9533a568c7e/weightedcalcs-example-usage-scf.ipynb), via Google Colab. \n\n### Weightedcalcs in the wild\n\n- \"[Procesando los microdatos de la Encuesta Permanente de Hogares](http://blog.jazzido.com/2017/01/09/procesando-microdatos-eph),\" by Manuel Aristarán\n- [BuzzFeedNews/2017-01-media-platform-and-news-trust-survey](https://github.com/BuzzFeedNews/2017-01-media-platform-and-news-trust-survey/blob/master/notebooks/platform-trust-additional-analysis.ipynb)\n- [BuzzFeedNews/2016-12-transgender-rights-survey](https://github.com/BuzzFeedNews/2016-12-transgender-rights-survey/blob/master/notebooks/additional-analysis.ipynb)\n\n## Other Python weighted-calculation libraries\n\n- [`tinybike/weightedstats`](https://github.com/tinybike/weightedstats)\n- [`nudomarinero/wquantiles`](https://github.com/nudomarinero/wquantiles/)\n\n","funding_links":[],"categories":["Statistics","Python"],"sub_categories":["NLP","Automated Machine Learning"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsvine%2Fweightedcalcs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsvine%2Fweightedcalcs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsvine%2Fweightedcalcs/lists"}