From e9e7a35e5b4a172fd050a44bb6792a59d689d557 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Tue, 22 Jul 2025 12:05:09 -0400 Subject: [PATCH 1/3] Remove all taxcalc functionality and dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove taxcalc from pyproject.toml optional dependencies - Delete microdf/taxcalc.py module - Delete microdf/tests/test_taxcalc.py - Remove taxcalc imports and exports from microdf/__init__.py - Remove taxcalc from _optional.py VERSIONS dict This removes all taxcalc-specific functionality from the microdf package. Documentation notebooks that demonstrate taxcalc integration may need updates in a follow-up commit. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- microdf/__init__.py | 13 --- microdf/_optional.py | 4 +- microdf/taxcalc.py | 161 ---------------------------------- microdf/tests/test_taxcalc.py | 25 ------ pyproject.toml | 3 - 5 files changed, 1 insertion(+), 205 deletions(-) delete mode 100644 microdf/taxcalc.py delete mode 100644 microdf/tests/test_taxcalc.py diff --git a/microdf/__init__.py b/microdf/__init__.py index ec8e858..905bca3 100644 --- a/microdf/__init__.py +++ b/microdf/__init__.py @@ -47,13 +47,6 @@ squared_poverty_gap, ) from .tax import mtr, tax_from_mtrs -from .taxcalc import ( - add_weighted_metrics, - calc_df, - n65, - recalculate, - static_baseline_calc, -) from .ubi import ubi_or_bens from .utils import ( cartesian_product, @@ -129,12 +122,6 @@ # tax.py "mtr", "tax_from_mtrs", - # taxcalc.py - "static_baseline_calc", - "add_weighted_metrics", - "n65", - "calc_df", - "recalculate", # ubi.py "ubi_or_bens", # utils.py diff --git a/microdf/_optional.py b/microdf/_optional.py index 86ebdf9..3d79574 100644 --- a/microdf/_optional.py +++ b/microdf/_optional.py @@ -7,9 +7,7 @@ # Adapted from: # https://github.com/pandas-dev/pandas/blob/master/pandas/compat/_optional.py -VERSIONS = { - "taxcalc": "2.0.0", -} +VERSIONS = {} def _get_version(module: types.ModuleType) -> str: diff --git a/microdf/taxcalc.py b/microdf/taxcalc.py deleted file mode 100644 index 84b4ad3..0000000 --- a/microdf/taxcalc.py +++ /dev/null @@ -1,161 +0,0 @@ -from typing import Optional - -import pandas as pd -import taxcalc - -import microdf as mdf -from microdf._optional import import_optional_dependency - - -def static_baseline_calc( - recs: pd.DataFrame, year: int -) -> "taxcalc.Calculator": - """Creates a static Calculator object. - - :param recs: Records object. - :param year: Year to advance to. - :returns: Calculator object. - """ - tc = import_optional_dependency("taxcalc") - calc = tc.Calculator(records=recs, policy=tc.Policy()) - calc.advance_to_year(year) - calc.calc_all() - return calc - - -def add_weighted_metrics( - df: pd.DataFrame, - metric_vars: list, - w: str = "s006", - divisor: float = 1e6, - suffix: str = "_m", -) -> None: - """Adds weighted metrics in millions to a Tax-Calculator pandas DataFrame. - - Columns are renamed to *_m. - - :param df: A pandas DataFrame containing Tax-Calculator data. - :param metric_vars: A list of column names to weight, or a single column - name. - :param w: Weight column. Defaults to s006. - :param divisor: Number by which the product is divided. Defaults to 1e6. - :param suffix: Suffix to add to each weighted total. Defaults to '_m' to - match divisor default of 1e6. - :returns: Nothing. Weighted columns are added in place. - """ - df[w + suffix] = df[w] / divisor - metric_vars = mdf.listify(metric_vars) - for metric_var in metric_vars: - df[metric_var + suffix] = df[metric_var] * df[w + suffix] - - -def n65( - age_head: pd.Series, age_spouse: pd.Series, elderly_dependents: pd.Series -) -> pd.Series: - """Calculates number of people in the tax unit age 65 or older. - - :param age_head: Series representing age_head from taxcalc data. - :param age_spouse: Series representing age_spouse from taxcalc data. - :param elderly_dependents: Series representing elderly_dependents from - taxcalc data. - :returns: Series representing the number of people age 65 or older. - """ - return ( - (age_head >= 65).astype(int) - + (age_spouse >= 65).astype(int) - + elderly_dependents - ) - - -def calc_df( - records: Optional[pd.DataFrame] = None, - policy: Optional[taxcalc.Policy] = None, - year: int = 2020, - reform: Optional[dict] = None, - group_vars: Optional[list] = None, - metric_vars: Optional[list] = None, - group_n65: Optional[bool] = False, -) -> pd.DataFrame: - """Creates a pandas DataFrame for given Tax-Calculator data. - - s006 is always included, and RECID is used as an index. - - :param records: An optional Records object. If not provided, uses CPS - records. (Default value = None) - :param policy: An optional Policy object. If not provided, uses default - Policy. - :param year: An optional year to advance to. If not provided, defaults to - 2020. - :param reform: An optional reform to implement for the Policy object. - (Default value = None) - :param group_vars: An optional list of column names to include in the - DataFrame. (Default value = None) - :param metric_vars: An optional list of column names to include and - calculate weighted sums of (in millions named as *_m) in the DataFrame. - (Default value = None) - :param group_n65: Whether to calculate and group by n65. Defaults to False. - :returns: A pandas DataFrame. market_income is also always calculated. - """ - tc = import_optional_dependency("taxcalc") - # Assign defaults. - if records is None: - records = tc.Records.cps_constructor() - if policy is None: - policy = tc.Policy() - if reform is not None: - policy.implement_reform(reform) - # Calculate. - calc = tc.Calculator(records=records, policy=policy, verbose=False) - calc.advance_to_year(year) - calc.calc_all() - # Get a deduplicated list of all columns. - if group_n65: - group_vars = group_vars + [ - "age_head", - "age_spouse", - "elderly_dependents", - ] - # Include expanded_income and benefits to produce market_income. - all_cols = mdf.listify( - [ - "RECID", - "s006", - "expanded_income", - "aftertax_income", - mdf.BENS, - group_vars, - metric_vars, - ] - ) - df = calc.dataframe(all_cols) - # Create core elements. - df["market_income"] = mdf.market_income(df) - df["bens"] = df[mdf.BENS].sum(axis=1) - df["tax"] = df.expanded_income - df.aftertax_income - if group_n65: - df["n65"] = n65(df.age_head, df.age_spouse, df.elderly_dependents) - df.drop( - ["age_head", "age_spouse", "elderly_dependents"], - axis=1, - inplace=True, - ) - # Add calculated columns for metrics. - mdf.add_weighted_metrics(df, metric_vars) - # Set RECID to int and set it as index before returning. - df["RECID"] = df.RECID.map(int) - return df.set_index("RECID") - - -def recalculate(df: pd.DataFrame) -> None: - """Recalculates fields in the DataFrame for after components have changed. - - :param df: DataFrame for use in microdf. - :returns: Nothing. Updates the DataFrame in place. - """ - # Recalculate TPC's Expanded Cash Income measure. - cols = df.columns - if "tpc_eci" in cols: - df.tpc_eci = mdf.tpc_eci(df) - # Recalculate weighted metrics (anything ending in _m). - mcols = cols[cols.str.endswith("_m")] - mdf.add_weighted_metrics(df, mcols) diff --git a/microdf/tests/test_taxcalc.py b/microdf/tests/test_taxcalc.py deleted file mode 100644 index 96c670b..0000000 --- a/microdf/tests/test_taxcalc.py +++ /dev/null @@ -1,25 +0,0 @@ -import pytest - -import microdf as mdf - -try: - import taxcalc as tc - - _HAVE_TAXCALC = True -except ImportError: - _HAVE_TAXCALC = False - - -def test_calc_df() -> None: - """""" - if not _HAVE_TAXCALC: - pytest.skip("taxcalc is not installed") - mdf.calc_df() - - -def test_static_baseline_calc() -> None: - """""" - if not _HAVE_TAXCALC: - pytest.skip("taxcalc is not installed") - recs = tc.Records.cps_constructor() - mdf.static_baseline_calc(recs, 2020) diff --git a/pyproject.toml b/pyproject.toml index 25fc290..730d755 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,9 +34,6 @@ dev = [ docs = [ "jupyter_book", ] -taxcalc = [ - "taxcalc", -] [tool.setuptools.packages.find] where = ["."] From 88e008781b4f67dc35a7aa613269c5b5685d0171 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Tue, 22 Jul 2025 12:10:57 -0400 Subject: [PATCH 2/3] Add changelog entry and development guidelines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add changelog_entry.yaml for taxcalc removal - Create CLAUDE.md with development guidelines for future work - Ensure files end with newlines to pass lint checks 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- CLAUDE.md | 36 ++++++++++++++++++++++++++++++++++++ changelog_entry.yaml | 6 ++++++ 2 files changed, 42 insertions(+) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..f8c8dec --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,36 @@ +# Claude Development Guidelines for microdf + +## Code Style +- All files must end with a newline character +- Run `make lint` before committing to catch style issues + +## Changelog Requirements +- Every PR must include a `changelog_entry.yaml` file at the root +- Format: + ```yaml + - bump: patch|minor|major + changes: + added|changed|removed|fixed: + - Description of change + ``` +- The file must not be empty and must end with a newline + +## Testing +- Run tests with: `python3 -m pytest microdf/tests/ -v` +- Ensure all tests pass before creating a PR + +## Pull Request Process +1. Create a feature branch from master +2. Make changes and ensure they follow code style guidelines +3. Add a changelog entry +4. Create PR with descriptive title and body +5. PRs should close related issues using "Closes #XXX" in the body + +## Dependencies +- Dependencies are managed in `pyproject.toml` +- Optional dependencies go in `[project.optional-dependencies]` +- When removing dependencies, also remove from `microdf/_optional.py` VERSIONS dict + +## Documentation +- Documentation notebooks are in `docs/` directory +- When removing functionality, consider impact on documentation examples \ No newline at end of file diff --git a/changelog_entry.yaml b/changelog_entry.yaml index e69de29..d745cc5 100644 --- a/changelog_entry.yaml +++ b/changelog_entry.yaml @@ -0,0 +1,6 @@ +- bump: minor + changes: + removed: + - Remove all taxcalc functionality and dependencies from the package. + - Delete taxcalc.py module and associated test file. + - Remove taxcalc from optional dependencies in pyproject.toml. From 227972af1118f7b6a664fcb0bb5e2f058adb77e9 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Tue, 22 Jul 2025 12:13:37 -0400 Subject: [PATCH 3/3] Remove taxcalc-dependent documentation notebooks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove demo.ipynb, custom_taxes.ipynb, agg.ipynb, weighting.ipynb, and income_measures.ipynb - Update _toc.yml to remove references to deleted notebooks - Update changelog entry to document notebook removal These notebooks demonstrated taxcalc integration and are no longer relevant after removing taxcalc functionality. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- changelog_entry.yaml | 1 + docs/_toc.yml | 5 - docs/agg.ipynb | 417 -------------- docs/custom_taxes.ipynb | 1053 ------------------------------------ docs/demo.ipynb | 381 ------------- docs/income_measures.ipynb | 360 ------------ docs/weighting.ipynb | 482 ----------------- 7 files changed, 1 insertion(+), 2698 deletions(-) delete mode 100644 docs/agg.ipynb delete mode 100644 docs/custom_taxes.ipynb delete mode 100644 docs/demo.ipynb delete mode 100644 docs/income_measures.ipynb delete mode 100644 docs/weighting.ipynb diff --git a/changelog_entry.yaml b/changelog_entry.yaml index d745cc5..ce5c4f7 100644 --- a/changelog_entry.yaml +++ b/changelog_entry.yaml @@ -4,3 +4,4 @@ - Remove all taxcalc functionality and dependencies from the package. - Delete taxcalc.py module and associated test file. - Remove taxcalc from optional dependencies in pyproject.toml. + - Remove documentation notebooks that depend on taxcalc functionality. diff --git a/docs/_toc.yml b/docs/_toc.yml index 0ba8408..d7ff41f 100644 --- a/docs/_toc.yml +++ b/docs/_toc.yml @@ -3,9 +3,4 @@ root: home sections: - file: examples sections: - - file: agg - - file: custom_taxes - - file: demo - file: gini - - file: income_measures - - file: weighting diff --git a/docs/agg.ipynb b/docs/agg.ipynb deleted file mode 100644 index 76e250b..0000000 --- a/docs/agg.ipynb +++ /dev/null @@ -1,417 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# The `agg` function\n", - "\n", - "Use `agg` to see the effect of a $10,000 UBI by marital status.\n", - "\n", - "## Setup" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "import numpy as np\n", - "import pandas as pd\n", - "\n", - "import taxcalc as tc\n", - "import microdf as mdf" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'5.0.4'" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "tc.__version__" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Load data\n", - "\n", - "Start with a standard `DataFrame`, then add a UBI manually in a reform copy." - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "base = mdf.calc_df(group_vars=['expanded_income', 'MARS', 'XTOT'],\n", - " metric_vars='aftertax_income')" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], - "source": [ - "reform = base.copy(deep=True)\n", - "UBI_PP = 10000\n", - "reform['ubi'] = reform.XTOT * UBI_PP\n", - "reform['aftertax_income'] = reform.aftertax_income + reform.ubi\n", - "mdf.add_weighted_metrics(reform, 'aftertax_income')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## `agg`\n", - "\n", - "### Change in aftertax income by marital status." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
aftertax_income_m_baseaftertax_income_m_reformaftertax_income_pctchg
MARS
1.04.454948e+065.692781e+060.277856
2.08.086353e+061.007139e+070.245480
3.01.747066e+052.200549e+050.259568
4.01.082960e+061.584130e+060.462778
\n", - "
" - ], - "text/plain": [ - " aftertax_income_m_base aftertax_income_m_reform aftertax_income_pctchg\n", - "MARS \n", - "1.0 4.454948e+06 5.692781e+06 0.277856\n", - "2.0 8.086353e+06 1.007139e+07 0.245480\n", - "3.0 1.747066e+05 2.200549e+05 0.259568\n", - "4.0 1.082960e+06 1.584130e+06 0.462778" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mdf.agg(base, reform, 'MARS', 'aftertax_income')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Also sum baseline `expanded_income`" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
aftertax_income_m_baseexpanded_incomeaftertax_income_m_reformaftertax_income_pctchg
MARS
1.04.454948e+066.176263e+095.692781e+060.277856
2.08.086353e+061.429634e+101.007139e+070.245480
3.01.747066e+052.233541e+082.200549e+050.259568
4.01.082960e+061.362624e+091.584130e+060.462778
\n", - "
" - ], - "text/plain": [ - " aftertax_income_m_base expanded_income aftertax_income_m_reform \\\n", - "MARS \n", - "1.0 4.454948e+06 6.176263e+09 5.692781e+06 \n", - "2.0 8.086353e+06 1.429634e+10 1.007139e+07 \n", - "3.0 1.747066e+05 2.233541e+08 2.200549e+05 \n", - "4.0 1.082960e+06 1.362624e+09 1.584130e+06 \n", - "\n", - " aftertax_income_pctchg \n", - "MARS \n", - "1.0 0.277856 \n", - "2.0 0.245480 \n", - "3.0 0.259568 \n", - "4.0 0.462778 " - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mdf.agg(base, reform, 'MARS', 'aftertax_income', 'expanded_income')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Also sum UBI amount" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
aftertax_income_m_baseaftertax_income_m_reformubi_maftertax_income_pctchg
MARS
1.04.454948e+065.692781e+061.237833e+060.277856
2.08.086353e+061.007139e+071.985039e+060.245480
3.01.747066e+052.200549e+054.534831e+040.259568
4.01.082960e+061.584130e+065.011703e+050.462778
\n", - "
" - ], - "text/plain": [ - " aftertax_income_m_base aftertax_income_m_reform ubi_m \\\n", - "MARS \n", - "1.0 4.454948e+06 5.692781e+06 1.237833e+06 \n", - "2.0 8.086353e+06 1.007139e+07 1.985039e+06 \n", - "3.0 1.747066e+05 2.200549e+05 4.534831e+04 \n", - "4.0 1.082960e+06 1.584130e+06 5.011703e+05 \n", - "\n", - " aftertax_income_pctchg \n", - "MARS \n", - "1.0 0.277856 \n", - "2.0 0.245480 \n", - "3.0 0.259568 \n", - "4.0 0.462778 " - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mdf.add_weighted_metrics(reform, 'ubi') # Creates ubi_m = ubi * s006 / 1e6.\n", - "\n", - "mdf.agg(base, reform, 'MARS', 'aftertax_income', reform_metrics='ubi_m')" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "pe", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.11" - }, - "toc": { - "base_numbering": 1, - "nav_menu": {}, - "number_sections": true, - "sideBar": true, - "skip_h1_title": false, - "title_cell": "Table of Contents", - "title_sidebar": "Contents", - "toc_cell": false, - "toc_position": {}, - "toc_section_display": true, - "toc_window_display": false - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/docs/custom_taxes.ipynb b/docs/custom_taxes.ipynb deleted file mode 100644 index e697e8a..0000000 --- a/docs/custom_taxes.ipynb +++ /dev/null @@ -1,1053 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Custom taxes\n", - "\n", - "## Setup" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "import numpy as np\n", - "import pandas as pd\n", - "\n", - "import taxcalc as tc\n", - "import microdf as mdf" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'5.0.4'" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "tc.__version__" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Load data\n", - "\n", - "Start with a `DataFrame` with `aftertax_income` and necessary ingredients of `tpc_eci`. " - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Index(['mcaid_ben', 'tanf_ben', 'expanded_income', 'XTOT', 'snap_ben', 's006',\n", - " 'vet_ben', 'e02400', 'ssi_ben', 'mcare_ben', 'other_ben', 'housing_ben',\n", - " 'aftertax_income', 'wic_ben', 'e02300', 'market_income', 'bens', 'tax',\n", - " 's006_m', 'XTOT_m'],\n", - " dtype='object')" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df = mdf.calc_df(group_vars=['expanded_income', 'aftertax_income'] +\n", - " mdf.ECI_REMOVE_COLS,\n", - " metric_vars=['XTOT'])\n", - "df.columns" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Calculate Tax Policy Center's Expanded Cash Income measure, used for the analysis." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "df['tpc_eci'] = mdf.tpc_eci(df)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Incidence of a VAT per Tax Policy Center." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Index(['mcaid_ben', 'tanf_ben', 'expanded_income', 'XTOT', 'snap_ben', 's006',\n", - " 'vet_ben', 'e02400', 'ssi_ben', 'mcare_ben', 'other_ben', 'housing_ben',\n", - " 'aftertax_income', 'wic_ben', 'e02300', 'market_income', 'bens', 'tax',\n", - " 's006_m', 'XTOT_m', 'tpc_eci', 'vat'],\n", - " dtype='object')" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mdf.add_vat(df)\n", - "df.columns" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
mcaid_bentanf_benexpanded_incomeXTOTsnap_bens006vet_bene02400ssi_benmcare_ben...aftertax_incomewic_bene02300market_incomebenstaxs006_mXTOT_mtpc_ecivat
RECID
1927220.00.0-303140.1631412.00.0381.900.00.00.00.0...-299540.1631410.00.000000-303140.1631410.000000-3600.00.0003820.000764-303140.1631410.0
1665580.00.0-235938.5424642.00.0501.660.00.00.00.0...-232338.5424640.05188.764042-241127.3065065188.764042-3600.00.0005020.001003-235938.5424640.0
126430.00.0-169432.3255001.00.0414.870.00.00.00.0...-167632.3255000.00.000000-169432.3255000.000000-1800.00.0004150.000415-169432.3255000.0
2621110.00.0-166304.9854752.00.0585.690.00.00.00.0...-162704.9854750.05724.820074-172029.8055495724.820074-3600.00.0005860.001171-166304.9854750.0
127290.00.0-158776.4473201.00.0304.880.00.00.00.0...-156976.4473200.00.000000-158776.4473200.000000-1800.00.0003050.000305-158776.4473200.0
\n", - "

5 rows × 22 columns

\n", - "
" - ], - "text/plain": [ - " mcaid_ben tanf_ben expanded_income XTOT snap_ben s006 vet_ben \\\n", - "RECID \n", - "192722 0.0 0.0 -303140.163141 2.0 0.0 381.90 0.0 \n", - "166558 0.0 0.0 -235938.542464 2.0 0.0 501.66 0.0 \n", - "12643 0.0 0.0 -169432.325500 1.0 0.0 414.87 0.0 \n", - "262111 0.0 0.0 -166304.985475 2.0 0.0 585.69 0.0 \n", - "12729 0.0 0.0 -158776.447320 1.0 0.0 304.88 0.0 \n", - "\n", - " e02400 ssi_ben mcare_ben ... aftertax_income wic_ben \\\n", - "RECID ... \n", - "192722 0.0 0.0 0.0 ... -299540.163141 0.0 \n", - "166558 0.0 0.0 0.0 ... -232338.542464 0.0 \n", - "12643 0.0 0.0 0.0 ... -167632.325500 0.0 \n", - "262111 0.0 0.0 0.0 ... -162704.985475 0.0 \n", - "12729 0.0 0.0 0.0 ... -156976.447320 0.0 \n", - "\n", - " e02300 market_income bens tax s006_m XTOT_m \\\n", - "RECID \n", - "192722 0.000000 -303140.163141 0.000000 -3600.0 0.000382 0.000764 \n", - "166558 5188.764042 -241127.306506 5188.764042 -3600.0 0.000502 0.001003 \n", - "12643 0.000000 -169432.325500 0.000000 -1800.0 0.000415 0.000415 \n", - "262111 5724.820074 -172029.805549 5724.820074 -3600.0 0.000586 0.001171 \n", - "12729 0.000000 -158776.447320 0.000000 -1800.0 0.000305 0.000305 \n", - "\n", - " tpc_eci vat \n", - "RECID \n", - "192722 -303140.163141 0.0 \n", - "166558 -235938.542464 0.0 \n", - "12643 -169432.325500 0.0 \n", - "262111 -166304.985475 0.0 \n", - "12729 -158776.447320 0.0 \n", - "\n", - "[5 rows x 22 columns]" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.head() # Note these are zero because we block negative tax liability." - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
mcaid_bentanf_benexpanded_incomeXTOTsnap_bens006vet_bene02400ssi_benmcare_ben...aftertax_incomewic_bene02300market_incomebenstaxs006_mXTOT_mtpc_ecivat
RECID
1212690.0000000.091950.8791542.00.0000001030.130.039477.8510828136.35625414469.708379...91695.5243840.00.00000024687.94223767262.936917255.3547700.0010300.00206077481.1707753301.038878
1133798801.5619110.013400.3158171.00.0000001260.650.00.0000000.0000000.000000...15200.3158170.00.0000000.00000013400.315817-1800.0000000.0012610.0012614598.753905592.812317
2637250.0000000.0130030.1518882.00.000000408.480.059718.5628130.00000028940.650007...132584.4973930.00.00000041370.93906988659.212820-2554.3455050.0004080.000817101089.5018824507.872911
503998801.5619110.032464.6545582.00.000000457.480.00.0000000.0000000.000000...38029.6713970.02748.09447416316.24426816148.410290-5565.0168390.0004570.00091523663.0926471369.068170
2205480.0000000.025110.7112171.03234.713349581.980.05513.6419490.00000014469.708379...26910.7112170.00.0000000.00000025110.711217-1800.0000000.0005820.00058210641.0028381049.517737
\n", - "

5 rows × 22 columns

\n", - "
" - ], - "text/plain": [ - " mcaid_ben tanf_ben expanded_income XTOT snap_ben s006 \\\n", - "RECID \n", - "121269 0.000000 0.0 91950.879154 2.0 0.000000 1030.13 \n", - "113379 8801.561911 0.0 13400.315817 1.0 0.000000 1260.65 \n", - "263725 0.000000 0.0 130030.151888 2.0 0.000000 408.48 \n", - "50399 8801.561911 0.0 32464.654558 2.0 0.000000 457.48 \n", - "220548 0.000000 0.0 25110.711217 1.0 3234.713349 581.98 \n", - "\n", - " vet_ben e02400 ssi_ben mcare_ben ... \\\n", - "RECID ... \n", - "121269 0.0 39477.851082 8136.356254 14469.708379 ... \n", - "113379 0.0 0.000000 0.000000 0.000000 ... \n", - "263725 0.0 59718.562813 0.000000 28940.650007 ... \n", - "50399 0.0 0.000000 0.000000 0.000000 ... \n", - "220548 0.0 5513.641949 0.000000 14469.708379 ... \n", - "\n", - " aftertax_income wic_ben e02300 market_income bens \\\n", - "RECID \n", - "121269 91695.524384 0.0 0.000000 24687.942237 67262.936917 \n", - "113379 15200.315817 0.0 0.000000 0.000000 13400.315817 \n", - "263725 132584.497393 0.0 0.000000 41370.939069 88659.212820 \n", - "50399 38029.671397 0.0 2748.094474 16316.244268 16148.410290 \n", - "220548 26910.711217 0.0 0.000000 0.000000 25110.711217 \n", - "\n", - " tax s006_m XTOT_m tpc_eci vat \n", - "RECID \n", - "121269 255.354770 0.001030 0.002060 77481.170775 3301.038878 \n", - "113379 -1800.000000 0.001261 0.001261 4598.753905 592.812317 \n", - "263725 -2554.345505 0.000408 0.000817 101089.501882 4507.872911 \n", - "50399 -5565.016839 0.000457 0.000915 23663.092647 1369.068170 \n", - "220548 -1800.000000 0.000582 0.000582 10641.002838 1049.517737 \n", - "\n", - "[5 rows x 22 columns]" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.sample(5)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Add carbon tax and financial transaction tax." - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Index(['mcaid_ben', 'tanf_ben', 'expanded_income', 'XTOT', 'snap_ben', 's006',\n", - " 'vet_ben', 'e02400', 'ssi_ben', 'mcare_ben', 'other_ben', 'housing_ben',\n", - " 'aftertax_income', 'wic_ben', 'e02300', 'market_income', 'bens', 'tax',\n", - " 's006_m', 'XTOT_m', 'tpc_eci', 'vat', 'carbon_tax', 'ftt'],\n", - " dtype='object')" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mdf.add_carbon_tax(df)\n", - "mdf.add_ftt(df)\n", - "df.columns" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
mcaid_bentanf_benexpanded_incomeXTOTsnap_bens006vet_bene02400ssi_benmcare_ben...e02300market_incomebenstaxs006_mXTOT_mtpc_ecivatcarbon_taxftt
RECID
906620.0000000.028793.1501701.00.000000549.210.00.0000000.000000.000000...0.02.879315e+040.0000003563.9373740.0005490.00054928793.150170908.251661353.20897925.229213
659448801.5619110.053460.3137141.0434.350848487.520.011987.1752182992.9594514469.708379...0.0-7.275958e-1253460.313714-1800.0000000.0004880.00048822172.9726102155.152235663.12376555.260314
711660.0000000.032369.9517712.00.000000706.990.00.0000000.000000.000000...0.03.236995e+040.000000-2521.0893620.0007070.00141432369.9517711256.077481488.47457634.891041
23930.0000000.031734.5314311.00.000000220.260.016905.6627090.0000014469.708379...0.03.591603e+0231375.371088-1800.0000000.0002200.00022017264.8230521307.846726402.41437733.534531
107310.0000000.0131398.2378942.00.000000458.540.072074.8429990.0000028940.650007...0.03.038274e+04101015.493006-3600.0000000.0004590.000917102457.5878874589.9400882429.968282269.996476
\n", - "

5 rows × 24 columns

\n", - "
" - ], - "text/plain": [ - " mcaid_ben tanf_ben expanded_income XTOT snap_ben s006 \\\n", - "RECID \n", - "90662 0.000000 0.0 28793.150170 1.0 0.000000 549.21 \n", - "65944 8801.561911 0.0 53460.313714 1.0 434.350848 487.52 \n", - "71166 0.000000 0.0 32369.951771 2.0 0.000000 706.99 \n", - "2393 0.000000 0.0 31734.531431 1.0 0.000000 220.26 \n", - "10731 0.000000 0.0 131398.237894 2.0 0.000000 458.54 \n", - "\n", - " vet_ben e02400 ssi_ben mcare_ben ... e02300 \\\n", - "RECID ... \n", - "90662 0.0 0.000000 0.00000 0.000000 ... 0.0 \n", - "65944 0.0 11987.175218 2992.95945 14469.708379 ... 0.0 \n", - "71166 0.0 0.000000 0.00000 0.000000 ... 0.0 \n", - "2393 0.0 16905.662709 0.00000 14469.708379 ... 0.0 \n", - "10731 0.0 72074.842999 0.00000 28940.650007 ... 0.0 \n", - "\n", - " market_income bens tax s006_m XTOT_m \\\n", - "RECID \n", - "90662 2.879315e+04 0.000000 3563.937374 0.000549 0.000549 \n", - "65944 -7.275958e-12 53460.313714 -1800.000000 0.000488 0.000488 \n", - "71166 3.236995e+04 0.000000 -2521.089362 0.000707 0.001414 \n", - "2393 3.591603e+02 31375.371088 -1800.000000 0.000220 0.000220 \n", - "10731 3.038274e+04 101015.493006 -3600.000000 0.000459 0.000917 \n", - "\n", - " tpc_eci vat carbon_tax ftt \n", - "RECID \n", - "90662 28793.150170 908.251661 353.208979 25.229213 \n", - "65944 22172.972610 2155.152235 663.123765 55.260314 \n", - "71166 32369.951771 1256.077481 488.474576 34.891041 \n", - "2393 17264.823052 1307.846726 402.414377 33.534531 \n", - "10731 102457.587887 4589.940088 2429.968282 269.996476 \n", - "\n", - "[5 rows x 24 columns]" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.sample(5)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "VAT with a custom amount generated." - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Multiplying tax by 1.08.\n" - ] - }, - { - "data": { - "text/plain": [ - "Index(['mcaid_ben', 'tanf_ben', 'expanded_income', 'XTOT', 'snap_ben', 's006',\n", - " 'vet_ben', 'e02400', 'ssi_ben', 'mcare_ben', 'other_ben', 'housing_ben',\n", - " 'aftertax_income', 'wic_ben', 'e02300', 'market_income', 'bens', 'tax',\n", - " 's006_m', 'XTOT_m', 'tpc_eci', 'vat', 'carbon_tax', 'ftt', 'vat2'],\n", - " dtype='object')" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mdf.add_vat(df, total=500e9, name='vat2')\n", - "df.columns" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "464.5240745518526" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mdf.weighted_sum(df, 'vat', 's006') / 1e9" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "500.0000000000001" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mdf.weighted_sum(df, 'vat2', 's006') / 1e9" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Calculate by hand using `add_custom_tax`." - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Multiplying tax by 2.15.\n" - ] - } - ], - "source": [ - "mdf.add_custom_tax(df, 'tpc_eci', 'XTOT_m', 'aftertax_income', \n", - " mdf.VAT_INCIDENCE, 'vat3', 1e12)" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "1000.0000000000002" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mdf.weighted_sum(df, 'vat3', 's006') / 1e9" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "pe", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.11" - }, - "toc": { - "base_numbering": 1, - "nav_menu": {}, - "number_sections": true, - "sideBar": true, - "skip_h1_title": false, - "title_cell": "Table of Contents", - "title_sidebar": "Contents", - "toc_cell": false, - "toc_position": {}, - "toc_section_display": true, - "toc_window_display": false - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/docs/demo.ipynb b/docs/demo.ipynb deleted file mode 100644 index b9d10f1..0000000 --- a/docs/demo.ipynb +++ /dev/null @@ -1,381 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# `microdf` demo" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Setup" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import numpy as np\n", - "import pandas as pd\n", - "\n", - "import taxcalc as tc\n", - "import microdf as mdf" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Generate data" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "base = mdf.calc_df(group_vars=['expanded_income', 'MARS'],\n", - " metric_vars=['aftertax_income', 'XTOT'])" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Index(['vet_ben', 's006', 'tanf_ben', 'e02400', 'expanded_income', 'ssi_ben',\n", - " 'wic_ben', 'aftertax_income', 'housing_ben', 'e02300', 'mcare_ben',\n", - " 'XTOT', 'snap_ben', 'MARS', 'other_ben', 'mcaid_ben', 'market_income',\n", - " 'bens', 'tax', 's006_m', 'XTOT_m', 'aftertax_income_m'],\n", - " dtype='object')" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "base.columns" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Define a reform that treats capital gains as ordinary income and sets the top marginal rate to 70%." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], - "source": [ - "CG_REFORM = {\n", - " 'CG_nodiff': {2019: True},\n", - " 'II_rt7': {2019: 0.7}\n", - "}" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "reform = mdf.calc_df(reform=CG_REFORM, group_vars=['MARS'], group_n65=True, \n", - " metric_vars=['aftertax_income', 'XTOT'])" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Index(['s006', 'ssi_ben', 'e02300', 'aftertax_income', 'mcare_ben',\n", - " 'expanded_income', 'wic_ben', 'XTOT', 'MARS', 'mcaid_ben', 'vet_ben',\n", - " 'tanf_ben', 'e02400', 'housing_ben', 'snap_ben', 'other_ben',\n", - " 'market_income', 'bens', 'tax', 'n65', 's006_m', 'XTOT_m',\n", - " 'aftertax_income_m'],\n", - " dtype='object')" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "reform.columns" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Calculate senior UBI.\n", - "\n", - "Start with total revenue ($ billions)." - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "337.44427805705" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "new_rev_m = base.aftertax_income_m.sum() - reform.aftertax_income_m.sum()\n", - "new_rev_m / 1e3" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "How many seniors are there?" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "60.66105169000002" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mdf.add_weighted_metrics(reform, 'n65')\n", - "\n", - "n65_total_m = reform.n65_m.sum()\n", - "n65_total_m" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Divide." - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "5562.7831805738" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "senior_ubi = new_rev_m / reform.n65_m.sum()\n", - "senior_ubi" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Add senior UBI to `aftertax_income` and recalculate" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [], - "source": [ - "reform['ubi'] = senior_ubi * reform.n65\n", - "reform['aftertax_income'] = reform.aftertax_income + reform.ubi\n", - "mdf.add_weighted_metrics(reform, 'aftertax_income')" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "np.allclose(base.aftertax_income_m.sum(), reform.aftertax_income_m.sum())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Analyze\n", - "\n", - "Gini, FPL, distributional impact chart\n", - "\n", - "### Change to Gini index" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "0.4810691765589658" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mdf.gini(base, 'aftertax_income', 's006')" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "0.464648453442316" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mdf.gini(reform, 'aftertax_income', 's006')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Change to poverty rate\n", - "\n", - "Add federal poverty line with `mdf.fpl`." - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [], - "source": [ - "base['fpl'] = mdf.fpl(base.XTOT)\n", - "reform['fpl'] = mdf.fpl(reform.XTOT)\n", - "\n", - "base['fpl_XTOT_m'] = np.where(base.aftertax_income < base.fpl,\n", - " base.XTOT_m, 0)\n", - "reform['fpl_XTOT_m'] = np.where(reform.aftertax_income < reform.fpl,\n", - " reform.XTOT_m, 0)" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "-0.04505398741648947" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "reform.fpl_XTOT_m.sum() / base.fpl_XTOT_m.sum() - 1" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "pe", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.11" - }, - "toc": { - "base_numbering": 1, - "nav_menu": {}, - "number_sections": true, - "sideBar": true, - "skip_h1_title": false, - "title_cell": "Table of Contents", - "title_sidebar": "Contents", - "toc_cell": false, - "toc_position": {}, - "toc_section_display": true, - "toc_window_display": false - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/docs/income_measures.ipynb b/docs/income_measures.ipynb deleted file mode 100644 index 65e7339..0000000 --- a/docs/income_measures.ipynb +++ /dev/null @@ -1,360 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Income measures\n", - "\n", - "## Setup" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "import numpy as np\n", - "import pandas as pd\n", - "\n", - "import taxcalc as tc\n", - "import microdf as mdf" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'2.3.0'" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "tc.__version__" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Load data\n", - "\n", - "Start with a `DataFrame` with `expanded_income` and the variables in `expanded_income` excluded from `tpc_eci`." - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [], - "source": [ - "df = mdf.calc_df(group_vars=['expanded_income', 'wic_ben', 'housing_ben', \n", - " 'vet_ben', 'mcare_ben', 'mcaid_ben'],\n", - " metric_vars=['XTOT'])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Calculate `tpc_eci`." - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [], - "source": [ - "df['tpc_eci'] = mdf.tpc_eci(df)" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
snap_benvet_benmcaid_benmcare_benaftertax_incomee02300ssi_benwic_bens006expanded_income...tanf_benother_bene02400XTOTmarket_incomebenstaxs006_mXTOT_mtpc_eci
RECID
10.000000.00.0000000.00000043371.0125040.00.000000.0250.1453636.919015...0.00.0000000.0000002.053636.9190150.00000010265.9065110.0002500.00050053636.919015
20.000000.00.0000000.00000020937.8865110.00.000000.0211.6318650.034959...0.00.0000000.0000003.018650.0349590.000000-2287.8515530.0002120.00063518650.034959
31734.129390.08211.59362713640.39061252516.1653970.03374.522390.0323.5052516.165397...0.06663.70162313227.0798161.00.00000052516.1653970.0000000.0003240.00032424999.433219
40.000000.08211.5936270.00000036857.7091880.00.000000.0186.3237764.286717...0.03906.5423680.0000002.025646.15072312118.135995906.5775290.0001860.00037329552.693091
50.000000.00.00000027280.78122363941.1582830.00.000000.0343.0863941.158283...0.00.00000035560.5532862.01099.82377462841.3345090.0000000.0003430.00068636660.377060
\n", - "

5 rows × 21 columns

\n", - "
" - ], - "text/plain": [ - " snap_ben vet_ben mcaid_ben mcare_ben aftertax_income \\\n", - "RECID \n", - "1 0.00000 0.0 0.000000 0.000000 43371.012504 \n", - "2 0.00000 0.0 0.000000 0.000000 20937.886511 \n", - "3 1734.12939 0.0 8211.593627 13640.390612 52516.165397 \n", - "4 0.00000 0.0 8211.593627 0.000000 36857.709188 \n", - "5 0.00000 0.0 0.000000 27280.781223 63941.158283 \n", - "\n", - " e02300 ssi_ben wic_ben s006 expanded_income ... tanf_ben \\\n", - "RECID ... \n", - "1 0.0 0.00000 0.0 250.14 53636.919015 ... 0.0 \n", - "2 0.0 0.00000 0.0 211.63 18650.034959 ... 0.0 \n", - "3 0.0 3374.52239 0.0 323.50 52516.165397 ... 0.0 \n", - "4 0.0 0.00000 0.0 186.32 37764.286717 ... 0.0 \n", - "5 0.0 0.00000 0.0 343.08 63941.158283 ... 0.0 \n", - "\n", - " other_ben e02400 XTOT market_income bens \\\n", - "RECID \n", - "1 0.000000 0.000000 2.0 53636.919015 0.000000 \n", - "2 0.000000 0.000000 3.0 18650.034959 0.000000 \n", - "3 6663.701623 13227.079816 1.0 0.000000 52516.165397 \n", - "4 3906.542368 0.000000 2.0 25646.150723 12118.135995 \n", - "5 0.000000 35560.553286 2.0 1099.823774 62841.334509 \n", - "\n", - " tax s006_m XTOT_m tpc_eci \n", - "RECID \n", - "1 10265.906511 0.000250 0.000500 53636.919015 \n", - "2 -2287.851553 0.000212 0.000635 18650.034959 \n", - "3 0.000000 0.000324 0.000324 24999.433219 \n", - "4 906.577529 0.000186 0.000373 29552.693091 \n", - "5 0.000000 0.000343 0.000686 36660.377060 \n", - "\n", - "[5 rows x 21 columns]" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.head()" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.3" - }, - "toc": { - "base_numbering": 1, - "nav_menu": {}, - "number_sections": true, - "sideBar": true, - "skip_h1_title": false, - "title_cell": "Table of Contents", - "title_sidebar": "Contents", - "toc_cell": false, - "toc_position": {}, - "toc_section_display": true, - "toc_window_display": false - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/docs/weighting.ipynb b/docs/weighting.ipynb deleted file mode 100644 index e7c71b7..0000000 --- a/docs/weighting.ipynb +++ /dev/null @@ -1,482 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Weighting in taxcalc_helpers\n", - "\n", - "## Setup" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "import numpy as np\n", - "import pandas as pd\n", - "\n", - "import taxcalc as tc\n", - "import microdf as mdf" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'3.0.0'" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "tc.__version__" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Load data\n", - "\n", - "Start with a `DataFrame` with `nu18` and `XTOT`, and also calculate `XTOT_m`." - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Index(['s006', 'other_ben', 'snap_ben', 'aftertax_income', 'mcaid_ben',\n", - " 'mcare_ben', 'ssi_ben', 'e02300', 'nu18', 'expanded_income',\n", - " 'housing_ben', 'vet_ben', 'wic_ben', 'e02400', 'tanf_ben', 'XTOT',\n", - " 'market_income', 'bens', 'tax', 's006_m', 'XTOT_m'],\n", - " dtype='object')" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df = mdf.calc_df(group_vars=['nu18'], metric_vars=['XTOT'])\n", - "df.columns" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "From this we can calculate the number of people and tax units by the tax unit's number of children." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
s006_mXTOT_m
nu18
0.0152.988772209.816367
1.022.68825354.115850
2.018.85994568.880292
3.07.43848134.795527
4.02.37111113.539261
5.00.7442765.015182
6.00.2161581.688063
7.00.0903320.790239
8.00.0265010.258552
9.00.0122380.134320
10.00.0071960.084201
12.00.0002650.003715
\n", - "
" - ], - "text/plain": [ - " s006_m XTOT_m\n", - "nu18 \n", - "0.0 152.988772 209.816367\n", - "1.0 22.688253 54.115850\n", - "2.0 18.859945 68.880292\n", - "3.0 7.438481 34.795527\n", - "4.0 2.371111 13.539261\n", - "5.0 0.744276 5.015182\n", - "6.0 0.216158 1.688063\n", - "7.0 0.090332 0.790239\n", - "8.0 0.026501 0.258552\n", - "9.0 0.012238 0.134320\n", - "10.0 0.007196 0.084201\n", - "12.0 0.000265 0.003715" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.groupby('nu18')[['s006_m', 'XTOT_m']].sum()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "What if we also want to calculate the total number of *children* by the tax unit's number of children?\n", - "\n", - "For this we can use `add_weighted_metrics`, the function called within `calc_df`." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "mdf.add_weighted_metrics(df, ['nu18'])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now we can do the same thing as before, with the new `nu18_m` column." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
nu18_m
nu18
0.00.000000
1.022.688253
2.037.719889
3.022.315444
4.09.484444
5.03.721381
6.01.296949
7.00.632325
8.00.212008
9.00.110139
10.00.071958
12.00.003184
\n", - "
" - ], - "text/plain": [ - " nu18_m\n", - "nu18 \n", - "0.0 0.000000\n", - "1.0 22.688253\n", - "2.0 37.719889\n", - "3.0 22.315444\n", - "4.0 9.484444\n", - "5.0 3.721381\n", - "6.0 1.296949\n", - "7.0 0.632325\n", - "8.0 0.212008\n", - "9.0 0.110139\n", - "10.0 0.071958\n", - "12.0 0.003184" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.groupby('nu18')[['nu18_m']].sum()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can also calculate weighted sums without adding the weighted metric." - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Total children: 98M.'" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "total_children = mdf.weighted_sum(df, 'nu18', 's006')\n", - "# Fix this decimal.\n", - "'Total children: ' + str(round(total_children / 1e6)) + 'M.'" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can also calculate the weighted mean and median." - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "0.4782626894263673" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mdf.weighted_mean(df, 'nu18', 's006')" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "ename": "TypeError", - "evalue": "weighted_quantile() missing 1 required positional argument: 'quantiles'", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mweighted_median\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'nu18'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m's006'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/microdf/weighted.py\u001b[0m in \u001b[0;36mweighted_median\u001b[0;34m(df, col, w)\u001b[0m\n\u001b[1;32m 84\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 85\u001b[0m \"\"\"\n\u001b[0;32m---> 86\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mweighted_quantile\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mcol\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m0.5\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mw\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 87\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 88\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mTypeError\u001b[0m: weighted_quantile() missing 1 required positional argument: 'quantiles'" - ] - } - ], - "source": [ - "mdf.weighted_median(df, 'nu18', 's006')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can also look at more quantiles.\n", - "\n", - "*Note that weighted quantiles have a different interface.*" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "decile_bounds = np.arange(0, 1.1, 0.1)\n", - "deciles = mdf.weighted_quantile(df, 'nu18', 's006', decile_bounds)\n", - "pd.DataFrame(deciles, index=decile_bounds)" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.9" - }, - "toc": { - "base_numbering": 1, - "nav_menu": {}, - "number_sections": true, - "sideBar": true, - "skip_h1_title": false, - "title_cell": "Table of Contents", - "title_sidebar": "Contents", - "toc_cell": false, - "toc_position": {}, - "toc_section_display": true, - "toc_window_display": false - } - }, - "nbformat": 4, - "nbformat_minor": 2 -}