Repository: pwwang/datar Branch: master Commit: e4a9f8860a90 Files: 149 Total size: 2.9 MB Directory structure: gitextract_ikaf322n/ ├── .codesandbox/ │ ├── Dockerfile │ └── setup.sh ├── .coveragerc ├── .github/ │ ├── ISSUE_TEMPLATE/ │ │ ├── bug_report.yml │ │ ├── feature_request.yml │ │ └── submit_question.yml │ └── workflows/ │ ├── ci.yml │ └── docs.yml ├── .gitignore ├── .pre-commit-config.yaml ├── LICENSE ├── README.md ├── datar/ │ ├── __init__.py │ ├── all.py │ ├── apis/ │ │ ├── __init__.py │ │ ├── base.py │ │ ├── dplyr.py │ │ ├── forcats.py │ │ ├── misc.py │ │ ├── tibble.py │ │ └── tidyr.py │ ├── base.py │ ├── core/ │ │ ├── __init__.py │ │ ├── defaults.py │ │ ├── load_plugins.py │ │ ├── names.py │ │ ├── operator.py │ │ ├── options.py │ │ ├── plugin.py │ │ ├── utils.py │ │ └── verb_env.py │ ├── data/ │ │ ├── __init__.py │ │ └── metadata.py │ ├── datasets.py │ ├── dplyr.py │ ├── forcats.py │ ├── misc.py │ ├── tibble.py │ └── tidyr.py ├── docs/ │ ├── CHANGELOG.md │ ├── ENV_VARS.md │ ├── backends.md │ ├── data.md │ ├── f.md │ ├── import.md │ ├── notebooks/ │ │ ├── across.ipynb │ │ ├── add_column.ipynb │ │ ├── add_row.ipynb │ │ ├── arrange.ipynb │ │ ├── base-arithmetic.ipynb │ │ ├── base-funs.ipynb │ │ ├── base.ipynb │ │ ├── between.ipynb │ │ ├── bind.ipynb │ │ ├── case_when.ipynb │ │ ├── chop.ipynb │ │ ├── coalesce.ipynb │ │ ├── complete.ipynb │ │ ├── context.ipynb │ │ ├── count.ipynb │ │ ├── cumall.ipynb │ │ ├── desc.ipynb │ │ ├── distinct.ipynb │ │ ├── drop_na.ipynb │ │ ├── enframe.ipynb │ │ ├── expand.ipynb │ │ ├── expand_grid.ipynb │ │ ├── extract.ipynb │ │ ├── fill.ipynb │ │ ├── filter-joins.ipynb │ │ ├── filter.ipynb │ │ ├── forcats_fct_multi.ipynb │ │ ├── forcats_lvl_addrm.ipynb │ │ ├── forcats_lvl_order.ipynb │ │ ├── forcats_lvl_value.ipynb │ │ ├── forcats_misc.ipynb │ │ ├── full_seq.ipynb │ │ ├── group_by.ipynb │ │ ├── group_map.ipynb │ │ ├── group_split.ipynb │ │ ├── group_trim.ipynb │ │ ├── lead-lag.ipynb │ │ ├── mutate-joins.ipynb │ │ ├── mutate.ipynb │ │ ├── n_distinct.ipynb │ │ ├── na_if.ipynb │ │ ├── nb_helpers.py │ │ ├── near.ipynb │ │ ├── nest-join.ipynb │ │ ├── nest.ipynb │ │ ├── nth.ipynb │ │ ├── other.ipynb │ │ ├── pack.ipynb │ │ ├── pivot_longer.ipynb │ │ ├── pivot_wider.ipynb │ │ ├── pull.ipynb │ │ ├── ranking.ipynb │ │ ├── readme.ipynb │ │ ├── recode.ipynb │ │ ├── reframe.ipynb │ │ ├── relocate.ipynb │ │ ├── rename.ipynb │ │ ├── replace_na.ipynb │ │ ├── rownames.ipynb │ │ ├── rows.ipynb │ │ ├── rowwise.ipynb │ │ ├── select.ipynb │ │ ├── separate.ipynb │ │ ├── setops.ipynb │ │ ├── slice.ipynb │ │ ├── summarise.ipynb │ │ ├── tibble.ipynb │ │ ├── uncount.ipynb │ │ ├── unite.ipynb │ │ └── with_groups.ipynb │ ├── options.md │ ├── reference-maps/ │ │ ├── ALL.md │ │ ├── base.md │ │ ├── datasets.md │ │ ├── dplyr.md │ │ ├── forcats.md │ │ ├── other.md │ │ ├── stats.md │ │ ├── tibble.md │ │ ├── tidyr.md │ │ └── utils.md │ └── style.css ├── mkdocs.yml ├── pyproject.toml ├── setup.py ├── tests/ │ ├── __init__.py │ ├── conflict_names.py │ ├── conftest.py │ ├── test_array_ufunc.py │ ├── test_base.py │ ├── test_conflict_names.py │ ├── test_data.py │ ├── test_dplyr.py │ ├── test_forcats.py │ ├── test_names.py │ ├── test_options.py │ ├── test_pipe.py │ ├── test_plugin.py │ ├── test_tibble.py │ ├── test_tidyr.py │ ├── test_utils.py │ ├── test_verb_env.py │ └── test_verb_env_integration.py └── tox.ini ================================================ FILE CONTENTS ================================================ ================================================ FILE: .codesandbox/Dockerfile ================================================ FROM python:3.10.12 RUN apt-get update && apt-get install -y npm fish && \ pip install -U pip && \ pip install poetry && \ poetry config virtualenvs.create false && \ chsh -s /usr/bin/fish ================================================ FILE: .codesandbox/setup.sh ================================================ WORKSPACE="/workspace" # Install python dependencies poetry update && poetry install cd $WORKSPACE # Install whichpy WHICHPY="https://gist.githubusercontent.com/pwwang/879966128b0408c2459eb0a0b413fa69/raw/2f2573d191edec1937a2bf0873aa33a646b5ef29/whichpy.fish" curl -sS $WHICHPY -o ~/.config/fish/functions/whichpy.fish ================================================ FILE: .coveragerc ================================================ [report] exclude_lines = pragma: no cover if TYPE_CHECKING: omit = datar/datasets.py */site-packages/* ================================================ FILE: .github/ISSUE_TEMPLATE/bug_report.yml ================================================ name: Bug Report description: Report incorrect behavior in the datar library title: "[BUG] " labels: [bug] body: - type: checkboxes id: checks attributes: label: datar version checks options: - label: > I have checked that this issue has not already been reported. required: true - label: > I have confirmed this bug exists on the **latest version** of datar and its backends. required: true - type: textarea id: problem attributes: label: Issue Description description: > Please provide a description of the issue shown in the reproducible example. validations: required: true - type: textarea id: expected-behavior attributes: label: Expected Behavior description: > Please describe or show a code example of the expected behavior. validations: required: true - type: textarea id: version attributes: label: Installed Versions description: > Please paste the output of ``datar.get_versions()`` value: >
Replace this line with the output of datar.get_versions()
validations: required: true ================================================ FILE: .github/ISSUE_TEMPLATE/feature_request.yml ================================================ name: Feature Request description: Suggest an idea for datar title: "[ENH] " labels: [enhancement] body: - type: checkboxes id: checks attributes: label: Feature Type description: Please check what type of feature request you would like to propose. options: - label: > Adding new functionality to datar - label: > Changing existing functionality in datar - label: > Removing existing functionality in datar - type: textarea id: description attributes: label: Problem Description description: > Please describe what problem the feature would solve, e.g. "I wish I could use datar to ..." placeholder: > I wish I could use datar to port the purrr package from R. validations: required: true - type: textarea id: feature attributes: label: Feature Description description: > Please describe how the new feature would be implemented, using psudocode if relevant. placeholder: > Add a new module `datar.purrr` with functions `map`, `map2`, `map_df`, etc. validations: required: true - type: textarea id: context attributes: label: Additional Context description: > Please provide any relevant GitHub issues, code examples or references that help describe and support the feature request. ================================================ FILE: .github/ISSUE_TEMPLATE/submit_question.yml ================================================ name: Submit Question description: Ask a general question about datar title: "[QST] " labels: [question] body: - type: textarea id: question attributes: label: Question about datar description: > Try to provide a clear and concise description of your question. placeholder: | ```python # Your code here, if applicable ``` ================================================ FILE: .github/workflows/ci.yml ================================================ name: CI on: push: pull_request: release: types: [published] jobs: build: runs-on: ubuntu-latest strategy: matrix: python-version: [3.9, "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v6 - name: Install uv uses: astral-sh/setup-uv@v8.0.0 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: uv sync - name: Run flake8 run: uv run flake8 datar - name: Test with pytest run: uv run pytest tests/ --junitxml=junit/test-results-${{ matrix.python-version }}.xml - name: Upload pytest test results uses: actions/upload-artifact@v7 with: name: pytest-results-${{ matrix.python-version }} path: junit/test-results-${{ matrix.python-version }}.xml # Use always() to always run this step to publish test results when there are test failures if: ${{ always() }} - name: Run codacy-coverage-reporter uses: codacy/codacy-coverage-reporter-action@master if: matrix.python-version == 3.12 with: project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} coverage-reports: cov.xml deploy: needs: build runs-on: ubuntu-latest if: github.event_name == 'release' strategy: matrix: python-version: ["3.12"] steps: - uses: actions/checkout@v6 - name: Install uv uses: astral-sh/setup-uv@v8.0.0 with: python-version: ${{ matrix.python-version }} - name: Build and publish to PyPI run: | uv build uv publish --username ${{ secrets.PYPI_USER }} --password ${{ secrets.PYPI_PASSWORD }} if: success() ================================================ FILE: .github/workflows/docs.yml ================================================ name: Build Docs on: [push] jobs: docs: runs-on: ubuntu-latest # if: github.ref == 'refs/heads/master' strategy: matrix: python-version: ["3.12"] steps: - uses: actions/checkout@v4 - name: Install uv uses: astral-sh/setup-uv@v5 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: uv sync --group docs - name: Build docs run: | # python -m pip install -r docs/requirements.txt uv run python -m ipykernel install --user --name python --display-name python uv run python -m ipykernel install --user --name python3 --display-name python3 cd docs cp ../README.md index.md cp ../example.png example.png cp ../example2.png example2.png # cp ../logo.png logo.png cd .. uv run mkdocs build if : success() - name: Deploy docs run: | uv run mkdocs gh-deploy --clean --force # if: success() && github.ref == 'refs/heads/master' fix-index: needs: docs runs-on: ubuntu-latest # if: github.ref == 'refs/heads/master' strategy: matrix: python-version: ["3.12"] steps: - uses: actions/checkout@v4 with: ref: gh-pages - name: Fix index.html run: | echo ':: head of index.html - before ::' head index.html sed -i '1,5{/^$/d}' index.html echo ':: head of index.html - after ::' head index.html if: success() - name: Commit changes run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" git commit -m "Add changes" -a if: success() - name: Push changes uses: ad-m/github-push-action@master with: github_token: ${{ secrets.GITHUB_TOKEN }} branch: gh-pages if: success() ================================================ FILE: .gitignore ================================================ # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C extensions *.so # Distribution / packaging .Python env/ build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ *.egg-info/ .installed.cfg *.egg # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .coverage .coverage.* .cache nosetests.xml coverage.xml .coverage.xml cov.xml *,cover .hypothesis/ # Translations *.mo *.pot # Django stuff: *.log local_settings.py # Flask stuff: instance/ .webassets-cache # Scrapy stuff: .scrapy # Sphinx documentation docs/_build/ # PyBuilder target/ # IPython Notebook .ipynb_checkpoints # pyenv .python-version # celery beat schedule file celerybeat-schedule # dotenv .env # virtualenv venv/ ENV/ # Spyder project settings .spyderproject # Rope project settings .ropeproject workdir/ node_modules/ _book/ .vscode export/ *.svg *.dot *.queue.txt site/ # poetry # poetry.lock # backup files *.bak docs/index.md docs/logo.png docs/example.png docs/example2.png docs/api/ docs/*.nbconvert.ipynb docs/*/*.nbconvert.ipynb # vscode's local history extension .history/ # For quick test /_t.py /_t.ipynb ================================================ FILE: .pre-commit-config.yaml ================================================ fail_fast: true repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: 5df1a4bf6f04a1ed3a643167b38d502575e29aef hooks: - id: trailing-whitespace - id: end-of-file-fixer - id: check-yaml exclude: 'mkdocs.yml' - repo: local hooks: - id: flake8 name: Run flake8 files: ^datar/.+$ pass_filenames: false entry: flake8 args: [datar] types: [python] language: system - id: versionchecker name: Check version agreement in pyproject and __version__ entry: bash -c language: system args: - get_ver() { echo $(egrep "^__version|^version" $1 | cut -d= -f2 | sed 's/\"\| //g'); }; v1=`get_ver pyproject.toml`; v2=`get_ver datar/__init__.py`; if [[ $v1 == $v2 ]]; then exit 0; else exit 1; fi pass_filenames: false files: ^pyproject\.toml|datar/__init__\.py$ - id: pytest name: Run pytest entry: pytest language: system args: [tests/] pass_filenames: false files: ^tests/.+$|^datar/.+$ ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2020 pwwang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # datar A Grammar of Data Manipulation in python [![Pypi][6]][7] [![Github][8]][9] ![Building][10] [![Docs and API][11]][5] [![Codacy][12]][13] [![Codacy coverage][14]][13] [![Downloads][20]][7] [Documentation][5] | [Reference Maps][15] | [Notebook Examples][16] | [API][17] `datar` is a re-imagining of APIs for data manipulation in python with multiple backends supported. Those APIs are aligned with tidyverse packages in R as much as possible. ## Installation ```shell pip install -U datar # install with a backend pip install -U datar[pandas] # More backends support coming soon ``` ## Backends |Repo|Badges| |-|-| |[datar-numpy][1]|![3] ![18]| |[datar-pandas][2]|![4] ![19]| |[datar-arrow][22]|![23] ![24]| ## Example usage ```python # with pandas backend from datar import f from datar.dplyr import mutate, filter_, if_else from datar.tibble import tibble # or # from datar.all import f, mutate, filter_, if_else, tibble df = tibble( x=range(4), # or c[:4] (from datar.base import c) y=['zero', 'one', 'two', 'three'] ) df >> mutate(z=f.x) """# output x y z 0 0 zero 0 1 1 one 1 2 2 two 2 3 3 three 3 """ df >> mutate(z=if_else(f.x>1, 1, 0)) """# output: x y z 0 0 zero 0 1 1 one 0 2 2 two 1 3 3 three 1 """ df >> filter_(f.x>1) """# output: x y 0 2 two 1 3 three """ df >> mutate(z=if_else(f.x>1, 1, 0)) >> filter_(f.z==1) """# output: x y z 0 2 two 1 1 3 three 1 """ ``` ```python # works with plotnine # example grabbed from https://github.com/has2k1/plydata import numpy from datar import f from datar.base import sin, pi from datar.tibble import tibble from datar.dplyr import mutate, if_else from plotnine import ggplot, aes, geom_line, theme_classic df = tibble(x=numpy.linspace(0, 2 * pi, 500)) ( df >> mutate(y=sin(f.x), sign=if_else(f.y >= 0, "positive", "negative")) >> ggplot(aes(x="x", y="y")) + theme_classic() + geom_line(aes(color="sign"), size=1.2) ) ``` ![example](./example.png) ```python # very easy to integrate with other libraries # for example: klib import klib from pipda import register_verb from datar import f from datar.data import iris from datar.dplyr import pull dist_plot = register_verb(func=klib.dist_plot) iris >> pull(f.Sepal_Length) >> dist_plot() ``` ![example](./example2.png) ## Testimonials [@coforfe](https://github.com/coforfe): > Thanks for your excellent package to port R (`dplyr`) flow of processing to Python. I have been using other alternatives, and yours is the one that offers the most extensive and equivalent to what is possible now with `dplyr`. [1]: https://github.com/pwwang/datar-numpy [2]: https://github.com/pwwang/datar-pandas [3]: https://img.shields.io/codacy/coverage/0a7519dad44246b6bab30576895f6766?style=flat-square [4]: https://img.shields.io/codacy/coverage/45f4ea84ae024f1a8cf84be54dd144f7?style=flat-square [5]: https://pwwang.github.io/datar/ [6]: https://img.shields.io/pypi/v/datar?style=flat-square [7]: https://pypi.org/project/datar/ [8]: https://img.shields.io/github/v/tag/pwwang/datar?style=flat-square [9]: https://github.com/pwwang/datar [10]: https://img.shields.io/github/actions/workflow/status/pwwang/datar/ci.yml?branch=master&style=flat-square [11]: https://img.shields.io/github/actions/workflow/status/pwwang/datar/docs.yml?branch=master&style=flat-square [12]: https://img.shields.io/codacy/grade/3d9bdff4d7a34bdfb9cd9e254184cb35?style=flat-square [13]: https://app.codacy.com/gh/pwwang/datar [14]: https://img.shields.io/codacy/coverage/3d9bdff4d7a34bdfb9cd9e254184cb35?style=flat-square [15]: https://pwwang.github.io/datar/reference-maps/ALL/ [16]: https://pwwang.github.io/datar/notebooks/across/ [17]: https://pwwang.github.io/datar/api/datar/ [18]: https://img.shields.io/pypi/v/datar-numpy?style=flat-square [19]: https://img.shields.io/pypi/v/datar-pandas?style=flat-square [20]: https://img.shields.io/pypi/dm/datar?style=flat-square [21]: https://github.com/tidyverse/dplyr [22]: https://github.com/pwwang/datar-arrow [23]: https://img.shields.io/codacy/coverage/5f4ef9dd2503437db18786ff9e841d8b?style=flat-square [24]: https://img.shields.io/pypi/v/datar-arrow?style=flat-square ================================================ FILE: datar/__init__.py ================================================ from typing import Mapping as _Mapping from .core import operator as _ from .core.defaults import f from .core.options import options, get_option, options_context __version__ = "0.15.17" __all__ = [ "f", "options", "get_option", "options_context", "get_versions", ] def get_versions(prnt: bool = True) -> _Mapping[str, str]: """Return/Print the versions of the dependencies. Args: prnt: If True, print the versions, otherwise return them. Returns: A dict of the versions of the dependencies if `prnt` is False. """ import sys import executing import pipda import simplug from .core.load_plugins import plugin versions = { "python": sys.version, "datar": __version__, "simplug": simplug.__version__, "executing": executing.__version__, "pipda": pipda.__version__, } versions_plg = plugin.hooks.get_versions() versions.update(versions_plg) if not prnt: return versions keylen = max(map(len, versions)) for key in versions: ver = versions[key] verlines = ver.splitlines() print(f"{key.ljust(keylen)}: {verlines.pop(0)}") for verline in verlines: # pragma: no cover print(f"{' ' * keylen} {verline}") return None ================================================ FILE: datar/all.py ================================================ """Import all constants, verbs and functions""" from .core import load_plugins as _ from .core.defaults import f from .base import _conflict_names as _base_conflict_names from .dplyr import _conflict_names as _dplyr_conflict_names from .base import * from .dplyr import * from .forcats import * from .tibble import * from .tidyr import * from .misc import * __all__ = [key for key in locals() if not key.startswith("_")] if get_option("allow_conflict_names"): # noqa: F405 __all__.extend(_base_conflict_names | _dplyr_conflict_names) for name in _base_conflict_names | _dplyr_conflict_names: locals()[name] = locals()[name + "_"] def __getattr__(name): """Even when allow_conflict_names is False, datar.base.sum should be fine """ if name in _base_conflict_names | _dplyr_conflict_names: import sys import ast from executing import Source node = Source.executing(sys._getframe(1)).node if isinstance(node, (ast.Call, ast.Attribute)): # import datar.all as d # d.sum(...) or getattr(d, "sum")(...) return globals()[name + "_"] raise AttributeError ================================================ FILE: datar/apis/__init__.py ================================================ ================================================ FILE: datar/apis/base.py ================================================ """APIs ported from r-base""" # import the variables with _ so that they are not imported by * import math as _math from typing import Any from string import ascii_letters as _ascii_letters from pipda import register_func as _register_func from ..core.utils import ( NotImplementedByCurrentBackendError as _NotImplementedByCurrentBackendError, CollectionFunction as _CollectionFunction, ) from ..core.options import options, get_option, options_context # noqa: F401 from ..core.names import repair_names as _repair_names pi = _math.pi letters = list(_ascii_letters[:26]) LETTERS = list(_ascii_letters[26:]) month_name = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", ] month_abb = [m[:3] for m in month_name] FALSE = False TRUE = True NA = float("nan") NULL = None NaN = float("nan") Inf = float("inf") @_register_func(pipeable=True, dispatchable=True) def ceiling(x) -> Any: """Round up to the nearest integer Args: x: The value to be rounded up Returns: The rounded up value """ raise _NotImplementedByCurrentBackendError("ceiling", x) @_register_func(pipeable=True, dispatchable=True) def cov(x, y=None, na_rm: bool = False, ddof: int = 1) -> Any: """Compute pairwise covariance between two variables Args: x: a numeric vector, matrix or data frame. y: None or a vector, matrix or data frame with compatible dimensions to `x`. The default is equivalent to `y = x` na_rm: If `True`, remove missing values before computing the covariance. ddof: The denominator degrees of freedom. Returns: The covariance matrix """ raise _NotImplementedByCurrentBackendError("cov", x) @_register_func(pipeable=True, dispatchable=True) def floor(x) -> Any: """Round down to the nearest integer Args: x: The value to be rounded down Returns: The rounded down value """ raise _NotImplementedByCurrentBackendError("floor", x) @_register_func(pipeable=True, dispatchable=True) def mean(x, na_rm: bool = False) -> Any: """Compute the mean of a vector Args: x: A numeric vector na_rm: Whether to remove `NA` values Returns: The mean of the vector """ raise _NotImplementedByCurrentBackendError("mean", x) @_register_func(pipeable=True, dispatchable=True) def median(x, na_rm: bool = False) -> Any: """Compute the median of a vector Args: x: A numeric vector na_rm: Whether to remove `NA` values Returns: The median of the vector """ raise _NotImplementedByCurrentBackendError("median", x) @_register_func(pipeable=True, dispatchable=True) def pmax(*args, na_rm: bool = False) -> Any: """Returns the (regular or Parallel) maxima and minima of the input values. Args: x: A numeric vector more: One or more values na_rm: Whether to remove `NA` values Returns: The maximum of the vector and the values """ raise _NotImplementedByCurrentBackendError("pmax") @_register_func(pipeable=True, dispatchable=True) def pmin(*args, na_rm: bool = False) -> Any: """Returns the (regular or Parallel) maxima and minima of the input values. Args: x: A numeric vector more: One or more values na_rm: Whether to remove `NA` values Returns: The minimum of the vector and the values """ raise _NotImplementedByCurrentBackendError("pmin") @_register_func(pipeable=True, dispatchable=True) def sqrt(x) -> Any: """Compute the square root of a vector Args: x: A numeric vector Returns: The square root of the vector """ raise _NotImplementedByCurrentBackendError("sqrt", x) @_register_func(pipeable=True, dispatchable=True) def var(x, na_rm: bool = False, ddof: int = 1) -> Any: """Compute the variance of a vector Args: x: A numeric vector y: None or a vector, matrix or data frame with compatible dimensions to `x`. The default is equivalent to `y = x` na_rm: Whether to remove `NA` values ddof: The degrees of freedom Returns: The variance of the vector """ raise _NotImplementedByCurrentBackendError("var", x) @_register_func(pipeable=True, dispatchable=True) def scale(x, center=True, scale_=True) -> Any: """Center and/or scale the data Args: x: A numeric vector center: Whether to center the data scale_: Whether to scale the data Returns: The scaled data """ raise _NotImplementedByCurrentBackendError("scale", x) @_register_func(pipeable=True, dispatchable=True) def col_sums(x, na_rm: bool = False) -> Any: """Compute the column sums of a matrix Args: x: A numeric matrix na_rm: Whether to remove `NA` values Returns: The column sums of the matrix """ raise _NotImplementedByCurrentBackendError("col_sums", x) @_register_func(pipeable=True, dispatchable=True) def col_means(x, na_rm: bool = False) -> Any: """Compute the column means of a matrix Args: x: A numeric matrix na_rm: Whether to remove `NA` values Returns: The column means of the matrix """ raise _NotImplementedByCurrentBackendError("col_means", x) @_register_func(pipeable=True, dispatchable=True) def col_sds(x, na_rm: bool = False) -> Any: """Compute the column standard deviations of a matrix Args: x: A numeric matrix na_rm: Whether to remove `NA` values Returns: The column standard deviations of the matrix """ raise _NotImplementedByCurrentBackendError("col_sds", x) @_register_func(pipeable=True, dispatchable=True) def col_medians(x, na_rm: bool = False) -> Any: """Compute the column medians of a matrix Args: x: A numeric matrix na_rm: Whether to remove `NA` values Returns: The column medians of the matrix """ raise _NotImplementedByCurrentBackendError("col_medians", x) @_register_func(pipeable=True, dispatchable=True) def row_sums(x, na_rm: bool = False) -> Any: """Compute the row sums of a matrix Args: x: A numeric matrix na_rm: Whether to remove `NA` values Returns: The row sums of the matrix """ raise _NotImplementedByCurrentBackendError("row_sums", x) @_register_func(pipeable=True, dispatchable=True) def row_means(x, na_rm: bool = False) -> Any: """Compute the row means of a matrix Args: x: A numeric matrix na_rm: Whether to remove `NA` values Returns: The row means of the matrix """ raise _NotImplementedByCurrentBackendError("row_means", x) @_register_func(pipeable=True, dispatchable=True) def row_sds(x, na_rm: bool = False) -> Any: """Compute the row standard deviations of a matrix Args: x: A numeric matrix na_rm: Whether to remove `NA` values Returns: The row standard deviations of the matrix """ raise _NotImplementedByCurrentBackendError("row_sds", x) @_register_func(pipeable=True, dispatchable=True) def row_medians(x, na_rm: bool = False) -> Any: """Compute the row medians of a matrix Args: x: A numeric matrix na_rm: Whether to remove `NA` values Returns: The row medians of the matrix """ raise _NotImplementedByCurrentBackendError("row_medians", x) @_register_func(pipeable=True, dispatchable=True) def min_(x, na_rm: bool = False) -> Any: """Compute the minimum of a vector Args: x: A numeric vector na_rm: Whether to remove `NA` values Returns: The minimum of the vector """ raise _NotImplementedByCurrentBackendError("min", x) @_register_func(pipeable=True, dispatchable=True) def max_(x, na_rm: bool = False) -> Any: """Compute the maximum of a vector Args: x: A numeric vector na_rm: Whether to remove `NA` values Returns: The maximum of the vector """ raise _NotImplementedByCurrentBackendError("max", x) @_register_func(pipeable=True, dispatchable=True) def round_(x, digits: int = 0) -> Any: """Round the values of a vector Args: x: A numeric vector digits: The number of digits to round to Returns: The rounded values """ raise _NotImplementedByCurrentBackendError("round", x) @_register_func(pipeable=True, dispatchable=True) def sum_(x, na_rm: bool = False) -> Any: """Compute the sum of a vector Args: x: A numeric vector na_rm: Whether to remove `NA` values Returns: The sum of the vector """ raise _NotImplementedByCurrentBackendError("sum", x) @_register_func(pipeable=True, dispatchable=True) def abs_(x) -> Any: """Compute the absolute value of a vector Args: x: A numeric vector Returns: The absolute values of the vector """ raise _NotImplementedByCurrentBackendError("abs", x) @_register_func(pipeable=True, dispatchable=True) def prod(x, na_rm: bool = False) -> Any: """Compute the product of a vector Args: x: A numeric vector na_rm: Whether to remove `NA` values Returns: The product of the vector """ raise _NotImplementedByCurrentBackendError("prod", x) @_register_func(pipeable=True, dispatchable=True) def sign(x) -> Any: """Compute the sign of a vector Args: x: A numeric vector Returns: The signs of the vector """ raise _NotImplementedByCurrentBackendError("sign", x) @_register_func(pipeable=True, dispatchable=True) def signif(x, digits: int = 6) -> Any: """Round the values of a vector to a given number of significant digits Args: x: A numeric vector digits: The number of significant digits to round to Returns: The rounded values """ raise _NotImplementedByCurrentBackendError("signif", x) @_register_func(pipeable=True, dispatchable=True) def trunc(x) -> Any: """Truncate the values of a vector Args: x: A numeric vector Returns: The truncated values """ raise _NotImplementedByCurrentBackendError("trunc", x) @_register_func(pipeable=True, dispatchable=True) def exp(x) -> Any: """Compute the exponential of a vector Args: x: A numeric vector Returns: The exponential values """ raise _NotImplementedByCurrentBackendError("exp", x) @_register_func(pipeable=True, dispatchable=True) def log(x, base: float = _math.e) -> Any: """Compute the logarithm of a vector Args: x: A numeric vector base: The base of the logarithm Returns: The logarithm values """ raise _NotImplementedByCurrentBackendError("log", x) @_register_func(pipeable=True, dispatchable=True) def log2(x) -> Any: """Compute the base-2 logarithm of a vector Args: x: A numeric vector Returns: The logarithm values """ raise _NotImplementedByCurrentBackendError("log2", x) @_register_func(pipeable=True, dispatchable=True) def log10(x) -> Any: """Compute the base 10 logarithm of a vector Args: x: A numeric vector Returns: The logarithm values """ raise _NotImplementedByCurrentBackendError("log10", x) @_register_func(pipeable=True, dispatchable=True) def log1p(x) -> Any: """Compute the logarithm of one plus a vector Args: x: A numeric vector Returns: The logarithm values """ raise _NotImplementedByCurrentBackendError("log1p", x) @_register_func(pipeable=True, dispatchable=True) def sd(x, na_rm: bool = False) -> Any: """Compute the standard deviation of a vector Args: x: A numeric vector na_rm: Whether to remove `NA` values Returns: The standard deviation of the vector """ raise _NotImplementedByCurrentBackendError("sd", x) @_register_func(pipeable=True, dispatchable=True) def weighted_mean(x, w=None, na_rm: bool = False) -> Any: """Compute the weighted mean of a vector Args: x: A numeric vector w: The weights to use na_rm: Whether to remove `NA` values Returns: The weighted mean of the vector """ raise _NotImplementedByCurrentBackendError("weighted_mean", x) @_register_func(pipeable=True, dispatchable=True) def quantile( x, probs=(0.0, 0.25, 0.5, 0.75, 1.0), na_rm: bool = False, names: bool = True, type_: int = 7, digits: int = 7, ) -> Any: """Compute the quantiles of a vector Args: x: A numeric vector probs: The probabilities to use Returns: The quantiles of the vector """ raise _NotImplementedByCurrentBackendError("quantile", x) @_register_func(pipeable=True, dispatchable=True) def bessel_i(x, nu, expon_scaled: bool = False) -> Any: """Compute the modified Bessel function of the first kind Args: x: A numeric vector nu: The order of the Bessel function expon_scaled: Whether to use the scaled version Returns: The Bessel function values """ raise _NotImplementedByCurrentBackendError("bessel_i", x) @_register_func(pipeable=True, dispatchable=True) def bessel_j(x, nu) -> Any: """Compute the Bessel function of the first kind Args: x: A numeric vector nu: The order of the Bessel function Returns: The Bessel function values """ raise _NotImplementedByCurrentBackendError("bessel_j", x) @_register_func(pipeable=True, dispatchable=True) def bessel_k(x, nu, expon_scaled: bool = False) -> Any: """Compute the modified Bessel function of the second kind Args: x: A numeric vector nu: The order of the Bessel function expon_scaled: Whether to use the scaled version Returns: The Bessel function values """ raise _NotImplementedByCurrentBackendError("bessel_k", x) @_register_func(pipeable=True, dispatchable=True) def bessel_y(x, nu) -> Any: """Compute the Bessel function of the second kind Args: x: A numeric vector nu: The order of the Bessel function Returns: The Bessel function values """ raise _NotImplementedByCurrentBackendError("bessel_y", x) @_register_func(pipeable=True, dispatchable=True) def as_double(x) -> Any: """Convert a vector to a double vector Args: x: A numeric vector Returns: The double vector """ raise _NotImplementedByCurrentBackendError("as_double", x) @_register_func(pipeable=True, dispatchable=True) def as_integer(x) -> Any: """Convert a vector to an integer vector Args: x: A numeric vector Returns: The integer vector """ raise _NotImplementedByCurrentBackendError("as_integer", x) @_register_func(pipeable=True, dispatchable=True) def as_logical(x) -> Any: """Convert a vector to a logical vector Args: x: A numeric vector Returns: The logical vector """ raise _NotImplementedByCurrentBackendError("as_logical", x) @_register_func(pipeable=True, dispatchable=True) def as_character(x) -> Any: """Convert a vector to a character vector Args: x: A numeric vector Returns: The character vector """ raise _NotImplementedByCurrentBackendError("as_character", x) @_register_func(pipeable=True, dispatchable=True) def as_factor(x) -> Any: """Convert a vector to a factor vector Args: x: A numeric vector Returns: The factor vector """ raise _NotImplementedByCurrentBackendError("as_factor", x) @_register_func(pipeable=True, dispatchable=True) def as_ordered(x) -> Any: """Convert a vector to an ordered vector Args: x: A numeric vector Returns: The ordered vector """ raise _NotImplementedByCurrentBackendError("as_ordered", x) @_register_func(pipeable=True, dispatchable=True) def as_date( x, *, format=None, try_formats=None, optional=False, tz=0, origin=None, ) -> Any: """Convert an object to a datetime.date object See: https://rdrr.io/r/base/as.Date.html Args: x: Object that can be converted into a datetime.date object format: If not specified, it will try try_formats one by one on the first non-np.nan element, and give an error if none works. Otherwise, the processing is via strptime try_formats: vector of format strings to try if format is not specified. Default formats to try: "%Y-%m-%d" "%Y/%m/%d" "%Y-%m-%d %H:%M:%S" "%Y/%m/%d %H:%M:%S" optional: indicating to return np.nan (instead of signalling an error) if the format guessing does not succeed. origin: a datetime.date/datetime object, or something which can be coerced by as_date(origin, ...) to such an object. tz: a time zone offset or a datetime.timedelta object. Note that time zone name is not supported yet. Returns: The datetime.date object """ raise _NotImplementedByCurrentBackendError("as_date", x) @_register_func(pipeable=True, dispatchable=True) def as_numeric(x) -> Any: """Convert a vector to a numeric vector Args: x: A numeric vector Returns: The numeric vector """ raise _NotImplementedByCurrentBackendError("as_numeric", x) @_register_func(pipeable=True, dispatchable=True) def arg(x) -> Any: """Angles of complex numbers Args: x: A numeric vector Returns: The angles """ raise _NotImplementedByCurrentBackendError("arg", x) @_register_func(pipeable=True, dispatchable=True) def conj(x) -> Any: """Complex conjugate Args: x: A numeric vector Returns: The complex conjugates """ raise _NotImplementedByCurrentBackendError("conj", x) @_register_func(pipeable=True, dispatchable=True) def mod(x) -> Any: """Modulus of complex numbers Args: x: A numeric vector Returns: The modulus """ raise _NotImplementedByCurrentBackendError("mod", x) @_register_func(pipeable=True, dispatchable=True) def re_(x) -> Any: """Real part of complex numbers Args: x: A numeric vector Returns: The real parts """ raise _NotImplementedByCurrentBackendError("re", x) @_register_func(pipeable=True, dispatchable=True) def im(x) -> Any: """Imaginary part of complex numbers Args: x: A numeric vector Returns: The imaginary parts """ raise _NotImplementedByCurrentBackendError("im", x) @_register_func(pipeable=True, dispatchable=True) def as_complex(x) -> Any: """Convert a vector to a complex vector Args: x: A numeric vector Returns: The complex vector """ raise _NotImplementedByCurrentBackendError("as_complex", x) @_register_func(pipeable=True, dispatchable=True) def is_complex(x) -> Any: """Check if a vector is complex Args: x: A numeric vector Returns: Whether the vector is complex """ raise _NotImplementedByCurrentBackendError("is_complex", x) @_register_func(pipeable=True, dispatchable=True) def cummax(x) -> Any: """Cumulative maxima Args: x: A numeric vector Returns: The cumulative maxima """ raise _NotImplementedByCurrentBackendError("cummax", x) @_register_func(pipeable=True, dispatchable=True) def cummin(x) -> Any: """Cumulative minima Args: x: A numeric vector Returns: The cumulative minima """ raise _NotImplementedByCurrentBackendError("cummin", x) @_register_func(pipeable=True, dispatchable=True) def cumprod(x) -> Any: """Cumulative products Args: x: A numeric vector Returns: The cumulative products """ raise _NotImplementedByCurrentBackendError("cumprod", x) @_register_func(pipeable=True, dispatchable=True) def cumsum(x) -> Any: """Cumulative sums Args: x: A numeric vector Returns: The cumulative sums """ raise _NotImplementedByCurrentBackendError("cumsum", x) @_register_func(pipeable=True, dispatchable=True) def droplevels(x) -> Any: """Drop unused levels of a factor Args: x: A numeric vector Returns: The factor vector """ raise _NotImplementedByCurrentBackendError("droplevels", x) @_register_func(pipeable=True, dispatchable=True) def levels(x) -> Any: """Get the levels of a factor Args: x: A numeric vector Returns: The factor vector """ raise _NotImplementedByCurrentBackendError("levels", x) @_register_func(pipeable=True, dispatchable=True) def set_levels(x, levels) -> Any: """Set the levels of a factor Args: x: A numeric vector levels: The new levels Returns: The factor vector """ raise _NotImplementedByCurrentBackendError("set_levels", x) @_register_func(pipeable=True, dispatchable=True) def is_factor(x) -> Any: """Check if a vector is a factor Args: x: A numeric vector Returns: Whether the vector is a factor """ raise _NotImplementedByCurrentBackendError("is_factor", x) @_register_func(pipeable=True, dispatchable=True) def is_ordered(x) -> Any: """Check if a vector is ordered Args: x: A numeric vector Returns: Whether the vector is ordered """ raise _NotImplementedByCurrentBackendError("is_ordered", x) @_register_func(pipeable=True, dispatchable=True) def nlevels(x) -> Any: """Get the number of levels of a factor Args: x: A numeric vector Returns: The number of levels """ raise _NotImplementedByCurrentBackendError("nlevels", x) @_register_func(pipeable=True, dispatchable=True) def factor( x=None, *, levels=None, labels=None, exclude=None, ordered=False, nmax=None, ) -> Any: """Create a factor vector Args: x: A numeric vector levels: The levels labels: The labels exclude: The excluded levels ordered: Whether the factor is ordered nmax: The maximum number of levels Returns: The factor vector """ raise _NotImplementedByCurrentBackendError("factor", x) @_register_func(pipeable=True, dispatchable=True) def ordered(x, levels=None, labels=None, exclude=None, nmax=None) -> Any: """Create an ordered factor vector Args: x: A numeric vector levels: The levels labels: The labels exclude: The excluded levels nmax: The maximum number of levels Returns: The ordered factor vector """ raise _NotImplementedByCurrentBackendError("ordered", x) @_register_func(pipeable=True, dispatchable=True) def cut( x, breaks, labels=None, include_lowest=False, right=True, dig_lab=3, ordered_result=False, ) -> Any: """Cut a numeric vector into bins Args: x: A numeric vector breaks: The breaks labels: The labels include_lowest: Whether to include the lowest value right: Whether to include the rightmost value dig_lab: The number of digits for labels ordered_result: Whether to return an ordered factor Returns: The factor vector """ raise _NotImplementedByCurrentBackendError("cut", x) @_register_func(pipeable=True, dispatchable=True) def diff(x, lag: int = 1, differences: int = 1) -> Any: """Difference of a numeric vector Args: x: A numeric vector lag: The lag to use. Could be negative. It always calculates `x[lag:] - x[:-lag]` even when `lag` is negative differences: The order of the difference Returns: An array of `x[lag:] – x[:-lag]`. If `differences > 1`, the rule applies `differences` times on `x` """ raise _NotImplementedByCurrentBackendError("diff", x) @_register_func(pipeable=True, dispatchable=True) def expand_grid(x, *args, **kwargs) -> Any: """Expand a grid Args: x: A numeric vector *args: Additional numeric vectors **kwargs: Additional keyword arguments Returns: The expanded grid """ raise _NotImplementedByCurrentBackendError("expand_grid", x) @_register_func(pipeable=True, dispatchable=True) def outer(x, y, fun="*") -> Any: """Outer product of two vectors Args: x: A numeric vector y: A numeric vector fun: The function to handle how the result of the elements from the first and second vectors should be computed. The function has to be vectorized at the second argument, and return the same shape as y. Returns: The outer product """ raise _NotImplementedByCurrentBackendError("outer", x) @_register_func(cls=object, pipeable=True, dispatchable=True) def make_names(names, unique: bool = True) -> Any: """Make names for a vector Args: names: character vector to be coerced to syntactically valid names. This is coerced to character if necessary. unique: Whether to make the names unique Returns: The names """ try: from slugify import slugify except ImportError as imerr: # pragma: no cover raise ValueError( "`make_names()` requires `python-slugify` package.\n" "Try: pip install -U slugify" ) from imerr if isinstance(names, str): names = [names] try: iter(names) except TypeError: names = [names] names = [ slugify(str(name), separator="_", lowercase=False) for name in names ] names = [f"_{name}" if name[0].isdigit() else name for name in names] if unique: return _repair_names(names, "unique") return names @_register_func(cls=object, pipeable=True, dispatchable=True) def make_unique(names) -> Any: """Make a vector unique Args: names: a character vector Returns: The unique vector """ return make_names(names, unique=True, __ast_fallback="normal") @_register_func(pipeable=True, dispatchable=True) def rank(x, na_last: bool = True, ties_method: str = "average") -> Any: """Rank a numeric vector Args: x: A numeric vector na_last: Whether to put NA at the end ties_method: The method to handle ties. One of "average", "first", "last", "random", "max", "min" Returns: The ranks """ raise _NotImplementedByCurrentBackendError("rank", x) @_register_func(cls=object, pipeable=True, dispatchable=True) def identity(x) -> Any: """Identity function Args: x: A numeric vector Returns: The same vector """ return x @_register_func(pipeable=True, dispatchable=True) def is_logical(x) -> Any: """Check if a vector is logical Args: x: A numeric vector Returns: Whether the vector is logical """ raise _NotImplementedByCurrentBackendError("is_logical", x) @_register_func(pipeable=True, dispatchable=True) def is_true(x) -> bool: """Check if anything is true Args: x: object to be tested Returns: Whether `x` is true """ raise _NotImplementedByCurrentBackendError("is_true", x) @_register_func(pipeable=True, dispatchable=True) def is_false(x) -> bool: """Check if anything is false Args: x: object to be tested Returns: Whether `x` is false """ raise _NotImplementedByCurrentBackendError("is_false", x) @_register_func(pipeable=True, dispatchable=True) def is_na(x) -> Any: """Check if anything is NA Args: x: object to be tested Returns: Whether `x` is NA """ raise _NotImplementedByCurrentBackendError("is_na", x) @_register_func(pipeable=True, dispatchable=True) def is_finite(x) -> Any: """Check if anything is finite Args: x: object to be tested Returns: Whether `x` is finite """ raise _NotImplementedByCurrentBackendError("is_finite", x) @_register_func(pipeable=True, dispatchable=True) def is_infinite(x) -> Any: """Check if anything is infinite Args: x: object to be tested Returns: Whether `x` is infinite """ raise _NotImplementedByCurrentBackendError("is_infinite", x) @_register_func(pipeable=True, dispatchable=True) def any_na(x) -> Any: """Check if anything in `x` is NA Args: x: object to be tested Returns: Whether anything in `x` is NA """ raise _NotImplementedByCurrentBackendError("any_na", x) @_register_func(pipeable=True, dispatchable=True) def as_null(x) -> Any: """Convert anything to NULL Args: x: object to be converted Returns: NULL """ raise _NotImplementedByCurrentBackendError("as_null", x) @_register_func(pipeable=True, dispatchable=True) def is_null(x) -> Any: """Check if anything is NULL Args: x: object to be tested Returns: Whether `x` is NULL """ raise _NotImplementedByCurrentBackendError("is_null", x) @_register_func(pipeable=True, dispatchable=True) def set_seed(seed) -> Any: """Set the seed of the random number generator Args: seed: The seed """ raise _NotImplementedByCurrentBackendError("set_seed", seed) @_register_func(pipeable=True, dispatchable="all") def rep(x, times=1, length=None, each=1) -> Any: """Replicate elements of a vector Args: x: a vector or scaler times: number of times to repeat each element if of length len(x), or to repeat the whole vector if of length 1 length: non-negative integer. The desired length of the output vector each: non-negative integer. Each element of x is repeated each times. Returns: The replicated vector """ raise _NotImplementedByCurrentBackendError("rep", x) @_register_func(pipeable=True, dispatchable=True) def c_(*args) -> Any: """Concatenate vectors Args: args: vectors to be concatenated Returns: The concatenated vector """ raise _NotImplementedByCurrentBackendError("c", *args) c = _CollectionFunction(c_) @_register_func(pipeable=True, dispatchable=True) def length(x) -> Any: """Get the length of a vector Args: x: a vector or scaler Returns: The length of the vector """ raise _NotImplementedByCurrentBackendError("length", x) @_register_func(pipeable=True, dispatchable=True) def lengths(x) -> Any: """Get the lengths of a list Args: x: a list Returns: The lengths of the list """ raise _NotImplementedByCurrentBackendError("lengths", x) @_register_func(pipeable=True, dispatchable=True) def order(x, decreasing: bool = False, na_last: bool = True) -> Any: """Order a vector Args: x: a vector or scaler decreasing: Whether to order in decreasing order na_last: Whether to put NA at the end Returns: The order """ raise _NotImplementedByCurrentBackendError("order", x) @_register_func(pipeable=True, dispatchable=True) def sort(x, decreasing: bool = False, na_last: bool = True) -> Any: """Sort a vector Args: x: a vector or scaler decreasing: Whether to sort in decreasing order na_last: Whether to put NA at the end Returns: The sorted vector """ raise _NotImplementedByCurrentBackendError("sort", x) @_register_func(pipeable=True, dispatchable=True) def rev(x) -> Any: """Reverse a vector Args: x: a vector or scaler Returns: The reversed vector """ raise _NotImplementedByCurrentBackendError("rev", x) @_register_func(pipeable=True, dispatchable=True) def sample(x, size=None, replace: bool = False, prob=None) -> Any: """Sample a vector Args: x: a vector or scaler size: the size of the sample replace: whether to sample with replacement prob: the probabilities of sampling each element Returns: The sampled vector """ raise _NotImplementedByCurrentBackendError("sample", x) @_register_func(pipeable=True, dispatchable=True) def seq(from_=None, to=None, by=None, length_out=None, along_with=None) -> Any: """Generate a sequence Args: from_: the start of the sequence to: the end of the sequence by: the step of the sequence length_out: the length of the sequence along_with: the sequence to be aligned with Returns: The sequence """ raise _NotImplementedByCurrentBackendError("seq", from_) @_register_func(pipeable=True, dispatchable=True) def seq_along(x) -> Any: """Generate a sequence along a vector Args: x: a vector or scaler Returns: The sequence """ raise _NotImplementedByCurrentBackendError("seq_along", x) @_register_func(pipeable=True, dispatchable=True) def seq_len(x) -> Any: """Generate a sequence of length x Args: x: a vector or scaler Returns: The sequence """ raise _NotImplementedByCurrentBackendError("seq_len", x) @_register_func(pipeable=True, dispatchable=True) def match(x, table, nomatch=-1) -> Any: """Match elements of a vector Args: x: a vector or scaler table: the table to match nomatch: the value to use for no match Returns: The matched vector """ raise _NotImplementedByCurrentBackendError("match", x) @_register_func(pipeable=True, dispatchable=True) def beta(x, y) -> Any: """Compute the beta function Args: x: a vector or scaler y: a vector or scaler Returns: The beta function """ raise _NotImplementedByCurrentBackendError("beta", x) @_register_func(pipeable=True, dispatchable=True) def lgamma(x) -> Any: """Compute the log gamma function Args: x: a vector or scaler Returns: The log gamma function """ raise _NotImplementedByCurrentBackendError("lgamma", x) @_register_func(pipeable=True, dispatchable=True) def digamma(x) -> Any: """Compute the digamma function Args: x: a vector or scaler Returns: The digamma function """ raise _NotImplementedByCurrentBackendError("digamma", x) @_register_func(pipeable=True, dispatchable=True) def trigamma(x) -> Any: """Compute the trigamma function Args: x: a vector or scaler Returns: The trigamma function """ raise _NotImplementedByCurrentBackendError("trigamma", x) @_register_func(pipeable=True, dispatchable=True) def choose(n, k) -> Any: """Compute the binomial coefficient Args: n: a vector or scaler k: a vector or scaler Returns: The binomial coefficient """ raise _NotImplementedByCurrentBackendError("choose", n) @_register_func(pipeable=True, dispatchable=True) def factorial(x) -> Any: """Compute the factorial Args: x: a vector or scaler Returns: The factorial """ raise _NotImplementedByCurrentBackendError("factorial", x) @_register_func(pipeable=True, dispatchable=True) def gamma(x) -> Any: """Compute the gamma function Args: x: a vector or scaler Returns: The gamma function """ raise _NotImplementedByCurrentBackendError("gamma", x) @_register_func(pipeable=True, dispatchable=True) def lfactorial(x) -> Any: """Compute the log factorial Args: x: a vector or scaler Returns: The log factorial """ raise _NotImplementedByCurrentBackendError("lfactorial", x) @_register_func(pipeable=True, dispatchable=True) def lchoose(n, k) -> Any: """Compute the log binomial coefficient Args: n: a vector or scaler k: a vector or scaler Returns: The log binomial coefficient """ raise _NotImplementedByCurrentBackendError("lchoose", n) @_register_func(pipeable=True, dispatchable=True) def lbeta(x, y) -> Any: """Compute the log beta function Args: x: a vector or scaler y: a vector or scaler Returns: The log beta function """ raise _NotImplementedByCurrentBackendError("lbeta", x) @_register_func(pipeable=True, dispatchable=True) def psigamma(x, deriv) -> Any: """Compute the psi function Args: x: a vector or scaler deriv: the derivative Returns: The psi function """ raise _NotImplementedByCurrentBackendError("psigamma", x) @_register_func(pipeable=True, dispatchable=True) def rnorm(n, mean=0, sd=1) -> Any: """Generate random normal variables Args: n: the number of random variables mean: the mean of the random variables sd: the standard deviation of the random variables Returns: The random normal variables """ raise _NotImplementedByCurrentBackendError("rnorm", n) @_register_func(pipeable=True, dispatchable=True) def runif(n, min=0, max=1) -> Any: """Generate random uniform variables Args: n: the number of random variables min: the minimum of the random variables max: the maximum of the random variables Returns: The random uniform variables """ raise _NotImplementedByCurrentBackendError("runif", n) @_register_func(pipeable=True, dispatchable=True) def rpois(n, lambda_) -> Any: """Generate random Poisson variables Args: n: the number of random variables lambda_: the lambda of the random variables Returns: The random Poisson variables """ raise _NotImplementedByCurrentBackendError("rpois", n) @_register_func(pipeable=True, dispatchable=True) def rbinom(n, size, prob) -> Any: """Generate random binomial variables Args: n: the number of random variables size: the size of the random variables prob: the probability of the random variables Returns: The random binomial variables """ raise _NotImplementedByCurrentBackendError("rbinom", n) @_register_func(pipeable=True, dispatchable=True) def rcauchy(n, location=0, scale=1) -> Any: """Generate random Cauchy variables Args: n: the number of random variables location: the location of the random variables scale: the scale of the random variables Returns: The random Cauchy variables """ raise _NotImplementedByCurrentBackendError("rcauchy", n) @_register_func(pipeable=True, dispatchable=True) def rchisq(n, df) -> Any: """Generate random chi-squared variables Args: n: the number of random variables df: the degrees of freedom of the random variables Returns: The random chi-squared variables """ raise _NotImplementedByCurrentBackendError("rchisq", n) @_register_func(pipeable=True, dispatchable=True) def rexp(n, rate) -> Any: """Generate random exponential variables Args: n: the number of random variables rate: the rate of the random variables Returns: The random exponential variables """ raise _NotImplementedByCurrentBackendError("rexp", n) @_register_func(pipeable=True, dispatchable=True) def is_character(x) -> Any: """Is x a character vector Args: x: a vector or scaler Returns: True if x is a character vector """ raise _NotImplementedByCurrentBackendError("is_character", x) @_register_func(pipeable=True, dispatchable=True) def grep( pattern, x, ignore_case=False, value=False, fixed=False, invert=False, ) -> Any: """Grep for a pattern Args: pattern: the pattern to search for x: the vector to search ignore_case: ignore case value: return the value fixed: use fixed string matching invert: invert the match Returns: The indices of the matches """ raise _NotImplementedByCurrentBackendError("grep", pattern) @_register_func(pipeable=True, dispatchable=True) def grepl(pattern, x, ignore_case=False, fixed=False) -> Any: """Grep for a pattern Args: pattern: the pattern to search for x: the vector to search ignore_case: ignore case fixed: use fixed string matching Returns: The indices of the matches """ raise _NotImplementedByCurrentBackendError("grepl", pattern) @_register_func(pipeable=True, dispatchable=True) def sub(pattern, replacement, x, ignore_case=False, fixed=False) -> Any: """Substitute a pattern Args: pattern: the pattern to search for replacement: the replacement x: the vector to search ignore_case: ignore case fixed: use fixed string matching Returns: The vector with the substitutions """ raise _NotImplementedByCurrentBackendError("sub", pattern) @_register_func(pipeable=True, dispatchable=True) def gsub(pattern, replacement, x, ignore_case=False, fixed=False) -> Any: """Substitute a pattern Args: pattern: the pattern to search for replacement: the replacement x: the vector to search ignore_case: ignore case fixed: use fixed string matching Returns: The vector with the substitutions """ raise _NotImplementedByCurrentBackendError("gsub", pattern) @_register_func(pipeable=True, dispatchable=True) def strsplit(x, split, fixed=False, perl=False, use_bytes=False) -> Any: """Split a string Args: x: the vector to split split: the pattern to split on fixed: use fixed string matching perl: use perl regular expressions use_bytes: use bytes Returns: The vector with the splits """ raise _NotImplementedByCurrentBackendError("strsplit", x) @_register_func(pipeable=True, dispatchable=True) def paste(*args, sep=" ", collapse=None) -> Any: """Join a vector into a string Args: *args: the vector to join sep: the separator collapse: collapse the vector Returns: The vector joined into a string """ raise _NotImplementedByCurrentBackendError("paste") @_register_func(pipeable=True, dispatchable=True) def paste0(*args, collapse=None) -> Any: """Join a vector into a string Args: *args: the vector to join collapse: collapse the vector Returns: The vector joined into a string """ raise _NotImplementedByCurrentBackendError("paste0") @_register_func(pipeable=True, dispatchable=True) def sprintf(fmt, *args) -> Any: """Format a string Args: fmt: the format string args: the arguments to the format string Returns: The formatted string """ raise _NotImplementedByCurrentBackendError("sprintf", fmt) @_register_func(pipeable=True, dispatchable=True) def substr(x, start, stop) -> Any: """Get a substring Args: x: the string to get the substring from start: the start of the substring stop: the stop of the substring Returns: The substring """ raise _NotImplementedByCurrentBackendError("substr", x) @_register_func(pipeable=True, dispatchable=True) def substring(x, first, last=None) -> Any: """Get a substring Args: x: the string to get the substring from first: the start of the substring last: the stop of the substring Returns: The substring """ raise _NotImplementedByCurrentBackendError("substring", x) @_register_func(pipeable=True, dispatchable=True) def startswith(x, prefix) -> Any: """Does x start with prefix Args: x: the string to check prefix: the prefix to check Returns: True if x starts with prefix """ raise _NotImplementedByCurrentBackendError("startswith", x) @_register_func(pipeable=True, dispatchable=True) def endswith(x, suffix) -> Any: """Does x end with suffix Args: x: the string to check suffix: the suffix to check Returns: True if x ends with suffix """ raise _NotImplementedByCurrentBackendError("endswith", x) @_register_func(pipeable=True, dispatchable=True) def strtoi(x, base=0) -> Any: """Convert a string to an integer Args: x: the string to convert base: the base of the integer Returns: The integer """ raise _NotImplementedByCurrentBackendError("strtoi", x) @_register_func(pipeable=True, dispatchable=True) def trimws(x, which="both", whitespace=r" \t") -> Any: """Trim whitespace from a string Args: x: the string to trim which: which whitespace to trim whitespace: the whitespace to trim Returns: The trimmed string """ raise _NotImplementedByCurrentBackendError("trimws", x) @_register_func(pipeable=True, dispatchable=True) def toupper(x) -> Any: """Convert a string to upper case Args: x: the string to convert Returns: The upper case string """ raise _NotImplementedByCurrentBackendError("toupper", x) @_register_func(pipeable=True, dispatchable=True) def tolower(x) -> Any: """Convert a string to lower case Args: x: the string to convert Returns: The lower case string """ raise _NotImplementedByCurrentBackendError("tolower", x) @_register_func(pipeable=True, dispatchable=True) def chartr(old, new, x) -> Any: """Translate characters Args: old: the characters to translate new: the new characters x: the string to translate Returns: The translated string """ raise _NotImplementedByCurrentBackendError("chartr", x) @_register_func(pipeable=True, dispatchable=True) def nchar( x, type_="width", allow_na: bool = True, keep_na: bool = False, _na_len: int = 2, ) -> Any: """Get the number of characters in a string Args: x: the string to count type: the type of count allow_na: allow NA keep_na: keep NA Returns: The number of characters """ raise _NotImplementedByCurrentBackendError("nchar", x) @_register_func(pipeable=True, dispatchable=True) def nzchar(x, keep_na: bool = False) -> Any: """Is the string non-zero length Args: x: the string to check keep_na: keep NA Returns: True if the string is non-zero length """ raise _NotImplementedByCurrentBackendError("nzchar", x) @_register_func(pipeable=True, dispatchable=True) def table( x, *more, exclude=None, use_na="no", dnn=None, deparse_level=1, ) -> Any: """Get the table of a vector Args: x: the vector to get the table of more: more vectors exclude: exclude these values use_na: use NA dnn: the names of the vectors deparse_level: the deparse level Returns: The table """ raise _NotImplementedByCurrentBackendError("table", x) @_register_func(pipeable=True, dispatchable=True) def tabulate(bin, nbins=None) -> Any: """Get the table of a vector Args: bin: the vector to get the table of nbins: the number of bins Returns: An integer valued 'integer' vector (without names). There is a bin for each of the values '1, ..., nbins' """ raise _NotImplementedByCurrentBackendError("tabulate", bin) @_register_func(pipeable=True, dispatchable=True) def is_atomic(x) -> Any: """Is the object atomic Args: x: the object to check Returns: True if the object is atomic """ raise _NotImplementedByCurrentBackendError("is_atomic", x) @_register_func(pipeable=True, dispatchable=True) def is_double(x) -> Any: """Is the object a double Args: x: the object to check Returns: True if the object is a double """ raise _NotImplementedByCurrentBackendError("is_double", x) @_register_func(pipeable=True, dispatchable=True) def is_element(x, y) -> Any: """Is the object an element of the table Args: x: the object to check y: the pool to check Returns: True if the object is an element of the pool """ raise _NotImplementedByCurrentBackendError("is_element", x) is_in = is_element @_register_func(pipeable=True, dispatchable=True) def is_integer(x) -> Any: """Is the object an integer Args: x: the object to check Returns: True if the object is an integer """ raise _NotImplementedByCurrentBackendError("is_integer", x) @_register_func(pipeable=True, dispatchable=True) def is_numeric(x) -> Any: """Is the object numeric Args: x: the object to check Returns: True if the object is numeric """ raise _NotImplementedByCurrentBackendError("is_numeric", x) @_register_func(pipeable=True, dispatchable=True) def any_(x, na_rm: bool = False) -> Any: """Is any element true Args: x: the vector to check na_rm: remove NA Returns: True if any element is true """ raise _NotImplementedByCurrentBackendError("any", x) @_register_func(pipeable=True, dispatchable=True) def all_(x, na_rm: bool = False) -> Any: """Are all elements true Args: x: the vector to check na_rm: remove NA Returns: True if all elements are true """ raise _NotImplementedByCurrentBackendError("all", x) @_register_func(pipeable=True, dispatchable=True) def acos(x) -> Any: """Get the inverse cosine Args: x: the value to get the inverse cosine of Returns: The inverse cosine """ raise _NotImplementedByCurrentBackendError("acos", x) @_register_func(pipeable=True, dispatchable=True) def acosh(x) -> Any: """Get the inverse hyperbolic cosine Args: x: the value to get the inverse hyperbolic cosine of Returns: The inverse hyperbolic cosine """ raise _NotImplementedByCurrentBackendError("acosh", x) @_register_func(pipeable=True, dispatchable=True) def asin(x) -> Any: """Get the inverse sine Args: x: the value to get the inverse sine of Returns: The inverse sine """ raise _NotImplementedByCurrentBackendError("asin", x) @_register_func(pipeable=True, dispatchable=True) def asinh(x) -> Any: """Get the inverse hyperbolic sine Args: x: the value to get the inverse hyperbolic sine of Returns: The inverse hyperbolic sine """ raise _NotImplementedByCurrentBackendError("asinh", x) @_register_func(pipeable=True, dispatchable=True) def atan(x) -> Any: """Get the inverse tangent Args: x: the value to get the inverse tangent of Returns: The inverse tangent """ raise _NotImplementedByCurrentBackendError("atan", x) @_register_func(pipeable=True, dispatchable=True) def atanh(x) -> Any: """Get the inverse hyperbolic tangent Args: x: the value to get the inverse hyperbolic tangent of Returns: The inverse hyperbolic tangent """ raise _NotImplementedByCurrentBackendError("atanh", x) @_register_func(pipeable=True, dispatchable=True) def cos(x) -> Any: """Get the cosine Args: x: the value to get the cosine of Returns: The cosine """ raise _NotImplementedByCurrentBackendError("cos", x) @_register_func(pipeable=True, dispatchable=True) def cosh(x) -> Any: """Get the hyperbolic cosine Args: x: the value to get the hyperbolic cosine of Returns: The hyperbolic cosine """ raise _NotImplementedByCurrentBackendError("cosh", x) @_register_func(pipeable=True, dispatchable=True) def cospi(x) -> Any: """Get the cosine of pi times x Args: x: the value to get the cosine of pi times x of Returns: The cosine of pi times x """ raise _NotImplementedByCurrentBackendError("cospi", x) @_register_func(pipeable=True, dispatchable=True) def sin(x) -> Any: """Get the sine Args: x: the value to get the sine of Returns: The sine """ raise _NotImplementedByCurrentBackendError("sin", x) @_register_func(pipeable=True, dispatchable=True) def sinh(x) -> Any: """Get the hyperbolic sine Args: x: the value to get the hyperbolic sine of Returns: The hyperbolic sine """ raise _NotImplementedByCurrentBackendError("sinh", x) @_register_func(pipeable=True, dispatchable=True) def sinpi(x) -> Any: """Get the sine of pi times x Args: x: the value to get the sine of pi times x of Returns: The sine of pi times x """ raise _NotImplementedByCurrentBackendError("sinpi", x) @_register_func(pipeable=True, dispatchable=True) def tan(x) -> Any: """Get the tangent Args: x: the value to get the tangent of Returns: The tangent """ raise _NotImplementedByCurrentBackendError("tan", x) @_register_func(pipeable=True, dispatchable=True) def tanh(x) -> Any: """Get the hyperbolic tangent Args: x: the value to get the hyperbolic tangent of Returns: The hyperbolic tangent """ raise _NotImplementedByCurrentBackendError("tanh", x) @_register_func(pipeable=True, dispatchable=True) def tanpi(x) -> Any: """Get the tangent of pi times x Args: x: the value to get the tangent of pi times x of Returns: The tangent of pi times x """ raise _NotImplementedByCurrentBackendError("tanpi", x) @_register_func(pipeable=True, dispatchable=True) def atan2(y, x) -> Any: """Get the inverse tangent of y/x Args: y: the numerator x: the denominator Returns: The inverse tangent of y/x """ raise _NotImplementedByCurrentBackendError("atan2", x) @_register_func(pipeable=True, dispatchable=True) def append(x, values, after: int = -1) -> Any: """Append values to the vector Args: x: the vector to append to values: the values to append after: the index to append after Returns: The vector with the values appended """ raise _NotImplementedByCurrentBackendError("append", x) @_register_func(pipeable=True, dispatchable=True) def colnames(x, nested: bool = True) -> Any: """Get the column names Args: x: the data frame to get the column names of nested: whether x is a nested data frame Returns: The column names """ raise _NotImplementedByCurrentBackendError("colnames", x) @_register_func(pipeable=True, dispatchable=True) def set_colnames(x, names, nested: bool = True) -> Any: """Set the column names Args: x: the data frame to set the column names of names: the column names to set nested: whether the frame are nested Returns: The data frame with the column names set """ raise _NotImplementedByCurrentBackendError("set_colnames", x) @_register_func(pipeable=True, dispatchable=True) def rownames(x) -> Any: """Get the row names Args: x: the data frame to get the row names of Returns: The row names """ raise _NotImplementedByCurrentBackendError("rownames", x) @_register_func(pipeable=True, dispatchable=True) def set_rownames(x, names) -> Any: """Set the row names Args: x: the data frame to set the row names of names: the row names to set Returns: The data frame with the row names set """ raise _NotImplementedByCurrentBackendError("set_rownames", x) @_register_func(pipeable=True, dispatchable=True) def dim(x, nested: bool = True) -> Any: """Get the dimensions Args: x: the data frame to get the dimensions of nested: whether x is a nested data frame Returns: The dimensions """ raise _NotImplementedByCurrentBackendError("dim", x) @_register_func(pipeable=True, dispatchable=True) def diag(x, nrow=None, ncol=None) -> Any: """Get the diagonal of a matrix Args: x: the matrix to get the diagonal of nrow: the number of rows ncol: the number of columns Returns: The diagonal of the matrix """ raise _NotImplementedByCurrentBackendError("diag", x) @_register_func(pipeable=True, dispatchable=True) def duplicated(x, incomparables=None, from_last: bool = False) -> Any: """Get the duplicated values Args: x: the vector to get the duplicated values of incomparables: the incomparables from_last: whether to search from the last Returns: The duplicated values """ raise _NotImplementedByCurrentBackendError("duplicated", x) @_register_func(pipeable=True, dispatchable=True) def intersect(x, y) -> Any: """Get the intersection of two vectors Args: x: the first vector y: the second vector Returns: The intersection of the two vectors """ raise _NotImplementedByCurrentBackendError("intersect", x) @_register_func(pipeable=True, dispatchable=True) def ncol(x, nested: bool = True) -> Any: """Get the number of columns Args: x: the data frame to get the number of columns of nested: whether x is a nested data frame Returns: The number of columns """ raise _NotImplementedByCurrentBackendError("ncol", x) @_register_func(pipeable=True, dispatchable=True) def nrow(x) -> Any: """Get the number of rows Args: x: the data frame to get the number of rows of Returns: The number of rows """ raise _NotImplementedByCurrentBackendError("nrow", x) @_register_func(pipeable=True, dispatchable=True) def proportions(x, margin: int = 1) -> Any: """Get the proportion table Args: x: the data frame to get the proportion table of margin: the margin Returns: The proportion table """ raise _NotImplementedByCurrentBackendError("proportions", x) @_register_func(pipeable=True, dispatchable=True) def setdiff(x, y) -> Any: """Get the difference of two vectors Args: x: the first vector y: the second vector Returns: The difference of the two vectors """ raise _NotImplementedByCurrentBackendError("setdiff", x) @_register_func(pipeable=True, dispatchable=True) def setequal(x, y) -> Any: """Check if two vectors are equal Args: x: the first vector y: the second vector Returns: Whether the two vectors are equal """ raise _NotImplementedByCurrentBackendError("setequal", x) @_register_func(pipeable=True, dispatchable=True) def unique(x) -> Any: """Get the unique values Args: x: the vector to get the unique values of Returns: The unique values """ raise _NotImplementedByCurrentBackendError("unique", x) @_register_func(pipeable=True, dispatchable=True) def t(x) -> Any: """Get the transpose Args: x: the matrix to get the transpose of Returns: The transpose """ raise _NotImplementedByCurrentBackendError("t", x) @_register_func(pipeable=True, dispatchable=True) def union(x, y) -> Any: """Get the union of two vectors Args: x: the first vector y: the second vector Returns: The union of the two vectors """ raise _NotImplementedByCurrentBackendError("union", x) @_register_func(pipeable=True, dispatchable=True) def max_col(x, ties_method: str = "random", nested: bool = True) -> Any: """Get the maximum column Args: x: the data frame to get the maximum column of ties_method: the ties method nested: whether x is a nested data frame Returns: The maximum column """ raise _NotImplementedByCurrentBackendError("max_col", x) @_register_func(pipeable=True, dispatchable=True) def complete_cases(x) -> Any: """Get the complete cases Args: x: the data frame to get the complete cases of Returns: The complete cases """ raise _NotImplementedByCurrentBackendError("complete_cases", x) @_register_func(pipeable=True, dispatchable=True) def head(x, n: int = 6) -> Any: """Get the first n rows Args: x: the data frame to get the first n rows of n: the number of rows to get Returns: The first n rows """ raise _NotImplementedByCurrentBackendError("head", x) @_register_func(pipeable=True, dispatchable=True) def tail(x, n: int = 6) -> Any: """Get the last n rows Args: x: the data frame to get the last n rows of n: the number of rows to get Returns: The last n rows """ raise _NotImplementedByCurrentBackendError("tail", x) @_register_func(pipeable=True, dispatchable=True) def which(x) -> Any: """Get the indices of the non-zero values Args: x: the vector to get the indices of the non-zero values of Returns: The indices of the non-zero values """ raise _NotImplementedByCurrentBackendError("which", x) @_register_func(pipeable=True, dispatchable=True) def which_max(x) -> Any: """Get the index of the maximum value Args: x: the vector to get the index of the maximum value of Returns: The index of the maximum value """ raise _NotImplementedByCurrentBackendError("which_max", x) @_register_func(pipeable=True, dispatchable=True) def which_min(x) -> Any: """Get the index of the minimum value Args: x: the vector to get the index of the minimum value of Returns: The index of the minimum value """ raise _NotImplementedByCurrentBackendError("which_min", x) ================================================ FILE: datar/apis/dplyr.py ================================================ # import the variables with _ so that they are not imported by * from __future__ import annotations as _ from typing import ( Any, Callable as _Callable, Sequence as _Sequence, TypeVar as _TypeVar, ) from pipda import ( register_verb as _register_verb, register_func as _register_func, ) from ..core.verb_env import get_verb_ast_fallback as _get_verb_ast_fallback from ..core.defaults import f as _f_symbolic from ..core.utils import ( NotImplementedByCurrentBackendError as _NotImplementedByCurrentBackendError, ) from .base import intersect, setdiff, setequal, union # noqa: F401 T = _TypeVar("T") @_register_verb(dependent=True, ast_fallback=_get_verb_ast_fallback("pick")) def pick(_data: T, *args) -> T: """Pick columns by name The original API: https://dplyr.tidyverse.org/reference/pick.html Args: _data: The dataframe *args: The columns to pick Returns: The picked dataframe """ raise _NotImplementedByCurrentBackendError("pick", _data) @_register_verb(dependent=True, ast_fallback=_get_verb_ast_fallback("across")) def across(_data: T, *args, _names=None, **kwargs) -> T: """Apply the same transformation to multiple columns The original API: https://dplyr.tidyverse.org/reference/across.html Examples: # >>> iris >> mutate(across(c(f.Sepal_Length, f.Sepal_Width), round)) Sepal_Length Sepal_Width Petal_Length Petal_Width Species 0 5.0 4.0 1.4 0.2 setosa 1 5.0 3.0 1.4 0.2 setosa .. ... ... ... ... ... >>> iris >> group_by(f.Species) >> summarise( >>> across(starts_with("Sepal"), mean) >>> ) Species Sepal_Length Sepal_Width 0 setosa 5.006 3.428 1 versicolor 5.936 2.770 2 virginica 6.588 2.974 Args: _data: The dataframe. *args: If given, the first 2 elements should be columns and functions apply to each of the selected columns. The rest of them will be the arguments for the functions. _names: A glue specification that describes how to name the output columns. This can use `{_col}` to stand for the selected column name, and `{_fn}` to stand for the name of the function being applied. The default (None) is equivalent to `{_col}` for the single function case and `{_col}_{_fn}` for the case where a list is used for _fns. In such a case, `{_fn}` is 0-based. To use 1-based index, use `{_fn1}` _fn_context: Defines the context to evaluate the arguments for functions if they are plain functions. Note that registered functions will use its own context **kwargs: Keyword arguments for the functions Returns: A dataframe with one column for each column and each function. """ raise _NotImplementedByCurrentBackendError("across", _data) @_register_verb(dependent=True, ast_fallback=_get_verb_ast_fallback("c_across")) def c_across(_data: T, _cols=None) -> T: """Apply the same transformation to multiple columns rowwisely Args: _data: The dataframe _cols: The columns Returns: A rowwise tibble """ raise _NotImplementedByCurrentBackendError("c_across", _data) @_register_verb(dependent=True, ast_fallback=_get_verb_ast_fallback("if_any")) def if_any(_data, *args, _names=None, **kwargs) -> Any: """Apply the same predicate function to a selection of columns and combine the results True if any element is True. See Also: [`across()`](datar.dplyr.across.across) """ raise _NotImplementedByCurrentBackendError("if_any", _data) @_register_verb(dependent=True, ast_fallback=_get_verb_ast_fallback("if_all")) def if_all(_data, *args, _names=None, **kwargs) -> Any: """Apply the same predicate function to a selection of columns and combine the results True if all elements are True. See Also: [`across()`](datar.dplyr.across.across) """ raise _NotImplementedByCurrentBackendError("if_all", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("symdiff")) def symdiff(x: T, y: T) -> T: """Get the symmetric difference of two dataframes It computes the symmetric difference, i.e. all rows in x that aren't in y and all rows in y that aren't in x. The original API: https://dplyr.tidyverse.org/reference/setops.html Args: x: A dataframe y: A dataframe Returns: The symmetric difference of x and y """ raise _NotImplementedByCurrentBackendError("symdiff", x) @_register_verb(ast_fallback=_get_verb_ast_fallback("arrange")) def arrange(_data, *args, _by_group=False, **kwargs) -> Any: """orders the rows of a data frame by the values of selected columns. The original API: https://dplyr.tidyverse.org/reference/arrange.html Args: _data: A data frame *series: Variables, or functions of variables. Use desc() to sort a variable in descending order. _by_group: If TRUE, will sort first by grouping variable. Applies to grouped data frames only. **kwargs: Name-value pairs that apply with mutate Returns: An object of the same type as _data. The output has the following properties: All rows appear in the output, but (usually) in a different place. Columns are not modified. Groups are not modified. Data frame attributes are preserved. """ raise _NotImplementedByCurrentBackendError("arrange", _data) @_register_func(pipeable=True, dispatchable=True) def bind_rows(*data, _id=None, _copy: bool = True, **kwargs) -> Any: """Bind rows of give dataframes Original APIs https://dplyr.tidyverse.org/reference/bind.html Args: *data: Dataframes to combine _id: The name of the id columns _copy: If `False`, do not copy data unnecessarily. Original API does not support this. This argument will be passed by to `pandas.concat()` as `copy` argument. **kwargs: A mapping of dataframe, keys will be used as _id col. Returns: The combined dataframe """ raise _NotImplementedByCurrentBackendError("bind_rows") @_register_func(pipeable=True, dispatchable=True) def bind_cols(*data, _name_repair="unique", _copy: bool = True) -> Any: """Bind columns of give dataframes Note that unlike `dplyr`, mismatched dimensions are allowed and missing rows will be filled with `NA`s Args: *data: Dataframes to bind _name_repair: treatment of problematic column names: - "minimal": No name repair or checks, beyond basic existence, - "unique": Make sure names are unique and not empty, - "check_unique": (default value), no name repair, but check they are unique, - "universal": Make the names unique and syntactic - a function: apply custom name repair _copy: If `False`, do not copy data unnecessarily. Original API does not support this. This argument will be passed by to `pandas.concat()` as `copy` argument. Returns: The combined dataframe """ raise _NotImplementedByCurrentBackendError("bind_cols") # context @_register_func(plain=True) def cur_column(_data, _name) -> Any: """Get the current column Args: _data: The dataframe _name: The column name Returns: The current column """ raise _NotImplementedByCurrentBackendError("cur_column") @_register_verb(dependent=True, ast_fallback=_get_verb_ast_fallback("cur_data")) def cur_data(_data) -> Any: """Get the current dataframe Args: _data: The dataframe Returns: The current dataframe """ raise _NotImplementedByCurrentBackendError("cur_data", _data) @_register_verb(dependent=True, ast_fallback=_get_verb_ast_fallback("n")) def n(_data) -> Any: """Get the current group size Args: _data: The dataframe Returns: The number of rows """ raise _NotImplementedByCurrentBackendError("n", _data) @_register_verb( dependent=True, ast_fallback=_get_verb_ast_fallback("cur_data_all") ) def cur_data_all(_data) -> Any: """Get the current data for the current group including the grouping variables Args: _data: The dataframe Returns: The current dataframe """ raise _NotImplementedByCurrentBackendError("cur_data_all", _data) @_register_verb(dependent=True, ast_fallback=_get_verb_ast_fallback("cur_group")) def cur_group(_data) -> Any: """Get the current group Args: _data: The dataframe Returns: The current group """ raise _NotImplementedByCurrentBackendError("cur_group", _data) @_register_verb( dependent=True, ast_fallback=_get_verb_ast_fallback("cur_group_id") ) def cur_group_id(_data) -> Any: """Get the current group id Args: _data: The dataframe Returns: The current group id """ raise _NotImplementedByCurrentBackendError("cur_group_id", _data) @_register_verb( dependent=True, ast_fallback=_get_verb_ast_fallback("cur_group_rows") ) def cur_group_rows(_data) -> Any: """Get the current group row indices Args: _data: The dataframe Returns: The current group rows """ raise _NotImplementedByCurrentBackendError("cur_group_rows", _data) # count_tally @_register_verb(ast_fallback=_get_verb_ast_fallback("count")) def count( _data, *args, wt=None, sort=False, name=None, _drop=None, **kwargs, ) -> Any: """Count the number of rows in each group Original API: https://dplyr.tidyverse.org/reference/count.html Args: _data: A data frame *args: Variables, or functions of variables. Use desc() to sort a variable in descending order. wt: A variable or function of variables to weight by. sort: If TRUE, the result will be sorted by the count. name: The name of the count column. _drop: If `False`, keep grouping variables even if they are not used. Original API does not support this. **kwargs: Name-value pairs that apply with mutate Returns: A data frame with the same number of rows as the number of groups. The output has the following properties: All rows appear in the output, but (usually) in a different place. Columns are not modified. Groups are not modified. Data frame attributes are preserved. """ raise _NotImplementedByCurrentBackendError("count", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("tally")) def tally(_data, wt=None, sort=False, name=None) -> Any: """Count the number of rows in each group Original API: https://dplyr.tidyverse.org/reference/count.html Args: _data: A data frame wt: A variable or function of variables to weight by. sort: If TRUE, the result will be sorted by the count. name: The name of the count column. Returns: A data frame with the same number of rows as the number of groups. The output has the following properties: All rows appear in the output, but (usually) in a different place. Columns are not modified. Groups are not modified. Data frame attributes are preserved. """ raise _NotImplementedByCurrentBackendError("tally", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("add_count")) def add_count(_data, *args, wt=None, sort=False, name="n", **kwargs) -> Any: """Add a count column to a data frame Original API: https://dplyr.tidyverse.org/reference/count.html Args: _data: A data frame *args: Variables, or functions of variables. Use desc() to sort a variable in descending order. wt: A variable or function of variables to weight by. sort: If TRUE, the result will be sorted by the count. name: The name of the count column. **kwargs: Name-value pairs that apply with mutate Returns: A data frame with the same number of rows as the number of groups. The output has the following properties: All rows appear in the output, but (usually) in a different place. Columns are not modified. Groups are not modified. Data frame attributes are preserved. """ raise _NotImplementedByCurrentBackendError("add_count", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("add_tally")) def add_tally(_data, wt=None, sort=False, name="n") -> Any: """Add a count column to a data frame Original API: https://dplyr.tidyverse.org/reference/count.html Args: _data: A data frame wt: A variable or function of variables to weight by. sort: If TRUE, the result will be sorted by the count. name: The name of the count column. Returns: A data frame with the same number of rows as the number of groups. The output has the following properties: All rows appear in the output, but (usually) in a different place. Columns are not modified. Groups are not modified. Data frame attributes are preserved. """ raise _NotImplementedByCurrentBackendError("add_tally", _data) # desc @_register_func(pipeable=True, dispatchable=True) def desc(x) -> Any: """Transform a vector into a format that will be sorted in descending order This is useful within arrange(). The original API: https://dplyr.tidyverse.org/reference/desc.html Args: x: vector to transform Returns: The descending order of x """ raise _NotImplementedByCurrentBackendError("desc", x) # filter @_register_verb(ast_fallback=_get_verb_ast_fallback("filter_")) def filter_(_data, *conditions, _preserve: bool = False) -> Any: """Filter a data frame based on conditions The original API: https://dplyr.tidyverse.org/reference/filter.html Args: _data: A data frame *conditions: Conditions to filter by. _preserve: If `True`, keep grouping variables even if they are not used. Returns: The subset dataframe """ raise _NotImplementedByCurrentBackendError("filter", _data) # distinct @_register_verb(ast_fallback=_get_verb_ast_fallback("distinct")) def distinct( _data, *args, keep_all: bool = False, _preserve: bool = False, ) -> Any: """Filter a data frame based on conditions The original API: https://dplyr.tidyverse.org/reference/distinct.html Args: _data: A data frame *args: Variables to filter by. keep_all: If `True`, keep all rows that match. _preserve: If `True`, keep grouping variables even if they are not used. Returns: The subset dataframe """ raise _NotImplementedByCurrentBackendError("distinct", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("n_distinct")) def n_distinct(_data, na_rm: bool = True) -> Any: """Count the number of distinct values The original API: https://dplyr.tidyverse.org/reference/distinct.html Args: _data: A data frame na_rm: If `True`, remove missing values before counting. Returns: The number of distinct values """ raise _NotImplementedByCurrentBackendError("n_distinct", _data) # glimpse @_register_verb(ast_fallback=_get_verb_ast_fallback("glimpse")) def glimpse(_data, width: int = None, formatter=None) -> Any: """Display a summary of a data frame The original API: https://dplyr.tidyverse.org/reference/glimpse.html Args: _data: A data frame width: Width of output, defaults to the width of the console. formatter: A single-dispatch function to format a single element. """ raise _NotImplementedByCurrentBackendError("glimpse", _data) # slice @_register_verb(ast_fallback=_get_verb_ast_fallback("slice_")) def slice_(_data, *args, _preserve: bool = False) -> Any: """Extract rows by their position The original API: https://dplyr.tidyverse.org/reference/slice.html Args: _data: A data frame *args: Positions to extract. _preserve: If `True`, keep grouping variables even if they are not used. Returns: The subset dataframe """ raise _NotImplementedByCurrentBackendError("slice", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("slice_head")) def slice_head(_data, n: int = None, prop: float = None) -> Any: """Extract the first rows The original API: https://dplyr.tidyverse.org/reference/slice.html Args: _data: A data frame n: Number of rows to extract. prop: Proportion of rows to extract. Returns: The subset dataframe """ raise _NotImplementedByCurrentBackendError("slice_head", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("slice_tail")) def slice_tail(_data, n: int = None, prop: float = None) -> Any: """Extract the last rows The original API: https://dplyr.tidyverse.org/reference/slice.html Args: _data: A data frame n: Number of rows to extract. prop: Proportion of rows to extract. Returns: The subset dataframe """ raise _NotImplementedByCurrentBackendError("slice_tail", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("slice_sample")) def slice_sample( _data, n: int = 1, prop: float = None, weight_by=None, replace: bool = False, ) -> Any: """Extract rows by sampling The original API: https://dplyr.tidyverse.org/reference/slice.html Args: _data: A data frame n: Number of rows to extract. prop: Proportion of rows to extract. weight_by: A variable or function of variables to weight by. replace: If `True`, sample with replacement. Returns: The subset dataframe """ raise _NotImplementedByCurrentBackendError("slice_sample", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("slice_min")) def slice_min( _data, order_by, n: int = 1, prop: float = None, with_ties: bool | str = None, ) -> Any: """Extract rows with the minimum value The original API: https://dplyr.tidyverse.org/reference/slice.html Args: _data: A data frame order_by: A variable or function of variables to order by. n: Number of rows to extract. prop: Proportion of rows to extract. with_ties: If `True`, extract all rows with the minimum value. If "first", extract the first row with the minimum value. If "last", extract the last row with the minimum value. Returns: The subset dataframe """ raise _NotImplementedByCurrentBackendError("slice_min", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("slice_max")) def slice_max( _data, order_by, n: int = 1, prop: float = None, with_ties: bool | str = None, ) -> Any: """Extract rows with the maximum value The original API: https://dplyr.tidyverse.org/reference/slice.html Args: _data: A data frame order_by: A variable or function of variables to order by. n: Number of rows to extract. prop: Proportion of rows to extract. with_ties: If `True`, extract all rows with the maximum value. If "first", extract the first row with the maximum value. If "last", extract the last row with the maximum value. Returns: The subset dataframe """ raise _NotImplementedByCurrentBackendError("slice_max", _data) # misc funs @_register_func(pipeable=True, dispatchable=True) def between(x, left, right, inclusive: str = "both") -> Any: """Check if a value is between two other values The original API: https://dplyr.tidyverse.org/reference/between.html Args: x: A value left: The left bound right: The right bound inclusive: Either `both`, `neither`, `left` or `right`. Include boundaries. Whether to set each bound as closed or open. Returns: A bool value if `x` is scalar, otherwise an array of boolean values Note that it will be always False when NA appears in x, left or right. """ raise _NotImplementedByCurrentBackendError("between") @_register_func(pipeable=True, dispatchable=True) def cummean(x, na_rm: bool = False) -> Any: """Cumulative mean The original API: https://dplyr.tidyverse.org/reference/cumall.html Args: x: A numeric vector na_rm: If `True`, remove missing values before computing. Returns: An array of cumulative means """ raise _NotImplementedByCurrentBackendError("cummean", x) @_register_func(pipeable=True, dispatchable=True) def cumall(x) -> Any: """Get cumulative bool. All cases after first False The original API: https://dplyr.tidyverse.org/reference/cumall.html Args: x: A logical vector Returns: An array of cumulative conjunctions """ raise _NotImplementedByCurrentBackendError("cumall", x) @_register_func(pipeable=True, dispatchable=True) def cumany(x) -> Any: """Get cumulative bool. All cases after first True The original API: https://dplyr.tidyverse.org/reference/cumany.html Args: x: A logical vector Returns: An array of cumulative disjunctions """ raise _NotImplementedByCurrentBackendError("cumany", x) @_register_func(pipeable=True, dispatchable=True) def coalesce(x, *replace) -> Any: """Replace missing values with the first non-missing value The original API: https://dplyr.tidyverse.org/reference/coalesce.html Args: x: A vector *replace: Values to replace missing values with. Returns: An array of values """ raise _NotImplementedByCurrentBackendError("coalesce") @_register_func(pipeable=True, dispatchable=True) def consecutive_id(x, *args) -> _Sequence[int]: """Generate consecutive ids The original API: https://dplyr.tidyverse.org/reference/consecutive_id.html Args: x: A vector *args: Other vectors Returns: A sequence of consecutive ids """ raise _NotImplementedByCurrentBackendError("consecutive_id", x) @_register_func(pipeable=True, dispatchable=True) def na_if(x, value) -> Any: """Replace values with missing values The original API: https://dplyr.tidyverse.org/reference/na_if.html Args: x: A vector value: Values to replace with missing values. Returns: An array of values """ raise _NotImplementedByCurrentBackendError("na_if") @_register_func(pipeable=True, dispatchable=True) def near(x, y, tol: float = 1e-8) -> Any: """Check if values are approximately equal The original API: https://dplyr.tidyverse.org/reference/near.html Args: x: A numeric vector y: A numeric vector tol: Tolerance Returns: An array of boolean values """ raise _NotImplementedByCurrentBackendError("near") @_register_func(pipeable=True, dispatchable=True) def nth(x, n, order_by=None, default=None) -> Any: """Extract the nth element of a vector The original API: https://dplyr.tidyverse.org/reference/nth.html Args: x: A vector n: The index of the element to extract. order_by: A variable or function of variables to order by. default: A default value to return if `n` is out of bounds. Returns: A value """ raise _NotImplementedByCurrentBackendError("nth", x) @_register_func(pipeable=True, dispatchable=True) def first(x, order_by=None, default=None) -> Any: """Extract the first element of a vector The original API: https://dplyr.tidyverse.org/reference/nth.html Args: x: A vector order_by: A variable or function of variables to order by. default: A default value to return if `x` is empty. Returns: A value """ raise _NotImplementedByCurrentBackendError("first", x) @_register_func(pipeable=True, dispatchable=True) def last(x, order_by=None, default=None) -> Any: """Extract the last element of a vector The original API: https://dplyr.tidyverse.org/reference/nth.html Args: x: A vector order_by: A variable or function of variables to order by. default: A default value to return if `x` is empty. Returns: A value """ raise _NotImplementedByCurrentBackendError("last", x) # group_by @_register_verb(ast_fallback=_get_verb_ast_fallback("group_by")) def group_by(_data, *args, _add: bool = False, _drop: bool = None) -> Any: """Create a grouped frame The original API: https://dplyr.tidyverse.org/reference/group_by.html Args: _data: A data frame *args: A variable or function of variables to group by. _add: If `True`, add grouping variables to an existing group. _drop: If `True`, drop grouping variables from the output. Returns: A grouped frame """ raise _NotImplementedByCurrentBackendError("group_by", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("ungroup")) def ungroup(_data, *cols: str | int) -> Any: """Remove grouping variables The original API: https://dplyr.tidyverse.org/reference/ungroup.html Args: _data: A grouped frame *cols: Columns to remove grouping variables from. Returns: A data frame """ raise _NotImplementedByCurrentBackendError("ungroup", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("rowwise")) def rowwise(_data, *cols: str | int) -> Any: """Create a rowwise frame The original API: https://dplyr.tidyverse.org/reference/rowwise.html Args: _data: A data frame *cols: Columns to make rowwise. Returns: A rowwise frame """ raise _NotImplementedByCurrentBackendError("rowwise", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("group_by_drop_default")) def group_by_drop_default(_data) -> Any: """Get the default value of `_drop` of a frame The original API: https://dplyr.tidyverse.org/reference/group_by.html Args: _data: A data frame Returns: A bool value """ raise _NotImplementedByCurrentBackendError("group_by_drop_default", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("group_vars")) def group_vars(_data) -> Any: """Get the grouping variables of a frame The original API: https://dplyr.tidyverse.org/reference/group_vars.html Args: _data: A grouped frame Returns: A list of grouping variables """ raise _NotImplementedByCurrentBackendError("group_vars", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("group_indices")) def group_indices(_data) -> Any: """Get the group indices of a frame The original API: https://dplyr.tidyverse.org/reference/group_indices.html Args: _data: A grouped frame Returns: A list of group indices """ raise _NotImplementedByCurrentBackendError("group_indices", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("group_keys")) def group_keys(_data) -> Any: """Get the group keys of a frame The original API: https://dplyr.tidyverse.org/reference/group_keys.html Args: _data: A grouped frame Returns: A list of group keys """ raise _NotImplementedByCurrentBackendError("group_keys", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("group_size")) def group_size(_data) -> Any: """Get the group sizes of a frame The original API: https://dplyr.tidyverse.org/reference/group_size.html Args: _data: A grouped frame Returns: A list of group sizes """ raise _NotImplementedByCurrentBackendError("group_size", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("group_rows")) def group_rows(_data) -> Any: """Get the group rows of a frame The original API: https://dplyr.tidyverse.org/reference/group_rows.html Args: _data: A grouped frame Returns: A list of group rows """ raise _NotImplementedByCurrentBackendError("group_rows", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("group_cols")) def group_cols(_data) -> Any: """Get the group columns of a frame The original API: https://dplyr.tidyverse.org/reference/group_cols.html Args: _data: A grouped frame Returns: A list of group columns """ raise _NotImplementedByCurrentBackendError("group_cols", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("group_data")) def group_data(_data) -> Any: """Get the group data of a frame The original API: https://dplyr.tidyverse.org/reference/group_data.html Args: _data: A grouped frame Returns: A list of group data """ raise _NotImplementedByCurrentBackendError("group_data", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("n_groups")) def n_groups(_data) -> int: """Get the number of groups of a frame The original API: https://dplyr.tidyverse.org/reference/n_groups.html Args: _data: A grouped frame Returns: An int value """ raise _NotImplementedByCurrentBackendError("n_groups", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("group_map")) def group_map(_data, _f, *args, _keep: bool = False, **kwargs) -> Any: """Apply a function to each group The original API: https://dplyr.tidyverse.org/reference/group_map.html Args: _data: A grouped frame _f: A function to apply to each group. *args: Additional arguments to pass to `func`. _keep: If `True`, keep the grouping variables in the output. **kwargs: Additional keyword arguments to pass to `func`. Returns: A list of results """ raise _NotImplementedByCurrentBackendError("group_map", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("group_modify")) def group_modify(_data, _f, *args, _keep: bool = False, **kwargs) -> Any: """Apply a function to each group The original API: https://dplyr.tidyverse.org/reference/group_modify.html Args: _data: A grouped frame _f: A function to apply to each group. *args: Additional arguments to pass to `func`. _keep: If `True`, keep the grouping variables in the output. **kwargs: Additional keyword arguments to pass to `func`. Returns: A data frame """ raise _NotImplementedByCurrentBackendError("group_modify", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("group_split")) def group_split(_data, *args, _keep: bool = False, **kwargs) -> Any: """Split a grouped frame into a list of data frames The original API: https://dplyr.tidyverse.org/reference/group_split.html Args: _data: A grouped frame *args: Additional arguments to pass to `func`. _keep: If `True`, keep the grouping variables in the output. **kwargs: Additional keyword arguments to pass to `func`. Returns: A list of data frames """ raise _NotImplementedByCurrentBackendError("group_split", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("group_trim")) def group_trim(_data, _drop=None) -> Any: """Remove empty groups The original API: https://dplyr.tidyverse.org/reference/group_trim.html Args: _data: A grouped frame _drop: See `group_by`. Returns: A grouped frame """ raise _NotImplementedByCurrentBackendError("group_trim", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("group_walk")) def group_walk(_data, _f, *args, _keep: bool = False, **kwargs) -> Any: """Apply a function to each group The original API: https://dplyr.tidyverse.org/reference/group_walk.html Args: _data: A grouped frame _f: A function to apply to each group. *args: Additional arguments to pass to `func`. **kwargs: Additional keyword arguments to pass to `func`. Returns: A grouped frame """ raise _NotImplementedByCurrentBackendError("group_walk", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("with_groups")) def with_groups(_data, _groups, _func, *args, **kwargs) -> Any: """Modify the grouping variables for a single operation. Args: _data: A data frame _groups: columns passed by group_by Use None to temporarily ungroup. _func: Function to apply to regrouped data. Returns: The new data frame with operations applied. """ raise _NotImplementedByCurrentBackendError("with_groups", _data) @_register_func(pipeable=True, dispatchable=True) def if_else(condition, true, false, missing=None) -> Any: """Where condition is TRUE, the matching value from true, where it's FALSE, the matching value from false, otherwise missing. Note that NAs will be False in condition if missing is not specified Args: condition: the conditions true: and false: Values to use for TRUE and FALSE values of condition. They must be either the same length as condition, or length 1. missing: If not None, will be used to replace missing values Returns: A series with values replaced. """ raise _NotImplementedByCurrentBackendError("if_else") @_register_func(pipeable=True, dispatchable=True) def case_match(_x: T, *args, _default=None, _dtypes=None) -> T: """This function allows you to vectorise multiple `switch()` statements. Each case is evaluated sequentially and the first match for each element determines the corresponding value in the output vector. If no cases match, the `_default` is used. The original API: https://dplyr.tidyverse.org/reference/case_match.html Args: _x: A vector *args: A series of condition-value pairs _default: The default value _dtypes: The data types of the output """ raise _NotImplementedByCurrentBackendError("case_match", _x) @_register_func(pipeable=True, dispatchable=True) def case_when(cond, value, *more_cases) -> Any: """Vectorise multiple `if_else()` statements. Args: cond: A boolean vector value: A vector with values to replace *more_cases: A list of tuples (cond, value) Returns: A vector with values replaced. """ raise _NotImplementedByCurrentBackendError("case_when") # join @_register_verb(ast_fallback=_get_verb_ast_fallback("inner_join")) def inner_join( x, y, by=None, copy: bool = False, suffix: _Sequence[str] = ("_x", "_y"), keep: bool = False, na_matches: str = "na", multiple: str = "all", unmatched: str = "drop", relationship: str = None, ) -> Any: """Inner join two data frames by matching rows. The original API: https://dplyr.tidyverse.org/reference/join.html Args: x: A data frame y: A data frame by: A list of column names to join by. If None, use the intersection of the columns of x and y. copy: If True, always copy the data. suffix: A tuple of suffixes to apply to overlapping columns. keep: If True, keep the grouping variables in the output. na_matches: How should NA values be matched? "na": NA values are equal. "never": NA values are never matched. multiple: How should multiple matches be handled? "all": All matches are returned. "first": The first match is returned. "last": The last match is returned. "any": Any of the matched rows in y unmatched: How should unmatched keys that would result in dropped rows be handled? "drop": Drop unmatched keys. "error": Raise an error. relationship: The relationship between x and y. None: No expected relationship. "one_to_one": Each row in x matches at most one row in y. "one_to_many": Each row in x matches zero or more rows in y. "many_to_one": Each row in x matches at most one row in y. "many_to_many": Each row in x matches zero or more rows in y. Returns: A data frame """ raise _NotImplementedByCurrentBackendError("inner_join", x) @_register_verb(ast_fallback=_get_verb_ast_fallback("left_join")) def left_join( x, y, by=None, copy: bool = False, suffix: _Sequence[str] = ("_x", "_y"), keep: bool = False, na_matches: str = "na", multiple: str = "all", unmatched: str = "drop", relationship: str = None, ) -> Any: """Left join two data frames by matching rows. The original API: https://dplyr.tidyverse.org/reference/join.html Args: x: A data frame y: A data frame by: A list of column names to join by. If None, use the intersection of the columns of x and y. copy: If True, always copy the data. suffix: A tuple of suffixes to apply to overlapping columns. keep: If True, keep the grouping variables in the output. na_matches: How should NA values be matched? "na": NA values are equal. "never": NA values are never matched. multiple: How should multiple matches be handled? "all": All matches are returned. "first": The first match is returned. "last": The last match is returned. "any": Any of the matched rows in y unmatched: How should unmatched keys that would result in dropped rows be handled? "drop": Drop unmatched keys. "error": Raise an error. relationship: The relationship between x and y. None: No expected relationship. "one_to_one": Each row in x matches at most one row in y. "one_to_many": Each row in x matches zero or more rows in y. "many_to_one": Each row in x matches at most one row in y. "many_to_many": Each row in x matches zero or more rows in y. Returns: A data frame """ raise _NotImplementedByCurrentBackendError("left_join", x) @_register_verb(ast_fallback=_get_verb_ast_fallback("right_join")) def right_join( x, y, by=None, copy: bool = False, suffix: _Sequence[str] = ("_x", "_y"), keep: bool = False, na_matches: str = "na", multiple: str = "all", unmatched: str = "drop", relationship: str = None, ) -> Any: """Right join two data frames by matching rows. The original API: https://dplyr.tidyverse.org/reference/join.html Args: x: A data frame y: A data frame by: A list of column names to join by. If None, use the intersection of the columns of x and y. copy: If True, always copy the data. suffix: A tuple of suffixes to apply to overlapping columns. keep: If True, keep the grouping variables in the output. na_matches: How should NA values be matched? "na": NA values are equal. "never": NA values are never matched. multiple: How should multiple matches be handled? "all": All matches are returned. "first": The first match is returned. "last": The last match is returned. "any": Any of the matched rows in y unmatched: How should unmatched keys that would result in dropped rows be handled? "drop": Drop unmatched keys. "error": Raise an error. relationship: The relationship between x and y. None: No expected relationship. "one_to_one": Each row in x matches at most one row in y. "one_to_many": Each row in x matches zero or more rows in y. "many_to_one": Each row in x matches at most one row in y. "many_to_many": Each row in x matches zero or more rows in y. Returns: A data frame """ raise _NotImplementedByCurrentBackendError("right_join", x) @_register_verb(ast_fallback=_get_verb_ast_fallback("full_join")) def full_join( x, y, by=None, copy: bool = False, suffix: _Sequence[str] = ("_x", "_y"), keep: bool = False, na_matches: str = "na", multiple: str = "all", unmatched: str = "drop", relationship: str = None, ) -> Any: """Full join two data frames by matching rows. The original API: https://dplyr.tidyverse.org/reference/join.html Args: x: A data frame y: A data frame by: A list of column names to join by. If None, use the intersection of the columns of x and y. copy: If True, always copy the data. suffix: A tuple of suffixes to apply to overlapping columns. keep: If True, keep the grouping variables in the output. na_matches: How should NA values be matched? "na": NA values are equal. "never": NA values are never matched. multiple: How should multiple matches be handled? "all": All matches are returned. "first": The first match is returned. "last": The last match is returned. "any": Any of the matched rows in y unmatched: How should unmatched keys that would result in dropped rows be handled? "drop": Drop unmatched keys. "error": Raise an error. relationship: The relationship between x and y. None: No expected relationship. "one_to_one": Each row in x matches at most one row in y. "one_to_many": Each row in x matches zero or more rows in y. "many_to_one": Each row in x matches at most one row in y. "many_to_many": Each row in x matches zero or more rows in y. Returns: A data frame """ raise _NotImplementedByCurrentBackendError("full_join", x) @_register_verb(ast_fallback=_get_verb_ast_fallback("semi_join")) def semi_join( x, y, by=None, copy: bool = False, na_matches: str = "na", ) -> Any: """Semi join two data frames by matching rows. The original API: https://dplyr.tidyverse.org/reference/join.html Args: x: A data frame y: A data frame by: A list of column names to join by. If None, use the intersection of the columns of x and y. copy: If True, always copy the data. na_matches: How should NA values be matched? "na": NA values are equal. "never": NA values are never matched. Returns: A data frame """ raise _NotImplementedByCurrentBackendError("semi_join", x) @_register_verb(ast_fallback=_get_verb_ast_fallback("anti_join")) def anti_join( x, y, by=None, copy: bool = False, na_matches: str = "na", ) -> Any: """Anti join two data frames by matching rows. The original API: https://dplyr.tidyverse.org/reference/join.html Args: x: A data frame y: A data frame by: A list of column names to join by. If None, use the intersection of the columns of x and y. copy: If True, always copy the data. na_matches: How should NA values be matched? "na": NA values are equal. "never": NA values are never matched. Returns: A data frame """ raise _NotImplementedByCurrentBackendError("anti_join", x) @_register_verb(ast_fallback=_get_verb_ast_fallback("nest_join")) def nest_join( x, y, by=None, copy: bool = False, keep: bool = False, name=None, na_matches: str = "na", unmatched: str = "drop", ) -> Any: """Nest join two data frames by matching rows. The original API: https://dplyr.tidyverse.org/reference/join.html Args: x: A data frame y: A data frame by: A list of column names to join by. If None, use the intersection of the columns of x and y. copy: If True, always copy the data. keep: If True, keep the grouping variables in the output. name: The name of the column to store the nested data frame. na_matches: How should NA values be matched? "na": NA values are equal. "never": NA values are never matched. unmatched: How should unmatched keys that would result in dropped rows be handled? "drop": Drop unmatched keys. "error": Raise an error. Returns: A data frame """ raise _NotImplementedByCurrentBackendError("nest_join", x) @_register_verb(ast_fallback=_get_verb_ast_fallback("cross_join")) def cross_join( x: T, y: T, copy: bool = False, suffix: _Sequence[str] = ("_x", "_y"), ) -> T: """Cross joins match each row in x to every row in y, resulting in a data frame with nrow(x) * nrow(y) rows. The original API: https://dplyr.tidyverse.org/reference/cross_join.html Args: x: A data frame y: A data frame copy: If True, always copy the data. suffix: A tuple of suffixes to apply to overlapping columns. Returns: An object of the same type as x (including the same groups). """ raise _NotImplementedByCurrentBackendError("cross_join", x) # lead/lag @_register_func(pipeable=True, dispatchable=True) def lead(x, n=1, default=None, order_by=None) -> Any: """Shift a vector by `n` positions. The original API: https://dplyr.tidyverse.org/reference/lead.html Args: x: A vector n: The number of positions to shift. default: The default value to use for positions that don't exist. order_by: A vector of column names to order by. Returns: A vector """ raise _NotImplementedByCurrentBackendError("lead", x) @_register_func(pipeable=True, dispatchable=True) def lag(x, n=1, default=None, order_by=None) -> Any: """Shift a vector by `n` positions. The original API: https://dplyr.tidyverse.org/reference/lag.html Args: x: A vector n: The number of positions to shift. default: The default value to use for positions that don't exist. order_by: A vector of column names to order by. Returns: A vector """ raise _NotImplementedByCurrentBackendError("lag", x) # mutate @_register_verb(ast_fallback=_get_verb_ast_fallback("mutate")) def mutate( _data, *args, _keep: str = "all", _before=None, _after=None, **kwargs ) -> Any: """Add new columns to a data frame. The original API: https://dplyr.tidyverse.org/reference/mutate.html Args: _data: A data frame _keep: allows you to control which columns from _data are retained in the output: - "all", the default, retains all variables. - "used" keeps any variables used to make new variables; it's useful for checking your work as it displays inputs and outputs side-by-side. - "unused" keeps only existing variables not used to make new variables. - "none", only keeps grouping keys (like transmute()). _before: A list of column names to put the new columns before. _after: A list of column names to put the new columns after. *args: and **kwargs: Name-value pairs. The name gives the name of the column in the output. The value can be: - A vector of length 1, which will be recycled to the correct length. - A vector the same length as the current group (or the whole data frame if ungrouped). - None to remove the column Returns: An object of the same type as _data. The output has the following properties: - Rows are not affected. - Existing columns will be preserved according to the _keep argument. New columns will be placed according to the _before and _after arguments. If _keep = "none" (as in transmute()), the output order is determined only by ..., not the order of existing columns. - Columns given value None will be removed - Groups will be recomputed if a grouping variable is mutated. - Data frame attributes are preserved. """ raise _NotImplementedByCurrentBackendError("mutate", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("transmute")) def transmute(_data, *args, _before=None, _after=None, **kwargs) -> Any: """Add new columns to a data frame and remove existing columns using mutate with `_keep="none"`. The original API: https://dplyr.tidyverse.org/reference/mutate.html Args: _data: A data frame _before: A list of column names to put the new columns before. _after: A list of column names to put the new columns after. *args: and **kwargs: Name-value pairs. The name gives the name of the column in the output. The value can be: - A vector of length 1, which will be recycled to the correct length. - A vector the same length as the current group (or the whole data frame if ungrouped). - None to remove the column Returns: An object of the same type as _data. The output has the following properties: - Rows are not affected. - Existing columns will be preserved according to the _keep argument. New columns will be placed according to the _before and _after arguments. If _keep = "none" (as in transmute()), the output order is determined only by ..., not the order of existing columns. - Columns given value None will be removed - Groups will be recomputed if a grouping variable is mutated. - Data frame attributes are preserved. """ raise _NotImplementedByCurrentBackendError("transmute", _data) # order_by @_register_func(plain=True) def order_by(order, call) -> Any: """Order the data by the given order Note: This function should be called as an argument of a verb. If you want to call it regularly, try `with_order()` Examples: >>> df = tibble(x=c[1:6]) >>> df >> mutate(y=order_by(c[5:], cumsum(f.x))) >>> # df.y: >>> # 15, 14, 12, 9, 5 Args: order: An iterable to control the data order data: The data to be ordered Returns: A Function expression for verb to evaluate. """ raise _NotImplementedByCurrentBackendError("order_by") @_register_func(pipeable=True, dispatchable=True) def with_order(order, func, x, *args, **kwargs) -> Any: """Control argument and result of a window function Examples: >>> with_order([5,4,3,2,1], cumsum, [1,2,3,4,5]) >>> # 15, 14, 12, 9, 5 Args: order: An iterable to order the arugment and result func: The window function x: The first arugment for the function *args: and **kwargs: Other arugments for the function Returns: The ordered result or an expression if there is expression in arguments """ raise _NotImplementedByCurrentBackendError("with_order", order) # pull @_register_verb(ast_fallback=_get_verb_ast_fallback("pull")) def pull(_data, var: str | int = -1, name=None, to=None) -> Any: """Pull a series or a dataframe from a dataframe Args: _data: The dataframe var: The column to pull, either the name or the index name: The name of the pulled value - If `to` is frame, or the value pulled is data frame, it will be the column names - If `to` is series, it will be the series name. If multiple names are given, only the first name will be used. - If `to` is series, but value pulled is a data frame, then a dictionary of series with the series names as keys or given `name` as keys. to: Type of data to return. Only works when pulling `a` for name `a$b` - series: Return a pandas Series object Group information will be lost If pulled value is a dataframe, it will return a dict of series, with the series names or the `name` provided. - array: Return a numpy.ndarray object - frame: Return a DataFrame with that column - list: Return a python list - dict: Return a dict with `name` as keys and pulled value as values Only a single column is allowed to pull - If not provided: `series` when pulled data has only one columns. `dict` if `name` provided and has the same length as the pulled single column. Otherwise `frame`. Returns: The data according to `to` """ raise _NotImplementedByCurrentBackendError("pull", _data) def row_number(x=_f_symbolic) -> Any: """Get the row number of x Note that this function doesn't support piping. Args: x: The data to get row number Defaults to `Symbolic()` so the whole data is used by default when called `row_number()` Returns: The row number """ return row_number_(x, __ast_fallback="normal") @_register_func(pipeable=True, dispatchable=True) def row_number_(x) -> Any: raise _NotImplementedByCurrentBackendError("row_number", x) def ntile(x=_f_symbolic, *, n: int = None) -> Any: """a rough rank, which breaks the input vector into n buckets. The size of the buckets may differ by up to one, larger buckets have lower rank. Note that this function doesn't support piping. Args: x: The data to get rownumber Defaults to `Symbolic()` so the whole data is used by default when called `ntile(n=...)` n: The number of groups to divide the data into Returns: The row number """ return ntile_(x, n=n, __ast_fallback="normal") @_register_func(pipeable=True, dispatchable=True) def ntile_(x, *, n: int = None) -> Any: raise _NotImplementedByCurrentBackendError("ntile", x) def min_rank(x=_f_symbolic, *, na_last: str = "keep") -> Any: """Get the min rank of x Note that this function doesn't support piping. Args: x: The data to get row number Defaults to `Symbolic()` so the whole data is used by default when called `min_rank()` na_last: How NA values are ranked - "keep": NA values are ranked at the end - "top": NA values are ranked at the top - "bottom": NA values are ranked at the bottom Returns: The row number """ return min_rank_(x, na_last=na_last, __ast_fallback="normal") @_register_func(pipeable=True, dispatchable=True) def min_rank_(x, *, na_last: str = "keep") -> Any: raise _NotImplementedByCurrentBackendError("min_rank", x) def dense_rank(x=_f_symbolic, *, na_last: str = "keep") -> Any: """Get the dense rank of x Note that this function doesn't support piping. Args: x: The data to get row number Defaults to `Symbolic()` so the whole data is used by default when called `dense_rank()` na_last: How NA values are ranked - "keep": NA values are ranked at the end - "top": NA values are ranked at the top - "bottom": NA values are ranked at the bottom Returns: The row number """ return dense_rank_(x, na_last=na_last, __ast_fallback="normal") @_register_func(pipeable=True, dispatchable=True) def dense_rank_(x, *, na_last: str = "keep") -> Any: raise _NotImplementedByCurrentBackendError("dense_rank", x) def percent_rank(x=_f_symbolic, *, na_last: str = "keep") -> Any: """Get the percent rank of x Note that this function doesn't support piping. Args: x: The data to get row number Defaults to `Symbolic()` so the whole data is used by default when called `percent_rank()` na_last: How NA values are ranked - "keep": NA values are ranked at the end - "top": NA values are ranked at the top - "bottom": NA values are ranked at the bottom Returns: The row number """ return percent_rank_(x, na_last=na_last, __ast_fallback="normal") @_register_func(pipeable=True, dispatchable=True) def percent_rank_(x, *, na_last: str = "keep") -> Any: raise _NotImplementedByCurrentBackendError("percent_rank", x) def cume_dist(x=_f_symbolic, *, na_last: str = "keep") -> Any: """Get the cume_dist of x Note that this function doesn't support piping. Args: x: The data to get row number Defaults to `Symbolic()` so the whole data is used by default when called `cume_dist()` na_last: How NA values are ranked - "keep": NA values are ranked at the end - "top": NA values are ranked at the top - "bottom": NA values are ranked at the bottom Returns: The row number """ return cume_dist_(x, na_last=na_last, __ast_fallback="normal") @_register_func(pipeable=True, dispatchable=True) def cume_dist_(x, *, na_last: str = "keep") -> Any: raise _NotImplementedByCurrentBackendError("cume_dist", x) # recode @_register_func(pipeable=True, dispatchable=True) def recode(_x, *args, _default=None, _missing=None, **kwargs) -> Any: """Recode a vector, replacing elements in it Args: x: A vector to modify *args: and **kwargs: replacements _default: If supplied, all values not otherwise matched will be given this value. If not supplied and if the replacements are the same type as the original values in series, unmatched values are not changed. If not supplied and if the replacements are not compatible, unmatched values are replaced with np.nan. _missing: If supplied, any missing values in .x will be replaced by this value. Returns: The vector with values replaced """ raise _NotImplementedByCurrentBackendError("recode") @_register_func(pipeable=True, dispatchable=True) def recode_factor( _x, *args, _default=None, _missing=None, _ordered: bool = False, **kwargs, ) -> Any: """Recode a factor, replacing levels in it Args: x: A factor to modify *args: and **kwargs: replacements _default: If supplied, all values not otherwise matched will be given this value. If not supplied and if the replacements are the same type as the original values in series, unmatched values are not changed. If not supplied and if the replacements are not compatible, unmatched values are replaced with np.nan. _missing: If supplied, any missing values in .x will be replaced by this value. _ordered: If True, the factor will be ordered Returns: The factor with levels replaced """ raise _NotImplementedByCurrentBackendError("recode_factor") @_register_verb(ast_fallback=_get_verb_ast_fallback("relocate")) def relocate( _data, *args, _before: int | str = None, _after: int | str = None, **kwargs, ) -> Any: """change column positions See original API https://dplyr.tidyverse.org/reference/relocate.html Args: _data: A data frame *args: and **kwargs: Columns to rename and move _before: and _after: Destination. Supplying neither will move columns to the left-hand side; specifying both is an error. Returns: An object of the same type as .data. The output has the following properties: - Rows are not affected. - The same columns appear in the output, but (usually) in a different place. - Data frame attributes are preserved. - Groups are not affected """ raise _NotImplementedByCurrentBackendError("relocate", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("rename")) def rename(_data, **kwargs) -> Any: """Rename columns See original API https://dplyr.tidyverse.org/reference/rename.html Args: _data: A data frame **kwargs: Columns to rename Returns: The dataframe with new names """ raise _NotImplementedByCurrentBackendError("rename", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("rename_with")) def rename_with(_data, _fn, *args, **kwargs) -> Any: """Rename columns with a function See original API https://dplyr.tidyverse.org/reference/rename.html Args: _data: A data frame _fn: A function to apply to column names *args: the columns to rename and non-keyword arguments for the `_fn`. If `*args` is not provided, then assuming all columns, and no non-keyword arguments are allowed to pass to the function, use keyword arguments instead. **kwargs: keyword arguments for `_fn` Returns: The dataframe with new names """ raise _NotImplementedByCurrentBackendError("rename_with", _data) # rows @_register_verb(ast_fallback=_get_verb_ast_fallback("rows_insert")) def rows_insert( x, y, by=None, conflict: str = "error", **kwargs, ) -> Any: """Insert rows from y into x See original API https://dplyr.tidyverse.org/reference/rows.html Args: x: A data frame y: A data frame by: An unnamed character vector giving the key columns. The key columns must exist in both x and y. Keys typically uniquely identify each row, but this is only enforced for the key values of y By default, we use the first column in y, since the first column is a reasonable place to put an identifier variable. conflict: How to handle conflicts - "error": Throw an error - "ignore": Ignore conflicts **kwargs: Additional arguments to pass to the backend, such as `copy` and `in_place`. Depends on the backend implementation. Returns: A data frame with all existing rows and potentially new rows """ raise _NotImplementedByCurrentBackendError("rows_insert", x) @_register_verb(ast_fallback=_get_verb_ast_fallback("rows_update")) def rows_update( x, y, by=None, unmatched: str = "error", **kwargs, ) -> Any: """Update rows in x with values from y See original API https://dplyr.tidyverse.org/reference/rows.html Args: x: A data frame y: A data frame by: An unnamed character vector giving the key columns. The key columns must exist in both x and y. Keys typically uniquely identify each row, but this is only enforced for the key values of y By default, we use the first column in y, since the first column is a reasonable place to put an identifier variable. unmatched: how should keys in y that are unmatched by the keys in x be handled? One of - "error", the default, will error if there are any keys in y that are unmatched by the keys in x. "ignore" will ignore rows in y with keys that are unmatched by the keys in x. **kwargs: Additional arguments to pass to the backend, such as `copy` and `in_place`. Depends on the backend implementation. Returns: A data frame with all existing rows and potentially new rows """ raise _NotImplementedByCurrentBackendError("rows_update", x) @_register_verb(ast_fallback=_get_verb_ast_fallback("rows_patch")) def rows_patch( x, y, by=None, unmatched: str = "error", **kwargs, ) -> Any: """Patch rows in x with values from y See original API https://dplyr.tidyverse.org/reference/rows.html Args: x: A data frame y: A data frame by: An unnamed character vector giving the key columns. The key columns must exist in both x and y. Keys typically uniquely identify each row, but this is only enforced for the key values of y By default, we use the first column in y, since the first column is a reasonable place to put an identifier variable. unmatched: how should keys in y that are unmatched by the keys in x be handled? One of - "error", the default, will error if there are any keys in y that are unmatched by the keys in x. "ignore" will ignore rows in y with keys that are unmatched by the keys in x. **kwargs: Additional arguments to pass to the backend, such as `copy` and `in_place`. Depends on the backend implementation. Returns: A data frame with NA values overwritten and the number of rows preserved """ raise _NotImplementedByCurrentBackendError("rows_patch", x) @_register_verb(ast_fallback=_get_verb_ast_fallback("rows_upsert")) def rows_upsert(x, y, by=None, **kwargs) -> Any: """Upsert rows in x with values from y See original API https://dplyr.tidyverse.org/reference/rows.html Args: x: A data frame y: A data frame by: An unnamed character vector giving the key columns. The key columns must exist in both x and y. Keys typically uniquely identify each row, but this is only enforced for the key values of y By default, we use the first column in y, since the first column is a reasonable place to put an identifier variable. **kwargs: Additional arguments to pass to the backend, such as `copy` and `in_place`. Depends on the backend implementation. Returns: A data frame with inserted or updated depending on whether or not the key value in y already exists in x. Key values in y must be unique. """ raise _NotImplementedByCurrentBackendError("rows_upsert", x) @_register_verb(ast_fallback=_get_verb_ast_fallback("rows_delete")) def rows_delete( x, y, by=None, unmatched: str = "error", **kwargs, ) -> Any: """Delete rows in x that match keys in y See original API https://dplyr.tidyverse.org/reference/rows.html Args: x: A data frame y: A data frame by: An unnamed character vector giving the key columns. The key columns must exist in both x and y. Keys typically uniquely identify each row, but this is only enforced for the key values of y By default, we use the first column in y, since the first column is a reasonable place to put an identifier variable. unmatched: how should keys in y that are unmatched by the keys in x be handled? One of - "error", the default, will error if there are any keys in y that are unmatched by the keys in x. "ignore" will ignore rows in y with keys that are unmatched by the keys in x. **kwargs: Additional arguments to pass to the backend, such as `copy` and `in_place`. Depends on the backend implementation. Returns: A data frame with rows deleted """ raise _NotImplementedByCurrentBackendError("rows_delete", x) @_register_verb(ast_fallback=_get_verb_ast_fallback("rows_append")) def rows_append(x, y, **kwargs) -> Any: """Append rows in y to x See original API https://dplyr.tidyverse.org/reference/rows.html Args: x: A data frame y: A data frame **kwargs: Additional arguments to pass to the backend, such as `copy` and `in_place`. Depends on the backend implementation. Returns: A data frame with rows appended """ raise _NotImplementedByCurrentBackendError("rows_append", x) @_register_verb(ast_fallback=_get_verb_ast_fallback("select")) def select(_data, *args, **kwargs) -> Any: """Select columns from a data frame. See original API https://dplyr.tidyverse.org/reference/select.html Args: _data: A data frame *args: A list of columns to select **kwargs: A list of columns to select Returns: A data frame with only the selected columns """ raise _NotImplementedByCurrentBackendError("select", _data) @_register_func(pipeable=True, dispatchable=True) def union_all(x, y) -> Any: """Combine two data frames together. See original API https://dplyr.tidyverse.org/reference/setops.html Args: x: A data frame y: A data frame Returns: A data frame with rows from x and y """ raise _NotImplementedByCurrentBackendError("union_all", x) @_register_verb(ast_fallback=_get_verb_ast_fallback("summarise")) def summarise(_data, *args, _groups: str = None, **kwargs) -> Any: """Summarise a data frame. See original API https://dplyr.tidyverse.org/reference/summarise.html Args: _data: A data frame _groups: Grouping structure of the result. - "drop_last": dropping the last level of grouping. - "drop": All levels of grouping are dropped. - "keep": Same grouping structure as _data. - "rowwise": Each row is its own group. *args: and **kwargs: Name-value pairs, where value is the summarized data for each group Returns: A data frame with the summarised columns """ raise _NotImplementedByCurrentBackendError("summarise", _data) summarize = summarise @_register_verb(ast_fallback=_get_verb_ast_fallback("reframe")) def reframe(_data, *args, **kwargs) -> Any: """Reframe a data frame. See original API https://dplyr.tidyverse.org/reference/reframe.html Args: _data: A data frame *args: and **kwargs: Name-value pairs, where value is the reframed data for each group Returns: A data frame with the reframed columns """ raise _NotImplementedByCurrentBackendError("reframe", _data) @_register_verb(dependent=True, ast_fallback=_get_verb_ast_fallback("where")) def where(_data, fn: _Callable) -> Any: """Selects the variables for which a function returns True. See original API https://dplyr.tidyverse.org/reference/filter.html Args: _data: A data frame fn: A function that returns True or False. Currently it has to be `register_func/func_factory registered function purrr-like formula not supported yet. Returns: The matched columns """ raise _NotImplementedByCurrentBackendError("where", _data) @_register_verb( dependent=True, ast_fallback=_get_verb_ast_fallback("everything") ) def everything(_data) -> Any: """Select all variables. See original API https://dplyr.tidyverse.org/reference/select.html Args: _data: A data frame Returns: All columns """ raise _NotImplementedByCurrentBackendError("everything", _data) @_register_verb(dependent=True, ast_fallback=_get_verb_ast_fallback("last_col")) def last_col(_data, offset: int = 0, vars=None) -> Any: """Select the last column. See original API https://dplyr.tidyverse.org/reference/select.html Args: _data: A data frame offset: The offset of the last column vars: A list of columns to select Returns: The last column """ raise _NotImplementedByCurrentBackendError("last_col", _data) @_register_verb( dependent=True, ast_fallback=_get_verb_ast_fallback("starts_with") ) def starts_with(_data, match, ignore_case: bool = True, vars=None) -> Any: """Select columns that start with a string. See original API https://dplyr.tidyverse.org/reference/select.html Args: _data: A data frame match: The string to match ignore_case: Ignore case when matching vars: A list of columns to select Returns: The matched columns """ raise _NotImplementedByCurrentBackendError("starts_with", _data) @_register_verb(dependent=True, ast_fallback=_get_verb_ast_fallback("ends_with")) def ends_with(_data, match, ignore_case: bool = True, vars=None) -> Any: """Select columns that end with a string. See original API https://dplyr.tidyverse.org/reference/select.html Args: _data: A data frame match: The string to match ignore_case: Ignore case when matching vars: A list of columns to select Returns: The matched columns """ raise _NotImplementedByCurrentBackendError("ends_with", _data) @_register_verb(dependent=True, ast_fallback=_get_verb_ast_fallback("contains")) def contains(_data, match, ignore_case: bool = True, vars=None) -> Any: """Select columns that contain a string. See original API https://dplyr.tidyverse.org/reference/select.html Args: _data: A data frame match: The string to match ignore_case: Ignore case when matching vars: A list of columns to select Returns: The matched columns """ raise _NotImplementedByCurrentBackendError("contains", _data) @_register_verb(dependent=True, ast_fallback=_get_verb_ast_fallback("matches")) def matches(_data, match, ignore_case: bool = True, vars=None) -> Any: """Select columns that match a regular expression. See original API https://dplyr.tidyverse.org/reference/select.html Args: _data: A data frame match: The regular expression to match ignore_case: Ignore case when matching vars: A list of columns to select Returns: The matched columns """ raise _NotImplementedByCurrentBackendError("matches", _data) @_register_func(pipeable=True, dispatchable=True) def num_range(prefix: str, range_, width: int = None) -> Any: """Matches a numerical range like x01, x02, x03. Args: _data: The data piped in prefix: A prefix that starts the numeric range. range_: A sequence of integers, like `range(3)` (produces `0,1,2`). width: Optionally, the "width" of the numeric range. For example, a range of 2 gives "01", a range of three "001", etc. Returns: A list of ranges with prefix. """ raise _NotImplementedByCurrentBackendError("num_range") @_register_verb(dependent=True, ast_fallback=_get_verb_ast_fallback("all_of")) def all_of(_data, x) -> Any: """For strict selection. If any of the variables in the character vector is missing, an error is thrown. Args: _data: The data piped in x: A set of variables to match the columns Returns: The matched column names Raises: ColumnNotExistingError: When any of the elements in `x` does not exist in `_data` columns """ raise _NotImplementedByCurrentBackendError("all_of", _data) @_register_verb(dependent=True, ast_fallback=_get_verb_ast_fallback("any_of")) def any_of(_data, x, vars=None) -> Any: """For strict selection. If any of the variables in the character vector is missing, an error is thrown. Args: _data: The data piped in x: A set of variables to match the columns vars: A list of columns to select Returns: The matched column names Raises: ColumnNotExistingError: When any of the elements in `x` does not exist in `_data` columns """ raise _NotImplementedByCurrentBackendError("any_of", _data) ================================================ FILE: datar/apis/forcats.py ================================================ from typing import Any from pipda import register_func as _register_func from ..core.utils import ( NotImplementedByCurrentBackendError as _NotImplementedByCurrentBackendError, ) from .base import as_factor # noqa: F401 @_register_func(pipeable=True, dispatchable=True) def fct_relevel(_f, *lvls, after: int = None) -> Any: """Reorder factor levels by hand Args: _f: A factor (categoriccal), or a string vector *lvls: Either a function (then `len(lvls)` should equal to `1`) or the new levels. A function will be called with the current levels as input, and the return value (which must be a character vector) will be used to relevel the factor. Any levels not mentioned will be left in their existing order, by default after the explicitly mentioned levels. after: Where should the new values be placed? Returns: The factor with levels replaced """ raise _NotImplementedByCurrentBackendError("fct_relevel", _f) @_register_func(pipeable=True, dispatchable=True) def fct_inorder(_f, ordered: bool = None) -> Any: """Reorder factor levels by first appearance Args: _f: A factor ordered: A logical which determines the "ordered" status of the output factor. Returns: The factor with levels reordered """ raise _NotImplementedByCurrentBackendError("fct_inorder", _f) @_register_func(pipeable=True, dispatchable=True) def fct_infreq(_f, ordered: bool = None) -> Any: """Reorder factor levels by frequency Args: _f: A factor ordered: A logical which determines the "ordered" status of the output factor. Returns: The factor with levels reordered """ raise _NotImplementedByCurrentBackendError("fct_infreq", _f) @_register_func(pipeable=True, dispatchable=True) def fct_inseq(_f, ordered: bool = None) -> Any: """Reorder factor levels by sequence Args: _f: A factor ordered: A logical which determines the "ordered" status of the output factor. Returns: The factor with levels reordered """ raise _NotImplementedByCurrentBackendError("fct_inseq", _f) @_register_func(pipeable=True, dispatchable=True) def fct_reorder(_f, _x, *args, _fun=None, _desc: bool = False, **kwargs) -> Any: """Reorder factor levels by a function (default: median) Args: _f: A factor _x: The data to be used to reorder the factor _fun: A function to be used to reorder the factor _desc: If `True`, the factor will be reordered in descending order *args: Extra arguments to be passed to `_fun` **kwargs: Extra keyword arguments to be passed to `_fun` Returns: The factor with levels reordered """ raise _NotImplementedByCurrentBackendError("fct_reorder", _f) @_register_func(pipeable=True, dispatchable=True) def fct_reorder2( _f, _x, *args, _fun=None, _desc: bool = False, **kwargs, ) -> Any: """Reorder factor levels by a function (default: `last2`) Args: _f: A factor _x: The data to be used to reorder the factor _fun: A function to be used to reorder the factor _desc: If `True`, the factor will be reordered in descending order *args: Extra arguments to be passed to `_fun` **kwargs: Extra keyword arguments to be passed to `_fun` Returns: The factor with levels reordered """ raise _NotImplementedByCurrentBackendError("fct_reorder2", _f) @_register_func(pipeable=True, dispatchable=True) def fct_shuffle(_f) -> Any: """Shuffle the levels of a factor Args: _f: A factor Returns: The factor with levels shuffled """ raise _NotImplementedByCurrentBackendError("fct_shuffle", _f) @_register_func(pipeable=True, dispatchable=True) def fct_rev(_f) -> Any: """Reverse the order of the levels of a factor Args: _f: A factor Returns: The factor with levels reversed """ raise _NotImplementedByCurrentBackendError("fct_rev", _f) @_register_func(pipeable=True, dispatchable=True) def fct_shift(_f, n: int = 1) -> Any: """Shift the levels of a factor Args: _f: A factor n: The number of levels to shift Returns: The factor with levels shifted """ raise _NotImplementedByCurrentBackendError("fct_shift", _f) @_register_func(pipeable=True, dispatchable=True) def first2(_x, _y) -> Any: """Find the first element of `_y` ordered by `_x` Args: _x: The vector used to order `_y` _y: The vector to get the first element of Returns: First element of `_y` ordered by `_x` """ raise _NotImplementedByCurrentBackendError("first2", _x) @_register_func(pipeable=True, dispatchable=True) def last2(_x, _y) -> Any: """Find the last element of `_y` ordered by `_x` Args: _x: The vector used to order `_y` _y: The vector to get the last element of Returns: Last element of `_y` ordered by `_x` """ raise _NotImplementedByCurrentBackendError("last2", _x) @_register_func(pipeable=True, dispatchable=True) def fct_anon(_f, prefix: str = "") -> Any: """Anonymise factor levels Args: f: A factor. prefix: A character prefix to insert in front of the random labels. Returns: The factor with levels anonymised """ raise _NotImplementedByCurrentBackendError("fct_anon", _f) @_register_func(pipeable=True, dispatchable=True) def fct_recode(_f, *args, **kwargs) -> Any: """Change factor levels by hand Args: _f: A factor *args: and **kwargs: A sequence of named character vectors where the name gives the new level, and the value gives the old level. Levels not otherwise mentioned will be left as is. Levels can be removed by naming them `NULL`. As `NULL/None` cannot be a name of keyword arguments, replacement has to be specified as a dict (i.e. `fct_recode(x, {NULL: "apple"})`) If you want to replace multiple values with the same old value, use a `set`/`list`/`numpy.ndarray` (i.e. `fct_recode(x, fruit=["apple", "banana"])`). This is a safe way, since `set`/`list`/`numpy.ndarray` is not hashable to be a level of a factor. Do NOT use a `tuple`, as it's hashable! Note that the order of the name-value is in the reverse way as `dplyr.recode()` and `dplyr.recode_factor()` Returns: The factor recoded with given recodings """ raise _NotImplementedByCurrentBackendError("fct_recode", _f) @_register_func(pipeable=True, dispatchable=True) def fct_collapse(_f, other_level=None, **kwargs) -> Any: """Collapse factor levels into manually defined groups Args: _f: A factor **kwargs: The levels to collapse. Like `name=[old_level, old_level1, ...]`. The old levels will be replaced with `name` other_level: Replace all levels not named in `kwargs`. If not, don't collapse them. Returns: The factor with levels collapsed. """ raise _NotImplementedByCurrentBackendError("fct_collapse", _f) @_register_func(pipeable=True, dispatchable=True) def fct_lump( _f, n=None, prop=None, w=None, other_level="Other", ties_method: str = "min", ) -> Any: """Lump together factor levels into "other" Args: f: A factor n: Positive `n` preserves the most common `n` values. Negative `n` preserves the least common `-n` values. It there are ties, you will get at least `abs(n)` values. prop: Positive `prop` lumps values which do not appear at least `prop` of the time. Negative `prop` lumps values that do not appear at most `-prop` of the time. w: An optional numeric vector giving weights for frequency of each value (not level) in f. other_level: Value of level used for "other" values. Always placed at end of levels. ties_method A character string specifying how ties are treated. One of: `average`, `first`, `dense`, `max`, and `min`. Returns: The factor with levels lumped. """ raise _NotImplementedByCurrentBackendError("fct_lump", _f) @_register_func(pipeable=True, dispatchable=True) def fct_lump_min(_f, min_, w=None, other_level="Other") -> Any: """lumps levels that appear fewer than `min_` times. Args: _f: A factor min_: Preserve levels that appear at least `min_` number of times. w: An optional numeric vector giving weights for frequency of each value (not level) in f. other_level: Value of level used for "other" values. Always placed at end of levels. Returns: The factor with levels lumped. """ raise _NotImplementedByCurrentBackendError("fct_lump_min", _f) @_register_func(pipeable=True, dispatchable=True) def fct_lump_prop(_f, prop, w=None, other_level="Other") -> Any: """Lumps levels that appear in fewer `prop * n` times. Args: _f: A factor prop: Positive `prop` lumps values which do not appear at least `prop` of the time. Negative `prop` lumps values that do not appear at most `-prop` of the time. w: An optional numeric vector giving weights for frequency of each value (not level) in f. other_level: Value of level used for "other" values. Always placed at end of levels. Returns: The factor with levels lumped. """ raise _NotImplementedByCurrentBackendError("fct_lump_prop", _f) @_register_func(pipeable=True, dispatchable=True) def fct_lump_n(_f, n, w=None, other_level="Other") -> Any: """Lumps all levels except for the `n` most frequent. Args: f: A factor n: Positive `n` preserves the most common `n` values. Negative `n` preserves the least common `-n` values. It there are ties, you will get at least `abs(n)` values. w: An optional numeric vector giving weights for frequency of each value (not level) in f. other_level: Value of level used for "other" values. Always placed at end of levels. ties_method A character string specifying how ties are treated. One of: `average`, `first`, `dense`, `max`, and `min`. Returns: The factor with levels lumped. """ raise _NotImplementedByCurrentBackendError("fct_lump_n", _f) @_register_func(pipeable=True, dispatchable=True) def fct_lump_lowfreq(_f, other_level="Other") -> Any: """lumps together the least frequent levels, ensuring that "other" is still the smallest level. Args: f: A factor other_level: Value of level used for "other" values. Always placed at end of levels. Returns: The factor with levels lumped. """ raise _NotImplementedByCurrentBackendError("fct_lump_lowfreq", _f) @_register_func(pipeable=True, dispatchable=True) def fct_other(_f, keep=None, drop=None, other_level="Other") -> Any: """Replace levels with "other" Args: _f: A factor keep: and drop: Pick one of `keep` and `drop`: - `keep` will preserve listed levels, replacing all others with `other_level`. - `drop` will replace listed levels with `other_level`, keeping all as is. other_level: Value of level used for "other" values. Always placed at end of levels. Returns: The factor with levels replaced. """ raise _NotImplementedByCurrentBackendError("fct_other", _f) @_register_func(pipeable=True, dispatchable=True) def fct_relabel(_f, _fun, *args, **kwargs) -> Any: """Automatically relabel factor levels, collapse as necessary Args: _f: A factor _fun: A function to be applied to each level. Must accept the old levels and return a character vector of the same length as its input. *args: and **kwargs: Addtional arguments to `_fun` Returns: The factor with levels relabeled """ raise _NotImplementedByCurrentBackendError("fct_relabel", _f) @_register_func(pipeable=True, dispatchable=True) def fct_expand(_f, *additional_levels) -> Any: """Add additional levels to a factor Args: _f: A factor *additional_levels: Additional levels to add to the factor. Levels that already exist will be silently ignored. Returns: The factor with levels expanded """ raise _NotImplementedByCurrentBackendError("fct_expand", _f) @_register_func(pipeable=True, dispatchable=True) def fct_explicit_na(_f, na_level="(Missing)") -> Any: """Make missing values explicit This gives missing values an explicit factor level, ensuring that they appear in summaries and on plots. Args: _f: A factor na_level: Level to use for missing values. This is what NAs will be changed to. Returns: The factor with explict na_levels """ raise _NotImplementedByCurrentBackendError("fct_explicit_na", _f) @_register_func(pipeable=True, dispatchable=True) def fct_drop(_f, only=None) -> Any: """Drop unused levels Args: _f: A factor only: A character vector restricting the set of levels to be dropped. If supplied, only levels that have no entries and appear in this vector will be removed. Returns: The factor with unused levels dropped """ raise _NotImplementedByCurrentBackendError("fct_drop", _f) @_register_func(pipeable=True, dispatchable=True) def fct_unify( fs, levels=None, ) -> Any: """Unify the levels in a list of factors Args: fs: A list of factors levels: Set of levels to apply to every factor. Default to union of all factor levels Returns: A list of factors with the levels expanded """ raise _NotImplementedByCurrentBackendError("fct_unify", fs) @_register_func(pipeable=True, dispatchable=True) def fct_c(*fs) -> Any: """Concatenate factors, combining levels This is a useful ways of patching together factors from multiple sources that really should have the same levels but don't. Args: *fs: factors to concatenate Returns: The concatenated factor """ raise _NotImplementedByCurrentBackendError("fct_c") @_register_func(pipeable=True, dispatchable=True) def fct_cross( *fs, sep: str = ":", keep_empty: bool = False, ) -> Any: """Combine levels from two or more factors to create a new factor Computes a factor whose levels are all the combinations of the levels of the input factors. Args: *fs: factors to cross sep: A string to separate levels keep_empty: If True, keep combinations with no observations as levels Returns: The new factor """ raise _NotImplementedByCurrentBackendError("fct_cross") @_register_func(pipeable=True, dispatchable=True) def fct_count(_f, sort: bool = False, prop=False) -> Any: """Count entries in a factor Args: _f: A factor sort: If True, sort the result so that the most common values float to the top prop: If True, compute the fraction of marginal table. Returns: A data frame with columns `f`, `n` and `p`, if prop is True """ raise _NotImplementedByCurrentBackendError("fct_count", _f) @_register_func(pipeable=True, dispatchable=True) def fct_match(_f, lvls) -> Any: """Test for presence of levels in a factor Do any of `lvls` occur in `_f`? Args: _f: A factor lvls: A vector specifying levels to look for. Returns: A logical factor """ raise _NotImplementedByCurrentBackendError("fct_match", _f) @_register_func(pipeable=True, dispatchable=True) def fct_unique(_f) -> Any: """Unique values of a factor Args: _f: A factor Returns: The factor with the unique values in `_f` """ raise _NotImplementedByCurrentBackendError("fct_unique", _f) @_register_func(pipeable=True, dispatchable=True) def lvls_reorder( _f, idx, ordered: bool = None, ) -> Any: """Leaves values of a factor as they are, but changes the order by given indices Args: f: A factor (or character vector). idx: A integer index, with one integer for each existing level. new_levels: A character vector of new levels. ordered: A logical which determines the "ordered" status of the output factor. `None` preserves the existing status of the factor. Returns: The factor with levels reordered """ raise _NotImplementedByCurrentBackendError("lvls_reorder", _f) @_register_func(pipeable=True, dispatchable=True) def lvls_revalue( _f, new_levels, ) -> Any: """changes the values of existing levels; there must be one new level for each old level Args: _f: A factor new_levels: A character vector of new levels. Returns: The factor with the new levels """ raise _NotImplementedByCurrentBackendError("lvls_revalue", _f) @_register_func(pipeable=True, dispatchable=True) def lvls_expand( _f, new_levels, ) -> Any: """Expands the set of levels; the new levels must include the old levels. Args: _f: A factor new_levels: The new levels. Must include the old ones Returns: The factor with the new levels """ raise _NotImplementedByCurrentBackendError("lvls_expand", _f) @_register_func(pipeable=True, dispatchable=True) def lvls_union(fs) -> Any: """Find all levels in a list of factors Args: fs: A list of factors Returns: A list of all levels """ raise _NotImplementedByCurrentBackendError("lvls_union", fs) ================================================ FILE: datar/apis/misc.py ================================================ from contextlib import contextmanager from pipda import register_func @contextmanager def _array_ufunc_with_backend(backend: str): """Use a backend for the operator""" old_backend = array_ufunc.backend array_ufunc.backend = backend yield array_ufunc.backend = old_backend @register_func(cls=object, dispatchable="first") def array_ufunc(x, ufunc, *args, kind, **kwargs): """Implement the array ufunc Allow other backends to override the behavior of the ufunc on different types of data. """ return ufunc(x, *args, **kwargs) array_ufunc.backend = None array_ufunc.with_backend = _array_ufunc_with_backend ================================================ FILE: datar/apis/tibble.py ================================================ from __future__ import annotations as _ from typing import Any, Callable as _Callable from pipda import ( register_verb as _register_verb, register_func as _register_func, ) from ..core.verb_env import get_verb_ast_fallback as _get_verb_ast_fallback from ..core.utils import ( NotImplementedByCurrentBackendError as _NotImplementedByCurrentBackendError, ) @_register_func(plain=True) def tibble( *args, _name_repair: str | _Callable = "check_unique", _rows: int = None, _dtypes=None, _drop_index: bool = False, _index=None, **kwargs, ) -> Any: """Constructs a data frame Args: *args: and **kwargs: A set of name-value pairs. _name_repair: treatment of problematic column names: - "minimal": No name repair or checks, beyond basic existence, - "unique": Make sure names are unique and not empty, - "check_unique": (default value), no name repair, but check they are unique, - "universal": Make the names unique and syntactic - a function: apply custom name repair _rows: Number of rows of a 0-col dataframe when args and kwargs are not provided. When args or kwargs are provided, this is ignored. _dtypes: The dtypes for each columns to convert to. _drop_index: Whether drop the index for the final data frame _index: The new index of the output frame Returns: A constructed tibble """ raise _NotImplementedByCurrentBackendError("tibble") @_register_func(pipeable=True, dispatchable=True) def tibble_( *args, _name_repair: str | _Callable = "check_unique", _rows: int = None, _dtypes=None, _drop_index: bool = False, _index=None, **kwargs, ) -> Any: raise _NotImplementedByCurrentBackendError("tibble_") @_register_func(plain=True) def tribble( *dummies, _name_repair: str | _Callable = "minimal", _dtypes=None, ) -> Any: """Create dataframe using an easier to read row-by-row layout Unlike original API that uses formula (`f.col`) to indicate the column names, we use `f.col` to indicate them. Args: *dummies: Arguments specifying the structure of a dataframe Variable names should be specified with `f.name` _dtypes: The dtypes for each columns to convert to. Examples: >>> tribble( >>> f.colA, f.colB, >>> "a", 1, >>> "b", 2, >>> "c", 3, >>> ) Returns: A dataframe """ raise _NotImplementedByCurrentBackendError("tribble") @_register_func(plain=True) def tibble_row( *args, _name_repair: str | _Callable = "check_unique", _dtypes=None, **kwargs, ) -> Any: """Constructs a data frame that is guaranteed to occupy one row. Scalar values will be wrapped with `[]` Args: *args: and **kwargs: A set of name-value pairs. _name_repair: treatment of problematic column names: - "minimal": No name repair or checks, beyond basic existence, - "unique": Make sure names are unique and not empty, - "check_unique": (default value), no name repair, but check they are unique, - "universal": Make the names unique and syntactic - a function: apply custom name repair Returns: A constructed dataframe """ raise _NotImplementedByCurrentBackendError("tibble_row") @_register_verb(ast_fallback=_get_verb_ast_fallback("as_tibble")) def as_tibble(df) -> Any: """Convert a DataFrame object to Tibble object""" raise _NotImplementedByCurrentBackendError("as_tibble", df) @_register_verb(ast_fallback=_get_verb_ast_fallback("enframe")) def enframe(x, name="name", value="value") -> Any: """Converts mappings or lists to one- or two-column data frames. Args: x: a list, a dictionary or a dataframe with one or two columns name: and value: value Names of the columns that store the names and values. If `None`, a one-column dataframe is returned. `value` cannot be `None` Returns: A data frame with two columns if `name` is not None (default) or one-column otherwise. """ raise _NotImplementedByCurrentBackendError("enframe", x) @_register_verb(ast_fallback=_get_verb_ast_fallback("deframe")) def deframe(x) -> Any: """Converts two-column data frames to a dictionary using the first column as name and the second column as value. If the input has only one column, a list. Args: x: A data frame. Returns: A dictionary or a list if only one column in the data frame. """ raise _NotImplementedByCurrentBackendError("deframe", x) @_register_verb(ast_fallback=_get_verb_ast_fallback("add_row")) def add_row( _data, *args, _before=None, _after=None, **kwargs, ) -> Any: """Add one or more rows of data to an existing data frame. Aliases `add_case` Args: _data: Data frame to append to. *args: and **kwargs: Name-value pairs to add to the data frame. _before: and _after: row index where to add the new rows. (default to add after the last row) Returns: The dataframe with the added rows """ raise _NotImplementedByCurrentBackendError("add_row", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("add_column")) def add_column( _data, *args, _before=None, _after=None, _name_repair="check_unique", _dtypes=None, **kwargs, ) -> Any: """Add one or more columns to an existing data frame. Args: _data: Data frame to append to *args: and **kwargs: Name-value pairs to add to the data frame _before: and _after: Column index or name where to add the new columns (default to add after the last column) _dtypes: The dtypes for the new columns, either a uniform dtype or a dict of dtypes with keys the column names Returns: The dataframe with the added columns """ raise _NotImplementedByCurrentBackendError("add_column", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("has_rownames")) def has_rownames(_data) -> bool: """Detect if a data frame has row names Aliases `has_index` Args: _data: The data frame to check Returns: True if the data frame has index otherwise False. """ raise _NotImplementedByCurrentBackendError("has_rownames", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("remove_rownames")) def remove_rownames(_data) -> Any: """Remove the index/rownames of a data frame Aliases `remove_index`, `drop_index`, `remove_rownames` Args: _data: The data frame Returns: The data frame with index removed """ raise _NotImplementedByCurrentBackendError("remove_rownames", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("rownames_to_column")) def rownames_to_column(_data, var="rowname") -> Any: """Add rownames as a column Aliases `index_to_column` Args: _data: The data frame var: The name of the column Returns: The data frame with rownames added as one column. Note that the original index is removed. """ raise _NotImplementedByCurrentBackendError("rownames_to_column", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("rowid_to_column")) def rowid_to_column(_data, var="rowid") -> Any: """Add rownames as a column Args: _data: The data frame var: The name of the column Returns: The data frame with row ids added as one column. """ raise _NotImplementedByCurrentBackendError("rowid_to_column", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("column_to_rownames")) def column_to_rownames(_data, var="rowname") -> Any: """Set rownames/index with one column, and remove it Aliases `column_to_index` Args: _data: The data frame var: The column to conver to the rownames Returns: The data frame with the column converted to rownames """ raise _NotImplementedByCurrentBackendError("column_to_rownames", _data) # aliases add_case = add_row has_index = has_rownames remove_index = drop_index = remove_rownames index_to_column = rownames_to_column column_to_index = column_to_rownames ================================================ FILE: datar/apis/tidyr.py ================================================ from __future__ import annotations as _ from typing import Any, Callable as _Callable, Mapping as _Mapping from pipda import ( register_verb as _register_verb, register_func as _register_func, ) from ..core.verb_env import get_verb_ast_fallback as _get_verb_ast_fallback from ..core.utils import ( NotImplementedByCurrentBackendError as _NotImplementedByCurrentBackendError, ) from .base import expand_grid # noqa: F401 @_register_func(pipeable=True, dispatchable=True) def full_seq(x, period, tol=1e-6) -> Any: """Create the full sequence of values in a vector Args: x: A numeric vector. period: Gap between each observation. The existing data will be checked to ensure that it is actually of this periodicity. tol: Numerical tolerance for checking periodicity. Returns: The full sequence """ raise _NotImplementedByCurrentBackendError("full_seq", x) @_register_verb(ast_fallback=_get_verb_ast_fallback("chop")) def chop( data, cols=None, ) -> Any: """Makes data frame shorter by converting rows within each group into list-columns. Args: data: A data frame cols: Columns to chop Returns: Data frame with selected columns chopped """ raise _NotImplementedByCurrentBackendError("chop", data) @_register_verb(ast_fallback=_get_verb_ast_fallback("unchop")) def unchop( data, cols=None, keep_empty: bool = False, dtypes=None, ) -> Any: """Makes df longer by expanding list-columns so that each element of the list-column gets its own row in the output. See https://tidyr.tidyverse.org/reference/chop.html Recycling size-1 elements might be different from `tidyr` >>> df = tibble(x=[1, [2,3]], y=[[2,3], 1]) >>> df >> unchop([f.x, f.y]) >>> # tibble(x=[1,2,3], y=[2,3,1]) >>> # instead of following in tidyr >>> # tibble(x=[1,1,2,3], y=[2,3,1,1]) Args: data: A data frame. cols: Columns to unchop. keep_empty: By default, you get one row of output for each element of the list your unchopping/unnesting. This means that if there's a size-0 element (like NULL or an empty data frame), that entire row will be dropped from the output. If you want to preserve all rows, use `keep_empty` = `True` to replace size-0 elements with a single row of missing values. dtypes: Providing the dtypes for the output columns. Could be a single dtype, which will be applied to all columns, or a dictionary of dtypes with keys for the columns and values the dtypes. For nested data frames, we need to specify `col$a` as key. If `col` is used as key, all columns of the nested data frames will be casted into that dtype. Returns: A data frame with selected columns unchopped. """ raise _NotImplementedByCurrentBackendError("unchop", data) @_register_verb(ast_fallback=_get_verb_ast_fallback("nest")) def nest( _data, _names_sep: str = None, **cols: str | int, ) -> Any: """Nesting creates a list-column of data frames Args: _data: A data frame **cols: Columns to nest _names_sep: If `None`, the default, the names will be left as is. Inner names will come from the former outer names If a string, the inner and outer names will be used together. The names of the new outer columns will be formed by pasting together the outer and the inner column names, separated by `_names_sep`. Returns: Nested data frame. """ raise _NotImplementedByCurrentBackendError("nest", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("unnest")) def unnest( data, *cols: str | int, keep_empty: bool = False, dtypes=None, names_sep: str = None, names_repair: str | _Callable = "check_unique", ) -> Any: """Flattens list-column of data frames back out into regular columns. Args: data: A data frame to flatten. *cols: Columns to unnest. keep_empty: By default, you get one row of output for each element of the list your unchopping/unnesting. This means that if there's a size-0 element (like NULL or an empty data frame), that entire row will be dropped from the output. If you want to preserve all rows, use `keep_empty` = `True` to replace size-0 elements with a single row of missing values. dtypes: Providing the dtypes for the output columns. Could be a single dtype, which will be applied to all columns, or a dictionary of dtypes with keys for the columns and values the dtypes. names_sep: If `None`, the default, the names will be left as is. Inner names will come from the former outer names If a string, the inner and outer names will be used together. The names of the new outer columns will be formed by pasting together the outer and the inner column names, separated by `names_sep`. names_repair: treatment of problematic column names: - "minimal": No name repair or checks, beyond basic existence, - "unique": Make sure names are unique and not empty, - "check_unique": (default value), no name repair, but check they are unique, - "universal": Make the names unique and syntactic - a function: apply custom name repair Returns: Data frame with selected columns unnested. """ raise _NotImplementedByCurrentBackendError("unnest", data) @_register_verb(ast_fallback=_get_verb_ast_fallback("pack")) def pack( _data, _names_sep: str = None, **cols: str | int, ) -> Any: """Makes df narrow by collapsing a set of columns into a single df-column. Args: _data: A data frame **cols: Columns to pack _names_sep: If `None`, the default, the names will be left as is. Inner names will come from the former outer names If a string, the inner and outer names will be used together. The names of the new outer columns will be formed by pasting together the outer and the inner column names, separated by `_names_sep`. """ raise _NotImplementedByCurrentBackendError("pack", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("unpack")) def unpack( data, cols, names_sep: str = None, names_repair: str | _Callable = "check_unique", ) -> Any: """Makes df wider by expanding df-columns back out into individual columns. For empty columns, the column is kept asis, instead of removing it. Args: data: A data frame cols: Columns to unpack names_sep: If `None`, the default, the names will be left as is. Inner names will come from the former outer names If a string, the inner and outer names will be used together. The names of the new outer columns will be formed by pasting together the outer and the inner column names, separated by `_names_sep`. name_repair: treatment of problematic column names: - "minimal": No name repair or checks, beyond basic existence, - "unique": Make sure names are unique and not empty, - "check_unique": (default value), no name repair, but check they are unique, - "universal": Make the names unique and syntactic - a function: apply custom name repair Returns: Data frame with given columns unpacked. """ raise _NotImplementedByCurrentBackendError("unpack", data) @_register_verb(ast_fallback=_get_verb_ast_fallback("expand")) def expand( data, *args, _name_repair: str | _Callable = "check_unique", **kwargs, ) -> Any: """Generates all combination of variables found in a dataset. Args: data: A data frame *args: and, **kwargs: columns to expand. Columns can be atomic lists. - To find all unique combinations of x, y and z, including those not present in the data, supply each variable as a separate argument: `expand(df, x, y, z)`. - To find only the combinations that occur in the data, use nesting: `expand(df, nesting(x, y, z))`. - You can combine the two forms. For example, `expand(df, nesting(school_id, student_id), date)` would produce a row for each present school-student combination for all possible dates. _name_repair: treatment of problematic column names: - "minimal": No name repair or checks, beyond basic existence, - "unique": Make sure names are unique and not empty, - "check_unique": (default value), no name repair, but check they are unique, - "universal": Make the names unique and syntactic - a function: apply custom name repair Returns: A data frame with all combination of variables. """ raise _NotImplementedByCurrentBackendError("expand", data) @_register_func(dispatchable=True) def nesting( *args, _name_repair: str | _Callable = "check_unique", **kwargs, ) -> Any: """A helper that only finds combinations already present in the data. Args: *args: and, **kwargs: columns to expand. Columns can be atomic lists. - To find all unique combinations of x, y and z, including those not present in the data, supply each variable as a separate argument: `expand(df, x, y, z)`. - To find only the combinations that occur in the data, use nesting: `expand(df, nesting(x, y, z))`. - You can combine the two forms. For example, `expand(df, nesting(school_id, student_id), date)` would produce a row for each present school-student combination for all possible dates. _name_repair: treatment of problematic column names: - "minimal": No name repair or checks, beyond basic existence, - "unique": Make sure names are unique and not empty, - "check_unique": (default value), no name repair, but check they are unique, - "universal": Make the names unique and syntactic - a function: apply custom name repair Returns: A data frame with all combinations in data. """ raise _NotImplementedByCurrentBackendError("nesting") @_register_func(dispatchable=True) def crossing( *args, _name_repair: str | _Callable = "check_unique", **kwargs, ) -> Any: """A wrapper around `expand_grid()` that de-duplicates and sorts its inputs When values are not specified by literal `list`, they will be sorted. Args: *args: and, **kwargs: columns to expand. Columns can be atomic lists. - To find all unique combinations of x, y and z, including those not present in the data, supply each variable as a separate argument: `expand(df, x, y, z)`. - To find only the combinations that occur in the data, use nesting: `expand(df, nesting(x, y, z))`. - You can combine the two forms. For example, `expand(df, nesting(school_id, student_id), date)` would produce a row for each present school-student combination for all possible dates. _name_repair: treatment of problematic column names: - "minimal": No name repair or checks, beyond basic existence, - "unique": Make sure names are unique and not empty, - "check_unique": (default value), no name repair, but check they are unique, - "universal": Make the names unique and syntactic - a function: apply custom name repair Returns: A data frame with values deduplicated and sorted. """ raise _NotImplementedByCurrentBackendError("crossing") @_register_verb(ast_fallback=_get_verb_ast_fallback("complete")) def complete( data, *args, fill=None, explict: bool = True, ) -> Any: """Turns implicit missing values into explicit missing values. Args: data: A data frame *args: columns to expand. Columns can be atomic lists. - To find all unique combinations of x, y and z, including those not present in the data, supply each variable as a separate argument: `expand(df, x, y, z)`. - To find only the combinations that occur in the data, use nesting: `expand(df, nesting(x, y, z))`. - You can combine the two forms. For example, `expand(df, nesting(school_id, student_id), date)` would produce a row for each present school-student combination for all possible dates. fill: A named list that for each variable supplies a single value to use instead of NA for missing combinations. explict: Should both implicit (newly created) and explicit (pre-existing) missing values be filled by fill? By default, this is TRUE, but if set to FALSE this will limit the fill to only implicit missing values. Returns: Data frame with missing values completed """ raise _NotImplementedByCurrentBackendError("complete", data) @_register_verb(ast_fallback=_get_verb_ast_fallback("drop_na")) def drop_na( _data, *columns: str, _how: str = "any", ) -> Any: """Drop rows containing missing values See https://tidyr.tidyverse.org/reference/drop_na.html Args: data: A data frame. *columns: Columns to inspect for missing values. _how: How to select the rows to drop - all: All columns of `columns` to be `NA`s - any: Any columns of `columns` to be `NA`s (tidyr doesn't support this argument) Returns: Dataframe with rows with NAs dropped and indexes dropped """ raise _NotImplementedByCurrentBackendError("drop_na", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("extract")) def extract( data, col: str | int, into, regex: str = r"(\w+)", remove: bool = True, convert=False, ) -> Any: """Given a regular expression with capturing groups, extract() turns each group into a new column. If the groups don't match, or the input is NA, the output will be NA. See https://tidyr.tidyverse.org/reference/extract.html Args: data: The dataframe col: Column name or position. into: Names of new variables to create as character vector. Use None to omit the variable in the output. regex: a regular expression used to extract the desired values. There should be one group (defined by ()) for each element of into. remove: If TRUE, remove input column from output data frame. convert: The universal type for the extracted columns or a dict for individual ones Returns: Dataframe with extracted columns. """ raise _NotImplementedByCurrentBackendError("extract", data) @_register_verb(ast_fallback=_get_verb_ast_fallback("fill")) def fill( _data, *columns: str | int, _direction: str = "down", ) -> Any: """Fills missing values in selected columns using the next or previous entry. See https://tidyr.tidyverse.org/reference/fill.html Args: _data: A dataframe *columns: Columns to fill _direction: Direction in which to fill missing values. Currently either "down" (the default), "up", "downup" (i.e. first down and then up) or "updown" (first up and then down). Returns: The dataframe with NAs being replaced. """ raise _NotImplementedByCurrentBackendError("fill", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("pivot_longer")) def pivot_longer( _data, cols, names_to="name", names_prefix: str = None, names_sep: str = None, names_pattern: str = None, names_dtypes=None, names_transform: _Callable | _Mapping[str, _Callable] = None, names_repair="check_unique", values_to: str = "value", values_drop_na: bool = False, values_dtypes=None, values_transform: _Callable | _Mapping[str, _Callable] = None, ) -> Any: """ "lengthens" data, increasing the number of rows and decreasing the number of columns. The row order is a bit different from `tidyr` and `pandas.DataFrame.melt`. >>> df = tibble(x=c[1:2], y=c[3:4]) >>> pivot_longer(df, f[f.x:f.y]) >>> # name value >>> # 0 x 1 >>> # 1 x 2 >>> # 2 y 3 >>> # 3 y 4 But with `tidyr::pivot_longer`, the output will be: >>> # # A tibble: 4 x 2 >>> # name value >>> # >>> # 1 x 1 >>> # 2 y 3 >>> # 3 x 2 >>> # 4 y 4 Args: _data: A data frame to pivot. cols: Columns to pivot into longer format. names_to: A string specifying the name of the column to create from the data stored in the column names of data. Can be a character vector, creating multiple columns, if names_sep or names_pattern is provided. In this case, there are two special values you can take advantage of: - `None`/`NA`/`NULL` will discard that component of the name. - `.value`/`_value` indicates that component of the name defines the name of the column containing the cell values, overriding values_to. - Different as `tidyr`: With `.value`/`_value`, if there are other parts of the names to distinguish the groups, they must be captured. For example, use `r'(\\w)_(\\d)'` to match `'a_1'` and `['.value', NA]` to discard the suffix, instead of use `r'(\\w)_\\d'` to match. names_prefix: A regular expression used to remove matching text from the start of each variable name. names_sep: and names_pattern: If names_to contains multiple values, these arguments control how the column name is broken up. names_sep takes the same specification as separate(), and can either be a numeric vector (specifying positions to break on), or a single string (specifying a regular expression to split on). names_pattern: takes the same specification as extract(), a regular expression containing matching groups (()). names_dtypes: and values_dtypes: A list of column name-prototype pairs. A prototype (or dtypes for short) is a zero-length vector (like integer() or numeric()) that defines the type, class, and attributes of a vector. Use these arguments if you want to confirm that the created columns are the types that you expect. Note that if you want to change (instead of confirm) the types of specific columns, you should use names_transform or values_transform instead. names_transform: and values_transform: A list of column name-function pairs. Use these arguments if you need to change the types of specific columns. For example, names_transform = dict(week = as.integer) would convert a character variable called week to an integer. If not specified, the type of the columns generated from names_to will be character, and the type of the variables generated from values_to will be the common type of the input columns used to generate them. names_repair: Not supported yet. values_to: A string specifying the name of the column to create from the data stored in cell values. If names_to is a character containing the special `.value`/`_value` sentinel, this value will be ignored, and the name of the value column will be derived from part of the existing column names. values_drop_na: If TRUE, will drop rows that contain only NAs in the value_to column. This effectively converts explicit missing values to implicit missing values, and should generally be used only when missing values in data were created by its structure. names_repair: treatment of problematic column names: - "minimal": No name repair or checks, beyond basic existence, - "unique": Make sure names are unique and not empty, - "check_unique": (default value), no name repair, but check they are unique, - "universal": Make the names unique and syntactic - a function: apply custom name repair Returns: The pivoted dataframe. """ raise _NotImplementedByCurrentBackendError("pivot_longer", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("pivot_wider")) def pivot_wider( _data, id_cols=None, names_from="name", names_prefix: str = "", names_sep: str = "_", names_glue: str = None, names_sort: bool = False, # names_repair: str = "check_unique", # todo values_from="value", values_fill=None, values_fn: _Callable | _Mapping[str, _Callable] = None, ) -> Any: """ "widens" data, increasing the number of columns and decreasing the number of rows. Args: _data: A data frame to pivot. id_cols: A set of columns that uniquely identifies each observation. Defaults to all columns in data except for the columns specified in names_from and values_from. names_from: and values_from: A pair of arguments describing which column (or columns) to get the name of the output column (names_from), and which column (or columns) to get the cell values from (values_from). names_prefix: String added to the start of every variable name. names_sep: If names_from or values_from contains multiple variables, this will be used to join their values together into a single string to use as a column name. names_glue: Instead of names_sep and names_prefix, you can supply a glue specification that uses the names_from columns (and special _value) to create custom column names. names_sort: Should the column names be sorted? If FALSE, the default, column names are ordered by first appearance. names_repair: todo values_fill: Optionally, a (scalar) value that specifies what each value should be filled in with when missing. values_fn: Optionally, a function applied to the value in each cell in the output. You will typically use this when the combination of `id_cols` and value column does not uniquely identify an observation. This can be a dict you want to apply different aggregations to different value columns. If not specified, will be `numpy.mean` Returns: The pivoted dataframe. """ raise _NotImplementedByCurrentBackendError("pivot_wider", _data) @_register_verb(ast_fallback=_get_verb_ast_fallback("separate")) def separate( data, col: int | str, into, sep: int | str = r"[^0-9A-Za-z]+", remove: bool = True, convert=False, extra: str = "warn", fill: str = "warn", ) -> Any: """Given either a regular expression or a vector of character positions, turns a single character column into multiple columns. Args: data: The dataframe col: Column name or position. into: Names of new variables to create as character vector. Use `None`/`NA`/`NULL` to omit the variable in the output. sep: Separator between columns. If str, `sep` is interpreted as a regular expression. The default value is a regular expression that matches any sequence of non-alphanumeric values. If int, `sep` is interpreted as character positions to split at. remove: If TRUE, remove input column from output data frame. convert: The universal type for the extracted columns or a dict for individual ones Note that when given `TRUE`, `DataFrame.convert_dtypes()` is called, but it will not convert `str` to other types (For example, `'1'` to `1`). You have to specify the dtype yourself. extra: If sep is a character vector, this controls what happens when there are too many pieces. There are three valid options: - "warn" (the default): emit a warning and drop extra values. - "drop": drop any extra values without a warning. - "merge": only splits at most length(into) times fill: If sep is a character vector, this controls what happens when there are not enough pieces. There are three valid options: - "warn" (the default): emit a warning and fill from the right - "right": fill with missing values on the right - "left": fill with missing values on the left Returns: Dataframe with separated columns. """ raise _NotImplementedByCurrentBackendError("separate", data) @_register_verb(ast_fallback=_get_verb_ast_fallback("separate_rows")) def separate_rows( data, *columns: str, sep: str = r"[^0-9A-Za-z]+", convert=False, ) -> Any: """Separates the values and places each one in its own row. Args: data: The dataframe *columns: The columns to separate on sep: Separator between columns. convert: The universal type for the extracted columns or a dict for individual ones Returns: Dataframe with rows separated and repeated. """ raise _NotImplementedByCurrentBackendError("separate_rows", data) @_register_verb(ast_fallback=_get_verb_ast_fallback("uncount")) def uncount( data, weights, _remove: bool = True, _id: str = None, ) -> Any: """Duplicating rows according to a weighting variable Args: data: A data frame weights: A vector of weights. Evaluated in the context of data _remove: If TRUE, and weights is the name of a column in data, then this column is removed. _id: Supply a string to create a new variable which gives a unique identifier for each created row (0-based). Returns: dataframe with rows repeated. """ raise _NotImplementedByCurrentBackendError("uncount", data) @_register_verb(ast_fallback=_get_verb_ast_fallback("unite")) def unite( data, col: str, *columns: str | int, sep: str = "_", remove: bool = True, na_rm: bool = True, ) -> Any: """Unite multiple columns into one by pasting strings together Args: data: A data frame. col: The name of the new column, as a string or symbol. *columns: Columns to unite sep: Separator to use between values. remove: If True, remove input columns from output data frame. na_rm: If True, missing values will be remove prior to uniting each value. Returns: The dataframe with selected columns united """ raise _NotImplementedByCurrentBackendError("unite", data) @_register_verb(ast_fallback=_get_verb_ast_fallback("replace_na")) def replace_na( data, data_or_replace=None, replace=None, ) -> Any: """Replace NA with a value This function can be also used not as a verb. As a function called as an argument in a verb, data is passed implicitly. Then one could pass data_or_replace as the data to replace. Args: data: The data piped in data_or_replace: When called as argument of a verb, this is the data to replace. Otherwise this is the replacement. replace: The value to replace with Can only be a scalar or dict for data frame. So replace NA with a list is not supported yet. Returns: Corresponding data with NAs replaced """ raise _NotImplementedByCurrentBackendError("replace_na", data) ================================================ FILE: datar/base.py ================================================ from .core.load_plugins import plugin as _plugin from .apis.base import * locals().update(_plugin.hooks.base_api()) __all__ = [key for key in locals() if not key.startswith("_")] _conflict_names = {"min", "max", "sum", "abs", "round", "all", "any", "re"} if get_option("allow_conflict_names"): # noqa: F405 __all__.extend(_conflict_names) for name in _conflict_names: locals()[name] = locals()[name + "_"] def __getattr__(name): """Even when allow_conflict_names is False, datar.base.sum should be fine """ if name in _conflict_names: import sys import ast from executing import Source node = Source.executing(sys._getframe(1)).node if isinstance(node, (ast.Call, ast.Attribute)): # import datar.base as d # d.sum(...) return globals()[name + "_"] raise AttributeError ================================================ FILE: datar/core/__init__.py ================================================ ================================================ FILE: datar/core/defaults.py ================================================ from pathlib import Path from pipda import Symbolic f = Symbolic() OPTION_FILE_HOME = Path("~/.datar.toml").expanduser() OPTION_FILE_CWD = Path("./.datar.toml").resolve() ================================================ FILE: datar/core/load_plugins.py ================================================ from pipda import register_array_ufunc from .options import get_option from .plugin import plugin def _array_ufunc_to_register(ufunc, x, *args, kind, **kwargs): """Register the array ufunc to pipda""" from ..apis.misc import array_ufunc return array_ufunc( x, ufunc, *args, kind=kind, **kwargs, __backend=array_ufunc.backend, ) plugin.load_entrypoints(only=get_option("backends")) plugin.hooks.setup() register_array_ufunc(_array_ufunc_to_register) ================================================ FILE: datar/core/names.py ================================================ """Name repairing""" import inspect import re import keyword import math from numbers import Number from typing import Any, Callable, List, Union, Iterable, Tuple from .utils import logger class NameNonUniqueError(ValueError): """Error for non-unique names""" def _isnan(x: Any) -> bool: """Check if x is nan""" return isinstance(x, Number) and math.isnan(x) def _is_scalar(x: Any) -> bool: """Check if x is scalar""" if isinstance(x, str): # pragma: no cover return True try: iter(x) except TypeError: return True return False def _log_changed_names(changed_names: List[Tuple[str, str]]) -> None: """Log the changed names""" if not changed_names: return logger.warning("New names:") for orig_name, new_name in changed_names: logger.warning("* %r -> %r", orig_name, new_name) def _repair_names_minimal(names: Iterable[str]) -> List[str]: """Minimal repairing""" return ["" if name is None or _isnan(name) else str(name) for name in names] def _repair_names_unique( names: Iterable[str], quiet: bool = False, sanitizer: Callable = None, ) -> List[str]: """Make sure names are unique""" min_names = _repair_names_minimal(names) neat_names = [ re.sub(r"(?:(? 1 or neat_name == "": neat_name = f"{neat_name}__{i}" if neat_name != name: changed_names.append((name, neat_name)) new_names.append(neat_name) if not quiet: _log_changed_names(changed_names) return new_names def _repair_names_universal( names: Iterable[str], quiet: bool = False, ) -> List[str]: """Make sure names are safely to be used as variable or attribute""" min_names = _repair_names_minimal(names) neat_names = [re.sub(r"[^\w]", "_", name) for name in min_names] new_names = _repair_names_unique( neat_names, quiet=True, sanitizer=lambda name: ( f"_{name}" if keyword.iskeyword(name) or (name and name[0].isdigit()) else name ), ) if not quiet: changed_names = [ (orig_name, new_name) for orig_name, new_name in zip(names, new_names) if orig_name != new_name ] _log_changed_names(changed_names) return new_names def _repair_names_check_unique(names: Iterable[str]) -> Iterable[str]: """Just check the uniqueness""" for name in names: if names.count(name) > 1: raise NameNonUniqueError(f"Names must be unique: {name}") if name == "" or _isnan(name): raise NameNonUniqueError(f"Names can't be empty: {name}") if re.search(r"(?:(? List[str]: """Repair names based on the method Args: names: The names to be repaired repair: The method to repair - `minimal`: Minimal names are never None or NA. When an element doesn't have a name, its minimal name is an empty string. - `unique`: Unique names are unique. A suffix is appended to duplicate names to make them unique. - `universal`: Universal names are unique and syntactic, meaning that you can safely use the names as variables without causing a syntax error (like `f.`). - A function, accepts either a list of names or a single name. Function accepts a list of names must annotate the first argument with `typing.Iterable` or `typing.Sequence`. Examples: >>> repair_names([None]*3, repair="minimal") >>> # ["", "", ""] >>> repair_names(["x", NA], repair="minimal") >>> # ["x", ""] >>> repair_names(["", "x", "", "y", "x", "_2", "__"], repair="unique") >>> # ["__1", "x__2", "__3", "y", "x__5", "__6", "__7"] >>> repair_names(["", "x", NA, "x"], repair="universal") >>> # ["__1", "x__2", "__3", "x__4"] >>> repair_names(["(y)" "_z" ".2fa" "False"], repair="universal") >>> # ["_y_", "_z", "_2fa", "_False"] Returns: The repaired names Raises: ValueError: when repair is not a string or callable NameNonUniqueError: when check_unique fails """ if isinstance(repair, str): repair = BUILTIN_REPAIR_METHODS[repair] # type: ignore elif ( not _is_scalar(repair) and all(isinstance(elem, str) for elem in repair) ): return repair # type: ignore elif not callable(repair): raise ValueError("Expect a function for name repairing.") parameters = inspect.signature(repair).parameters # type: ignore annotation = list(parameters.values())[0].annotation if annotation is inspect._empty or annotation._name not in ( "Iterable", "Sequence", ): # scalar input return [repair(name) for name in names] return repair(names) ================================================ FILE: datar/core/operator.py ================================================ """Operators for datar""" from typing import Callable from contextlib import contextmanager from pipda import register_operator, Operator @register_operator class DatarOperator(Operator): """Operator class for datar""" backend = None @classmethod @contextmanager def with_backend(cls, backend: str): """Use a backend for the operator""" old_backend = cls.backend cls.backend = backend yield cls.backend = old_backend def __getattr__(self, name: str) -> Callable: from .plugin import plugin return lambda x, y=None: plugin.hooks.operate( name, x, y, __plugin=self.__class__.backend, ) ================================================ FILE: datar/core/options.py ================================================ """Provide options""" from __future__ import annotations from typing import Any, Generator, Mapping from contextlib import contextmanager from diot import Diot from simpleconf import Config from .defaults import OPTION_FILE_CWD, OPTION_FILE_HOME _key_transform = lambda key: key.replace("_", ".") _dict_transform_back = lambda dic: { key.replace(".", "_"): val for key, val in dic.items() } OPTIONS = Diot( Config.load( { # Do we allow to use conflict names directly? "allow_conflict_names": False, # Disable some installed backends "backends": [], }, OPTION_FILE_HOME, OPTION_FILE_CWD, ignore_nonexist=True, ), diot_transform=_key_transform, ) def options( *args: str | Mapping[str, Any], _return: bool = None, **kwargs: Any, ) -> Mapping[str, Any]: """Allow the user to set and examine a variety of global options Args: *args: Names of options to return **kwargs: name-value pair to create/set an option _return: Whether return the options. If `None`, turned to `True` when option names provided in `args`. Returns: The options before updating if `_return` is `True`. """ if not args and not kwargs and (_return is None or _return is True): # Make sure the options won't be changed return OPTIONS.copy() names = [arg.replace(".", "_") for arg in args if isinstance(arg, str)] pairs = {} for arg in args: if isinstance(arg, dict): pairs.update(_dict_transform_back(arg)) pairs.update(_dict_transform_back(kwargs)) out = None if _return is None: _return = names if _return: out = Diot( { name: value for name, value in OPTIONS.items() if name in names or name in pairs }, diot_transform=_key_transform, ) for key, val in pairs.items(): oldval = OPTIONS[key] if oldval == val: continue OPTIONS[key] = val return out @contextmanager def options_context(**kwargs: Any) -> Generator: """A context manager to execute code with temporary options Note that this is not thread-safe. """ opts = options() # type: Mapping[str, Any] options(**kwargs) yield options(opts) def get_option(x: str, default: Any = None) -> Any: """Get the current value set for option `x`, or `default` (which defaults to `NULL`) if the option is unset. Args: x: The name of the option default: The default value if `x` is unset """ return OPTIONS.get(x, default) def add_option(x: str, default: Any = None) -> None: """Add an option Args: x: The name of the option default: The default value if `x` is unset """ OPTIONS.setdefault(x, default) ================================================ FILE: datar/core/plugin.py ================================================ """Plugin system to support different backends""" from typing import Any, List, Mapping, Tuple, Callable from simplug import Simplug, SimplugResult, makecall plugin = Simplug("datar") def _collect(calls: List[Tuple[Callable, Tuple, Mapping]]) -> Mapping[str, Any]: """Collect the results from plugins""" collected = {} for call in calls: out = makecall(call) if out is not None: collected.update(out) return collected @plugin.spec def setup(): """Initialize the backend""" @plugin.spec(result=_collect) def get_versions(): """Return the versions of the dependencies of the plugin.""" @plugin.spec(result=SimplugResult.TRY_SINGLE) def load_dataset(name: str, metadata: Mapping): """Implementations for load_dataset()""" @plugin.spec(result=_collect) def base_api(): """What is implemented the base APIs.""" @plugin.spec(result=_collect) def dplyr_api(): """What is implemented the dplyr APIs.""" @plugin.spec(result=_collect) def tibble_api(): """What is implemented the tibble APIs.""" @plugin.spec(result=_collect) def forcats_api(): """What is implemented the forcats APIs.""" @plugin.spec(result=_collect) def tidyr_api(): """What is implemented the tidyr APIs.""" @plugin.spec(result=_collect) def misc_api(): """What is implemented the misc APIs.""" @plugin.spec(result=SimplugResult.SINGLE) def c_getitem(item): """Get item for c""" @plugin.spec(result=SimplugResult.SINGLE) def operate(op: str, x: Any, y: Any = None): """Operate on x and y""" ================================================ FILE: datar/core/utils.py ================================================ """Utilities for datar""" import sys import logging from typing import Any, Callable from contextlib import contextmanager from .plugin import plugin # logger logger = logging.getLogger("datar") logger.setLevel(logging.INFO) stream_handler = logging.StreamHandler(sys.stderr) stream_handler.setFormatter( logging.Formatter( "[%(asctime)s][%(name)s][%(levelname)7s] %(message)s", datefmt="%Y-%m-%d %H:%M:%S", ) ) logger.addHandler(stream_handler) class NotImplementedByCurrentBackendError(NotImplementedError): """Raised when a function is not implemented by the current backend""" def __init__(self, func: str, data: Any = None) -> None: data_msg = "" if data is not None: data_msg = f"data type: {type(data).__name__}, " msg = ( f"'{func}' " f"({data_msg}backends: " f"{', '.join(plugin.get_enabled_plugin_names())})" ) super().__init__(msg) class CollectionFunction: """Enables c[1:3] to be interpreted as 1:3""" def __init__(self, c_func: Callable) -> None: self.c = c_func self.backend = None def __call__(self, *args, **kwargs): kwargs["__ast_fallback"] = "normal" return self.c(*args, **kwargs) @contextmanager def with_backend(self, backend: str): """Set the backend for c[]""" _backend = self.backend self.backend = backend yield self.backend = _backend def __getitem__(self, item): """Allow c[1:3] to be interpreted as 1:3""" return plugin.hooks.c_getitem(item, __plugin=self.backend) def arg_match(arg, argname, values, errmsg=None): """Make sure arg is in one of the values. Mimics `rlang::arg_match`. """ if not errmsg: values = list(values) errmsg = f"`{argname}` must be one of {values}." if arg not in values: raise ValueError(errmsg) return arg ================================================ FILE: datar/core/verb_env.py ================================================ """Utilities for getting verb AST fallback from environment variables""" from __future__ import annotations import os def get_verb_ast_fallback(verb: str) -> str | None: """Get ast_fallback value from environment variables. Checks for per-verb environment variable first, then falls back to global. Args: verb: The name of the verb (e.g., "mutate", "select", "filter") Returns: The ast_fallback value from environment variables, or None if not set Example: >>> @register_verb(ast_fallback=get_verb_ast_fallback("mutate")) >>> def mutate(...): ... pass """ # Convert verb name to uppercase, removing trailing underscore if present # e.g., "select" -> "SELECT", "filter_" -> "FILTER" verb_name = verb.rstrip("_").upper() # Check for per-verb environment variable first # e.g., DATAR_MUTATE_AST_FALLBACK per_verb_key = f"DATAR_{verb_name}_AST_FALLBACK" per_verb_value = os.environ.get(per_verb_key) if per_verb_value: return per_verb_value # Fall back to global environment variable global_key = "DATAR_VERB_AST_FALLBACK" global_value = os.environ.get(global_key) if global_value: return global_value return None ================================================ FILE: datar/data/__init__.py ================================================ """Collects datasets from R-datasets, dplyr and tidyr packages""" import functools from typing import Any, List from ..core.load_plugins import plugin from .metadata import Metadata, metadata # Should never do `from datar.data import *` __all__ = [] # type: List[str] def descr_datasets(*names: str): """Get the information of the given datasets Args: *names: Names of the datasets to get the information of. """ return { key: val for key, val in metadata.items() if key in names or not names } def add_dataset(name: str, meta: Metadata): """Add a dataset to the registry Args: name: The name of the dataset metadata: The metadata of the dataset """ metadata[name] = meta @functools.lru_cache() def load_dataset(name: str, __backend: str = None) -> Any: """Load the specific dataset""" loaded = plugin.hooks.load_dataset(name, metadata, __plugin=__backend) if loaded is None: from ..core.utils import NotImplementedByCurrentBackendError raise NotImplementedByCurrentBackendError(f"loading dataset '{name}'") return loaded def __getattr__(name: str): # mkapi accesses quite a lot of attributes starting with _ if not name.isidentifier() or name.startswith("__"): # pragma: no cover raise AttributeError(name) return load_dataset(name.lower()) ================================================ FILE: datar/data/metadata.py ================================================ from collections import namedtuple from pathlib import Path HERE = Path(__file__).parent Metadata = namedtuple('Metadata', ['descr', 'ref', 'index', 'source']) metadata = dict( airlines=Metadata( descr="Translation between two letter carrier codes and names", ref="https://github.com/tidyverse/nycflights13", index=False, source=HERE / "airlines.csv.gz", ), airports=Metadata( descr="airport names and locations", ref="https://github.com/tidyverse/nycflights13", index=False, source=HERE / "airports.csv.gz", ), airquality=Metadata( descr="Daily air quality measurements in New York, May to September 1973.", ref="https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/airquality", index=False, source=HERE / "airquality.csv.gz", ), anscombe=Metadata( descr="Four x-y datasets which have the same traditional statistical properties", ref="https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/anscombe", index=False, source=HERE / "anscombe.csv.gz", ), band_instruments=Metadata( descr="Band members of the Beatles and Rolling Stones", ref="https://dplyr.tidyverse.org/reference/band_members.html", index=False, source=HERE / "band_instruments.csv.gz", ), band_instruments2=Metadata( descr="Band members of the Beatles and Rolling Stones", ref="https://dplyr.tidyverse.org/reference/band_members.html", index=False, source=HERE / "band_instruments2.csv.gz", ), band_members=Metadata( descr="Band members of the Beatles and Rolling Stones", ref="https://dplyr.tidyverse.org/reference/band_members.html", index=False, source=HERE / "band_members.csv.gz", ), billboard=Metadata( descr="Song rankings for Billboard top 100 in the year 2000", ref="https://tidyr.tidyverse.org/reference/billboard.html", index=False, source=HERE / "billboard.csv.gz", ), chickweight=Metadata( descr="Weight versus age of chicks on different diets", ref="https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/ChickWeight", index=False, source=HERE / "chickweight.csv.gz", ), cms_patient_care=Metadata( descr="Data from the Centers for Medicare & Medicaid Services", ref="https://tidyr.tidyverse.org/reference/cms_patient_experience.html", index=False, source=HERE / "cms_patient_care.csv.gz", ), cms_patient_experience=Metadata( descr="Data from the Centers for Medicare & Medicaid Services", ref="https://tidyr.tidyverse.org/reference/cms_patient_experience.html", index=False, source=HERE / "cms_patient_experience.csv.gz", ), construction=Metadata( descr="Completed construction in the US in 2018", ref="https://tidyr.tidyverse.org/reference/construction.html", index=False, source=HERE / "construction.csv.gz", ), diamonds=Metadata( descr="A dataset containing the prices and other attributes of almost 54,000 diamonds", ref="https://ggplot2.tidyverse.org/reference/diamonds.html", index=False, source=HERE / "diamonds.csv.gz", ), economics=Metadata( descr="US economic time series", ref="https://ggplot2.tidyverse.org/reference/economics.html", index=False, source=HERE / "economics.csv.gz", ), economics_long=Metadata( descr="US economic time series", ref="https://ggplot2.tidyverse.org/reference/economics.html", index=False, source=HERE / "economics_long.csv.gz", ), faithful=Metadata( descr="Waiting time between eruptions and the duration of the eruption for the Old Faithful geyser in Yellowstone National Park, Wyoming, USA", ref="https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/faithful", index=False, source=HERE / "faithful.csv.gz", ), faithfuld=Metadata( descr="2d density estimate of Old Faithful data", ref="https://ggplot2.tidyverse.org/reference/faithfuld.html", index=False, source=HERE / "faithfuld.csv.gz", ), fish_encounters=Metadata( descr="Information about fish swimming down a river", ref="https://tidyr.tidyverse.org/reference/fish_encounters.html", index=False, source=HERE / "fish_encounters.csv.gz", ), flights=Metadata( descr="all flights that departed from NYC in 2013", ref="https://github.com/tidyverse/nycflights13", index=False, source=HERE / "flights.csv.gz", ), gss_cat=Metadata( descr="A sample of categorical variables from the General Social survey", ref="https://forcats.tidyverse.org/reference/gss_cat.html", index=False, source=HERE / "gss_cat.csv.gz", ), household=Metadata( descr="This dataset is based on an example in `vignette(\"datatable-reshape\", package = \"data.table\")`", ref="https://tidyr.tidyverse.org/reference/household.html", index=False, source=HERE / "household.csv.gz", ), iris=Metadata( descr="Edgar Anderson's Iris Data", ref="https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/iris", index=False, source=HERE / "iris.csv.gz", ), luv_colours=Metadata( descr="colors() in Luv space", ref="https://ggplot2.tidyverse.org/reference/luv_colours.html", index=False, source=HERE / "luv_colours.csv.gz", ), midwest=Metadata( descr="Midwest demographics", ref="https://ggplot2.tidyverse.org/reference/midwest.html", index=False, source=HERE / "midwest.csv.gz", ), mpg=Metadata( descr="Fuel economy data from 1999 to 2008 for 38 popular models of cars", ref="https://ggplot2.tidyverse.org/reference/mpg.html", index=False, source=HERE / "mpg.csv.gz", ), msleep=Metadata( descr="An updated and expanded version of the mammals sleep dataset", ref="https://ggplot2.tidyverse.org/reference/msleep.html", index=False, source=HERE / "msleep.csv.gz", ), mtcars=Metadata( descr="Motor Trend Car Road Tests", ref="https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/mtcars", index=True, source=HERE / "mtcars.csv.gz", ), planes=Metadata( descr="construction information about each plane", ref="https://github.com/tidyverse/nycflights13", index=False, source=HERE / "planes.csv.gz", ), population=Metadata( descr="A subset of data from the World Health Organization Global Tuberculosis Report, and accompanying global populations.", ref="https://tidyr.tidyverse.org/reference/who.html", index=False, source=HERE / "population.csv.gz", ), presidential=Metadata( descr="Terms of 11 presidents from Eisenhower to Obama", ref="https://ggplot2.tidyverse.org/reference/presidential.html", index=False, source=HERE / "presidential.csv.gz", ), relig_income=Metadata( descr="Pew religion and income survey", ref="https://tidyr.tidyverse.org/reference/relig_income.html", index=False, source=HERE / "relig_income.csv.gz", ), seals=Metadata( descr="Vector field of seal movements", ref="https://ggplot2.tidyverse.org/reference/seals.html", index=False, source=HERE / "seals.csv.gz", ), smith=Metadata( descr="A small demo dataset describing John and Mary Smith.", ref="https://tidyr.tidyverse.org/reference/smiths.html", index=False, source=HERE / "smith.csv.gz", ), starwars=Metadata( descr="tarwars characters (columns films, vehicles and starships are not included)", ref="https://dplyr.tidyverse.org/reference/starwars.html", index=False, source=HERE / "starwars.csv.gz", ), state_abb=Metadata( descr="character vector of 2-letter abbreviations for the state names.", ref="https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/state", index=False, source=HERE / "state_abb.csv.gz", ), state_division=Metadata( descr="factor giving state divisions (New England, Middle Atlantic, South Atlantic, East South Central, West South Central, East North Central, West North Central, Mountain, and Pacific).", ref="https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/state", index=False, source=HERE / "state_division.csv.gz", ), state_region=Metadata( descr="factor giving the region (Northeast, South, North Central, West) that each state belongs to.", ref="https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/state", index=False, source=HERE / "state_region.csv.gz", ), storms=Metadata( descr="This data is a subset of the NOAA Atlantic hurricane database best track data", ref="https://dplyr.tidyverse.org/reference/storms.html", index=True, source=HERE / "storms.csv.gz", ), table1=Metadata( descr="Example tabular representations", ref="https://tidyr.tidyverse.org/reference/table1.html", index=False, source=HERE / "table1.csv.gz", ), table2=Metadata( descr="Example tabular representations", ref="https://tidyr.tidyverse.org/reference/table1.html", index=False, source=HERE / "table2.csv.gz", ), table3=Metadata( descr="Example tabular representations", ref="https://tidyr.tidyverse.org/reference/table1.html", index=False, source=HERE / "table3.csv.gz", ), table4a=Metadata( descr="Example tabular representations", ref="https://tidyr.tidyverse.org/reference/table1.html", index=False, source=HERE / "table4a.csv.gz", ), table4b=Metadata( descr="Example tabular representations", ref="https://tidyr.tidyverse.org/reference/table1.html", index=False, source=HERE / "table4b.csv.gz", ), table5=Metadata( descr="Example tabular representations", ref="https://tidyr.tidyverse.org/reference/table1.html", index=False, source=HERE / "table5.csv.gz", ), toothgrowth=Metadata( descr="The Effect of Vitamin C on Tooth Growth in Guinea Pigs", ref="https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/ToothGrowth", index=False, source=HERE / "toothgrowth.csv.gz", ), txhousing=Metadata( descr="Housing sales in TX", ref="https://ggplot2.tidyverse.org/reference/txhousing.html", index=False, source=HERE / "txhousing.csv.gz", ), us_rent_income=Metadata( descr="US rent and income data", ref="https://tidyr.tidyverse.org/reference/us_rent_income.html", index=False, source=HERE / "us_rent_income.csv.gz", ), warpbreaks=Metadata( descr="The Number of Breaks in Yarn during Weaving", ref="https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/warpbreaks", index=False, source=HERE / "warpbreaks.csv.gz", ), weather=Metadata( descr="hourly meterological data for each airport", ref="https://github.com/tidyverse/nycflights13", index=False, source=HERE / "weather.csv.gz", ), who=Metadata( descr="A subset of data from the World Health Organization Global Tuberculosis Report, and accompanying global populations.", ref="https://tidyr.tidyverse.org/reference/who.html", index=False, source=HERE / "who.csv.gz", ), who2=Metadata( descr="A subset of data from the World Health Organization Global Tuberculosis Report, and accompanying global populations.", ref="https://tidyr.tidyverse.org/reference/who.html", index=False, source=HERE / "who2.csv.gz", ), world_bank_pop=Metadata( descr="Population data from the world bank", ref="https://tidyr.tidyverse.org/reference/world_bank_pop.html", index=False, source=HERE / "world_bank_pop.csv.gz", ), ) ================================================ FILE: datar/datasets.py ================================================ # pragma: no cover import warnings class DatasetsDeprecatedWarning(DeprecationWarning): ... warnings.simplefilter("always", DatasetsDeprecatedWarning) warnings.warn( "Import data from `datar.datasets` is deprecated and " "will be removed in the future. try `datar.data` instead.", DatasetsDeprecatedWarning, ) def __getattr__(name: str): from . import data return getattr(data, name) ================================================ FILE: datar/dplyr.py ================================================ from .core.load_plugins import plugin as _plugin from .core.options import get_option as _get_option from .apis.dplyr import * locals().update(_plugin.hooks.dplyr_api()) __all__ = [key for key in locals() if not key.startswith("_")] _conflict_names = {"filter", "slice"} if _get_option("allow_conflict_names"): __all__.extend(_conflict_names) for name in _conflict_names: locals()[name] = locals()[name + "_"] def __getattr__(name): """Even when allow_conflict_names is False, datar.base.sum should be fine """ if name in _conflict_names: import sys import ast from executing import Source node = Source.executing(sys._getframe(1)).node if isinstance(node, (ast.Call, ast.Attribute)): # import datar.dplyr as d # d.sum(...) return globals()[name + "_"] raise AttributeError ================================================ FILE: datar/forcats.py ================================================ from .core.load_plugins import plugin as _plugin from .apis.forcats import * locals().update(_plugin.hooks.forcats_api()) ================================================ FILE: datar/misc.py ================================================ from typing import Any as _Any, Callable as _Callable from pipda import register_verb as _register_verb from .core.verb_env import get_verb_ast_fallback as _get_verb_ast_fallback from .core.load_plugins import plugin as _plugin locals().update(_plugin.hooks.misc_api()) @_register_verb(object, ast_fallback=_get_verb_ast_fallback("pipe")) def pipe(data: _Any, func: _Callable, *args, **kwargs) -> _Any: """Apply a function to the data This function is similar to pandas.DataFrame.pipe() and allows you to apply custom functions in a piping workflow. Works with any data type. Args: data: The data object (can be any type) func: Function to apply to the data. ``args`` and ``kwargs`` are passed into ``func``. *args: Positional arguments passed into ``func`` **kwargs: Keyword arguments passed into ``func`` Returns: The return value of ``func`` Examples: >>> import datar.all as dr >>> # Works with lists >>> [1, 2, 3] >> dr.pipe(lambda x: [i * 2 for i in x]) [2, 4, 6] >>> # Works with dicts >>> data = {'a': 1, 'b': 2} >>> data >> dr.pipe(lambda x: {k: v * 2 for k, v in x.items()}) {'a': 2, 'b': 4} >>> # With additional arguments >>> def add_value(data, value): ... return [x + value for x in data] >>> [1, 2, 3] >> dr.pipe(add_value, 10) [11, 12, 13] >>> # Chain multiple operations >>> [1, 2, 3] >> dr.pipe(lambda x: [i * 2 for i in x]) >> dr.pipe(sum) 12 """ return func(data, *args, **kwargs) ================================================ FILE: datar/tibble.py ================================================ from .core.load_plugins import plugin as _plugin from .apis.tibble import * locals().update(_plugin.hooks.tibble_api()) ================================================ FILE: datar/tidyr.py ================================================ from .core.load_plugins import plugin as _plugin from .apis.tidyr import * locals().update(_plugin.hooks.tidyr_api()) ================================================ FILE: docs/CHANGELOG.md ================================================ # Change Log ## 0.15.17 - feat: update pandas dependency version to ^0.7 with pandas v3 support ## 0.15.16 - refactor: migrate poetry to uv for dep management - fix: correct `__all__` declaration in `__init__.py` ## 0.15.15 - docs: update outdated notebook for filter (#223) - chore: update python-simpleconf version to ^0.9 ## 0.15.14 - chore: update python-simpleconf version to ^0.8 ## 0.15.13 - feat: add environment variables to control verb AST fallback behavior (#219) ## 0.15.12 - chore: update datar-pandas to version ^0.6 - fix: fix fct_recode and fct_collapse with ordered factor (pwwang/datar#216) - fix: handle MultiIndex in _agg_result_compatible (pwwang/datar#214) - feat: suport pandas.Grouper() for group_by (pwwang/datar#215) - chore: update datar-arrow to version ^0.2 - chore: bump pyarrow to ^20 ## 0.15.11 - feat: add generic pipe() function to datar for applying custom functions in piping workflows (#212) - chore: update dependances - test: fix missing reframe from tests ## 0.15.10 - ci: update deployment environment to use ubuntu-latest - feat: add dplyr.reframe (#210) - docs: fix reference map links ## 0.15.9 - ci: ensure Python version is set for setup step - chore: update numpy dependency to allow any version ## 0.15.8 - chore(deps): update python-simpleconf to version 0.7 ## 0.15.7 - chore(deps): drop support for python3.8 - ci: update Python version matrix to drop 3.8 and add 3.11, 3.12 - chore(docs): add mkdocs and related dependencies for documentation generation ## 0.15.6 - deps: bump simplug to 0.4, datar-numpy to 0.3.4 and datar-pandas to 0.5.5 - tests: adopt pytest v8 - ci: use latest actions ## 0.15.5 - deps: bump datar-numpy to 0.3.3 ## 0.15.4 - docs: fix typo in README.md (#197) - docs: change `filter` to `filter_` in README.md - docs: fix typo in data.md - deps: bump datar-pandas to 0.5.4 (support pandas 2.2+) ## 0.15.3 - ⬆️ Bump pipda to 0.13.1 ## 0.15.2 - ⬆️ Bump datar-pandas to 0.5.2 to fix `pip install datar[pandas]` not having numpy backend installed. ## 0.15.1 - ⬆️ Bump datar-pandas to 0.5.1 - Dismiss ast warning for if_else. - Make scipy and wcwidth optional deps - Set seed in tests - Dismiss warnings of fillna with method for pandas2.1 ## 0.15.0 - ✨ Add data who2, household, cms_patient_experience, and cms_patient_care - ⬆️ Bump datar-pandas to 0.5 to support pandas2 (#186) ## 0.14.0 - ⬆️ Bump pipda to 0.13 - 🍱 Support dplyr up to 1.1.3 - 👽️ Align `rows_*()` verbs to align with dplyr 1.1.3 (#188) - 🔧 Update pyproject.toml to generate setup.py for poetry ## 0.13.1 - 🎨 Allow `datar.all.filter` regardless of `allow_conflict_names` (#184) ## 0.13.0 - 👷 Add scripts for codesandbox - 💥 Change the option for conflict names (#184) There is no more warning for conflict names (python reserved names). By default, those names are suffixed with `_` (ie `filter_` instead of `filter`). You can still use the original names by setting `allow_conflict_names` to `True` in `datar.options()`. ```python from datar import options options(allow_conflict_names=True) from datar.all import * filter # ``` ## 0.12.2 - ➕ Add pyarrow backend - 🐛 Exclude coverage for multiline version in `get_versions()` - ⬆️ Bump up `python-simpleconf` to 0.6 so datar can be installed in Windows (#180) ## 0.12.1 - ⬆️ Bump datar-numpy to ^0.2 ## 0.12.0 - 📝 Added import f to plotnine on README.md (#177) - ⬆️ Drop support for python3.7 - ⬆️ Bump pipda to 0.12 - 🍱 Update storms data to 2020 (tidyverse/dplyr#5899) ## 0.11.2 - 📝 Add pypi downloads badge to README - 📝 Fix github workflow badges for README - 🐛 Add return type annotation to fix #173 - ⬆️ Bump python-slugify to v8 ## 0.11.1 - 🐛 Fix `get_versions()` not showing plugin versions - 🐛 Fix plugins not loaded when loading datasets - 🚸 Add github issue templates ## 0.11.0 - 📝 Add testimonials and backend badges in README.md - 🐛 Load entrypoint plugins only when APIs are called (#162) - 💥 Rename `other` module to `misc` ## 0.10.3 - ⬆️ Bump simplug to 0.2.2 - ✨ Add `apis.other.array_ufunc` to support numpy ufuncs - 💥 Change hook `data_api` to `load_dataset` - ✨ Allow backend for `c[]` - ✨ Add `DatarOperator.with_backend()` to select backend for operators - ✅ Add tests - 📝 Update docs for backend supports ## 0.10.2 - 🚑 Fix false warning when importing from all ## 0.10.1 - Pump simplug to 0.2 ## 0.10.0 - Detach backend support, so that more backends can be supported easier in the future - numpy backend: https://github.com/pwwang/datar-numpy - pandas backend: https://github.com/pwwang/datar-pandas - Adopt pipda 0.10 so that functions can be pipeable (#148) - Support pandas 1.5+ (#148), but v1.5.0 excluded (see pandas-dev/pandas#48645) ## 0.9.1 - Pump pipda to 0.8.0 (fixes #149) ## 0.9.0 ### Fixes - Fix `weighted_mean` not handling group variables with NaN values (#137) - Fix `weighted_mean` on `NA` raising error instead of returning `NA` (#139) - Fix pandas `.groupby()` used internally not inheriting `sort`, `dropna` and `observed` (#138, #142) - Fix `mutate/summarise` not counting references inside function as used for `_keep` `"used"/"unused"` - Fix metadata `_datar` of nested `TibbleGrouped` not frozen ### Breaking changes - Refactor `core.factory.func_factory()` (#140) - Use `base.c[...]` for range short cut, instead of `f[...]` - Use `tibble.fibble()` when constructing `Tibble` inside a verb, instead of `tibble.tibble()` - Make `n` a keyword-only argument for `base.ntile` ### Deprecation - Deprecate `verb_factory`, use `register_verb` from `pipda` instead - Deprecate `base.data_context` ### Dependences - Adopt `pipda` `v0.7.1` - Remove `varname` dependency - Install `pdtypes` by default ## 0.8.6 - 🐛 Fix weighted_mean not working for grouped data (#133) - ✅ Add tests for weighted_mean on grouped data - ⚡️ Optimize distinct on existing columns (#128) ## 0.8.5 - 🐛 Fix columns missing after Join by same columns using mapping (#122) ## 0.8.4 - ➖ Add optional deps to extras so they aren't installed by default - 🎨 Giva better message when optional packages not installed ## 0.8.3 - ⬆️ Upgrade pipda to v0.6 - ⬆️️ Upgrade thon-simpleconf to 5.5 ## 0.8.2 - ♻️ Move `glimpse` to `dplyr` (as `glimpse` is a `tidyverse-dplyr` [API](https://dplyr.tidyverse.org/reference/glimpse.html)) - 🐛 Fix `glimpse()` output not rendering in qtconsole (#117) - 🐛 Fix `base.match()` for pandas 1.3.0 - 🐛 Allow `base.match()` to work with grouping data (#115) - 📌 Use `rtoml` (`python-simpleconf`) instead of `toml` (See https://github.com/pwwang/toml-bench) - 📌 Update dependencies ## 0.8.1 - 🐛 Fix `month_abb` and `month_name` being truncated (#112) - 🐛 Fix `unite()` not keeping other columns (#111) ## 0.8.0 - ✨ Support `base.glimpse()` (#107, machow/siuba#409) - 🐛 Register `base.factor()` and accept grouped data (#108) - ✨ Allow configuration file to save default options - 💥 Replace option `warn_builtin_names` with `imiport_names_conflict` (#73) - 🩹 Attach original `__module__` to `func_factory` registed functions - ⬆️ Bump `pipda` to `0.5.9` ## 0.7.2 - ✨ Allow tidyr.unite() to unite multiple columns into a list, instead of join them (#105) - 🩹 Typos in argument names of tidyr.pivot_longer() (#104) - 🐛 Fix base.sprintf() not working with Series (#102) ## 0.7.1 - 🐛 Fix settingwithcopywarning in tidyr.pivot_wider() - 📌 Pin deps for docs - 💚 Don't upload coverage in PR - 📝 Fix typos in docs (#99, #100) (Thanks to @pdwaggoner) ## 0.7.0 - ✨ Support `modin` as backend - ✨ Add `_return` argument for `datar.options()` - 🐛 Fix `tidyr.expand()` when `nesting(f.name)` as argument ## 0.6.4 ### Breaking changes - 🩹 Make `base.ntile()` labels 1-based (#92) ### Fixes - 🐛 Fix `order_by` argument for `dplyr.lead-lag` ### Enhancements - 🚑 Allow `base.paste/paste0()` to work with grouped data - 🩹 Change dtypes of `base.letters/LETTERS/month_abb/month_name` ### Housekeeping - 📝 Update and fix reference maps - 📝 Add `environment.yml` for binder to work - 📝 Update styles for docs - 📝 Update styles for API doc in notebooks - 📝 Update README for new description about the project and add examples from StackOverflow ## 0.6.3 - ✨ Allow `base.c()` to handle groupby data - 🚑 Allow `base.diff()` to work with groupby data - ✨ Allow `forcats.fct_inorder()` to work with groupby data - ✨ Allow `base.rep()`'s arguments `length` and `each` to work with grouped data - ✨ Allow `base.c()` to work with grouped data - ✨ Allow `base.paste()`/`base.paste0()` to work with grouped data - 🐛 Force `&/|` operators to return boolean data - 🚑 Fix `base.diff()` not keep empty groups - 🐛 Fix recycling non-ordered grouped data - 🩹 Fix `dplyr.count()/tally()`'s warning about the new name - 🚑 Make `dplyr.n()` return groupoed data - 🐛 Make `dplyr.slice()` work better with rows/indices from grouped data - 🩹 Make `dplyr.ntile()` labels 1-based - ✨ Add `datar.attrgetter()`, `datar.pd_str()`, `datar.pd_cat()` and `datar.pd_dt()` ## 0.6.2 - 🚑 Fix #87 boolean operator losing index - 🚑 Fix false alarm from `rename()`/`relocate()` for missing grouping variables (#89) - ✨ Add `base.diff()` - 📝 [doc] Update/Fix doc for case_when (#87) - 📝 [doc] Fix links in reference map - 📝 [doc] Update docs for `dplyr.base` ## 0.6.1 - 🐛 Fix `rep(df, n)` producing a nested df - 🐛 Fix `TibbleGrouped.__getitem__()` not keeping grouping structures ## 0.6.0 ### General - Adopt `pipda` 0.5.7 - Reimplement the split-apply-combine rule to solve all performance issues - Drop support for pandas v1.2, require pandas v1.3+ - Remove all `base0_` options and all indices are now 0-based, except `base.seq()`, ranks and their variants - Remove messy type annotations for now, will add them back in the future - Move implementation of data type display for frames in terminal and notebook to `pdtypes` package - Change all arguments end with "_" to arguments start with it to avoid confusion - Move module `datar.stats` to `datar.base.stats` - Default all `na_rm` arguments to `True` - Rename all `ptype` arguments for `tidyr` verbs into `dtypes` ### Details - Introduct new API to register function `datar.core.factory.func_factory()` - Aliase `register_verb` and `register_func` as `verb_factory` and `context_func_factory` in `datar.core.factory` - Expose `options`, `options_context`, `add_option` and `get_option` in `datar/__init__.py` and remove them from `datar.base` - Attach `pipda.options` to `datar.options` - Move `head` and `tail` from `datar.utils` to `datar.base` - Remove redundant `unique` implentation from `datar.base.seq` - Add `datar.core.factory.func_factory()` for developers to register function that works with different types of data (`NDFrame`, `GropuBy`, etc) - Not ensure NAs after NA for `base.cumxxx()` families any more - Remove `set_names` from `datar.stats`, use `names(df, )` from `datar.base` instead - Optimize `intersect`, `union`, `setdiff`, `append` from `datar.base` - Keep grouping variables for `intersect`, `union`, `setdiff` and `union_all` when `y` is a grouped df, even when `x` is not - Remove `drop_index` from `datar.datar`, use `datar.tibble.remove_rownames/remove_index/drop_index` instead - Add `assert_tibble_equal()` in `datar.testing` to test whether 2 tibbles are equal - `rep()` now works with frames - `c_across()` now returns a rowwise df to work with functions that apply to df on `axis=1` - `datar.dplyr.order_by()` now only works like it does in `r-dplyr` and only in side a verb - `datar.dplyr.group_by()` detauls `_sort` to `False` for speed - Only raise error for duplicated column names when selected by column name instead of index - `base.scale()` returns a series rather than a frame when works with a series - Other fixes and optimizations ## 0.5.6 - 🐛 Hotfix for types registered for base.proportions (#77) - 👽️ Fix for pandas 1.4 ## 0.5.5 - Fix #71: semi_join returns duplicated rows ## 0.5.4 - Fix `filter()` restructures group_data incorrectly (#69) ## 0.5.3 - ⚡️ Optimize dplyr.arrange when data are series from the df itself - 🐛 Fix sub-df order of apply for grouped df (#63) - 📝 Update doc for argument by for join functions (#62) - 🐛 Fix mean() with option na_rm=False does not work (#65) ## 0.5.2 More of a maintenance release. - 🔧 Add metadata for datasets - 🔊 Send logs to stderr, instead of stdout - 📌Pin dependency versions - 🚨 Switch linter to flake8 - 📝 Update some docs to fit `datar-cli` ## 0.5.1 - Add documentation about "blind" environment (#45, #54, #55) - Change `base.as_date()` to return pandas datetime types instead python datetime types (#56) - Add `base.as_pd_date()` to be an alias of `pandas.to_datetime()` (#56) - Expose `trimws` to `datar.all` (#58) ## 0.5.0 Added: - Added `forcats` (#51 ) - Added `base.is_ordered()`, `base.nlevels()`, `base.ordered()`, `base.rank()`, `base.order()`, `base.sort()`, `base.tabulate()`, `base.append()`, `base.prop_table()` and `base.proportions()` - Added `gss_cat` dataset Fixed: - Fixed an issue when `Collection` dealing with `numpy.int_` Enhanced: - Added `base0_` argument for `datar.get()` - Passed `__calling_env` to registered functions/verbs when used internally (this makes sure the library to be robust in different environments) ## 0.4.4 - Adopt `varname` `v0.8.0` - Add `base.make_names()` and `base.make_unique()` ## 0.4.3 - Adopt `pipda` `0.4.5` - Make dataset names case-insensitive; - Add datasets: `ToothGrowth`, `economics`, `economics_long`, `faithful`, `faithfuld`, `luv_colours`, `midwest`, `mpg`, `msleep`, `presidential`, `seals`, and `txhousing` - Add `base.complete_cases()` - Change `datasets.all_datasets()` to `datasets.list_datasets()` - Make sure `assume_all_piping` mode works internally: #45 ## 0.4.2 - Adopt `pipda` 0.4.4 - Add `varname` to dependency to close #30 - Rename `datar.datar_versions` to `datar.get_versions` - Port a set of functions from r-base, incluing: - `prod`, `sign`, `signif`, `trunc`, `exp`, `log`, `log2`, `log10`, `log1p`, - `is_finite`, `is_infinite`, `is_nan`, - `match`, - `startswith`, `endswith`, `strtoi`, `chartr`, `tolower`, `toupper`, - `max_col` ## 0.4.1 - Don't use piping syntax internally (`>>=`) - Add `python`, `numpy` and `datar` version to `datar.datar_versions()` - Fix #40: anti_join/semi_join not working when by is column mapping ## 0.4.0 - Adopt `pipda` v0.4.2 Performance improved: - Refactor core.grouped to adopt pandas's groupby - Try to use `DataFrame.agg()`/`DataFrameGroupBy.agg()` when function applied on a single columns (Related issues: #27, #33, #37) Fixed: - Fix when `data` or `context` as new column name for `mutate()` - Fix SettingwithCopyWarning in pivot_longer - Use regular calling internally to make sure it works in some cases that node cannot be detected (ie `Gooey`/`%%timeit` in jupyter) Added: - `datar.datar_versions()` to show versions of related packages for bug reporting. ## 0.3.2 - Adopt `pipda` v0.4.1 to fix `getattr()` failure for operater-connected expressions (#38) - Add `str_dtype` argument to `as_character()` to partially fix #36 - Update license in `core._frame_format_patch` (#28) ## 0.3.1 - Adopt `pipda` v0.4.0 - Change argument `_dtypes` to `dtypes_` for tibble-families ## 0.3.0 - Adopt `pipda` v0.3.0 Breaking changes: - Rename argument `dtypes` of `unchop` and `unnest` back to `ptype` - Change all `_base0` to `base0_` - Change argument `how` of `tidyr.drop_na` to `how_` ## 0.2.3 - Fix compatibility with `pandas` `v1.2.0~4` (#20, thanks to @antonio-yu) - Fix base.table when inputs are factors and exclude is NA; - Add base.scale/col_sums/row_sums/col_means/row_means/col_sds/row_sds/col_medians/row_medians ## 0.2.2 - Use a better strategy warning for builtin name overriding. - Fix index of subdf not dropped for mutate on grouped data - Fix `names_glue` not working with single `values_from` for `tidyr.pivot_wider` - Fix `base.paste` not registered - Fix `base.grep`/`grepl` on NA values - Make `base.sub`/`gsub` return scalar when inputs are scalar strings ## 0.2.1 - Use observed values for non-observsed value match for group_data instead of NAs, which might change the dtype. - Fix tibble recycling values too early ## 0.2.0 Added: - Add `base.which`, `base.bessel`, `base.special`, `base.trig_hb` and `base.string` modules - Add Support for duplicated keyword arguments for dplyr.mutate/summarise by using `_` as suffix - Warn when import python builtin names directly; ; Remove modkit dependency Fixed: - Fixed errors when use`a_1` as names for `"check_unique"` name repairs - Fixed #14: `f.a.mean()` not applied to grouped data Changed: - Don't allow `from datar.datasets import *` - Remove `modkit` dependency - Reset `NaN` to `NA` - Rename `base.getOption` to `base.get_option` - Rename `stats.setNames` to `stats.set_names` ## 0.1.1 - Adopt `pipda` 0.2.8 - Allow `f.col1[f.col2==max(f.col2)]` like expression - Add `base.which/cov/var` - Fix `base.max` - Add `datasets.ChickWeight` - Allow `dplyr.across` to have plain functions passed with default `EVAL` context. ## 0.1.0 Added: - `pandas.NA` as `NaN` - Dtypes display when printing a dataframe (string, html, notebook) - `zibble` to construct dataframes with names specified together, and values together. Fixed: - `base.diag()` on dataframes - Data recycling when length is different from original data - `datar.itemgetter()` not public Changed: - Behavior of `group_by()` with `_drop=False`. Invisible values will not mix with visible values of other columns ## 0.0.7 - Add dplyr rows verbs - Allow mixed numbering (with `c()` and `f[...]`) for tibble construction - Allow slice (`f[a:b]`) to be expanded into sequence for `EVAL` context - Finish tidyr porting. ## 0.0.6 - Add `options`, `get_option` and `options_context` to `datar.base` to allow set/get global options - Add options: `dplyr.summarise.inform` - Add `base0_` argument to all related APIs - Add `nycflights13` datasets - Support slice_head/slice_tail for grouped data ## 0.0.5 - Add option index.base.0; - Refactor Collection families ## 0.0.4 - Finish port of tibble. ## 0.0.3 - Add stats.weighted_mean - Allow function to prefer recycling input or output for summarise ## 0.0.2 - Port verbs and functions from tidyverse/dplyr and test them with original cases ================================================ FILE: docs/ENV_VARS.md ================================================ # Environment Variable Support for Verb AST Fallback This document explains how to use environment variables to control the fallback behavior for verbs when AST (Abstract Syntax Tree) is not retrievable. ## Overview When the AST of a function call is not available (e.g., in some interactive environments or when code is executed dynamically), datar verbs need to make assumptions about how they were called. You can now control this behavior using environment variables. ## Environment Variables ### Global Configuration Set the global fallback behavior for all verbs: ```bash export DATAR_VERB_AST_FALLBACK="piping" ``` This will assume all datar verbs are called with the piping pattern: `data >> verb(...)` ### Per-Verb Configuration You can also configure individual verbs: ```bash # Assume select is called like: data >> select(...) export DATAR_SELECT_AST_FALLBACK="piping" # Assume mutate is called like: mutate(data, ...) export DATAR_MUTATE_AST_FALLBACK="normal" ``` Per-verb environment variables take precedence over the global setting. ## Valid Values The following values are supported for ast_fallback: - `"piping"`: Assume `data >> verb(...)` calling pattern - `"normal"`: Assume `verb(data, ...)` calling pattern - `"piping_warning"`: Assume piping call, but show a warning (default) - `"normal_warning"`: Assume normal call, but show a warning - `"raise"`: Raise an error when AST is not available ## Examples ### Example 1: Set Global Piping Mode Add to your `.bashrc` or shell configuration: ```bash export DATAR_VERB_AST_FALLBACK="piping" ``` Then in Python: ```python from datar.all import * # This will work without warnings when AST is not available iris >> select(f.Species, f.Sepal_Length) ``` ### Example 2: Mixed Configuration ```bash # Most verbs use piping export DATAR_VERB_AST_FALLBACK="piping" # But filter uses normal calling convention export DATAR_FILTER_AST_FALLBACK="normal" ``` Then in Python: ```python from datar.all import * # select uses piping (from global setting) iris >> select(f.Species) # filter uses normal calling (from per-verb setting) filter(iris, f.Sepal_Length > 5) ``` ### Example 3: Raise Errors for Debugging ```bash export DATAR_VERB_AST_FALLBACK="raise" ``` This will help you identify cases where AST is not available, which can be useful for debugging. ## Notes - Environment variables are checked when the verb is registered (at import time). - If you change environment variables after importing datar modules, you'll need to restart your Python session for the changes to take effect. - If you explicitly specify `ast_fallback` in the `@register_verb()` decorator, it takes precedence over environment variables. - Verb names with trailing underscores (e.g., `filter_`) should use the environment variable without the underscore (e.g., `DATAR_FILTER_AST_FALLBACK`). ================================================ FILE: docs/backends.md ================================================ # Backends The `datar` package is a collection of APIs that are ported from a bunch of R packages. The APIs are implemented in a backend-agnostic way, so that they can be used with different backends. Currently, `datar` supports the following backends: - [`numpy`](https://github.com/pwwang/datar-numpy): Mostly the implementations of functions from `datar.base`. - [`pandas`](https://github.com/pwwang/datar-pandas): Implementations using `pandas` as backend. ## Installation of a backend ```bash pip install -U datar[] ``` ## Using desired backends You can install multiple backends, but can use a subset of them. ```python from datar import options options(backends=['pandas']) # Import the API functions then ``` ## Writing a backend A backend is supposed to implement as a `Simplug` plugin. There are a hooks to be implemented. ### Hooks - `setup()`: calleed before any API is imported. You can do some setup here. - `get_versions()`: return a dict of versions of the dependencies of the backend. The keys are the names of the packages, and the values are the versions. - `load_dataset(name: str, metadata: Mapping)`: load a dataset, which can be loaded using `from datar.data import `. - `base_api()`: load the implementation of `datar.apis.base`. - `dplyr_api()`: load the implementation of `datar.apis.dplyr`. - `tibble_api()`: load the implementation of `datar.apis.tibble`. - `forcats_api()`: load the implementation of `datar.apis.forcats`. - `tidyr_api()`: load the implementation of `datar.apis.tidyr`. - `other_api()`: load other backend-specific APIs. - `c_getitem(item)`: load the implementation of `datar.base.c.__getitem__` (`c[...]`). - `operate(op: str, x: Any, y: Any = None)`: load the implementation of the operators. ## Seleting a backend at runtime You can use `__backend` to select a backend at runtime. ```python from datar.tibble import tibble tibble(..., __backend="pandas") ``` ## Selecting a backend for operators If you have multiple backends installed, you can select a backend for operators. ```python from datar.core.operator import DatarOperator DatarOperator.backend = "pandas" # Or use the context manager with DatarOperator.with_backend("pandas"): data >> mutate(z=f.x + f.y) ``` ## Selecting a backend for `c[]` ```python from datar.base import c c.backend = "pandas" # Or use the context manager with c.with_backend("pandas"): data >> mutate(z=c[1:3]) ``` ## Selecting a backend for numpy ufuncs ```python from datar.apis.other import array_ufunc array_ufunc.backend = "pandas" # Or use the context manager with array_ufunc.with_backend("pandas"): data >> mutate(z=np.sin(f.x)) ``` ================================================ FILE: docs/data.md ================================================ See full reference of datasets at: [reference-maps/data][1] Datasets have to be imported individually by: ```python from datar.data import iris # or from datar import data iris = data.iris ``` To list all available datasets: ```python from datar import data print(datasets.descr_datasets()) ``` `file` shows the path to the csv file of the dataset, and `index` shows if it has index (rownames). !!! Note The column names are altered by replace `.` to `_`. For example `Sepal.Width` to `Sepal_Width`. !!! Note Dataset names are case-insensitive. So you can do: ```python from datar.datasets import ToothGrowth # or from datar.datasets import toothgrowth ``` See also [Backends][2] for implementations to loaad datasets. [1]: ./reference-maps/data [2]: ./backends ================================================ FILE: docs/f.md ================================================ ## Why `f`? It is just fast for you to type, since usually, it is `.` right after `f`. Then you have your left hand and right hand working together sequentially. ## The `Symbolic` object `f` You can import it by `from datar import f`, or `from datar.all import *` `f` is a universal `Symbolic` object, which does the magic to connect the expressions in verb arguments so that they can be delayed to execute. There are different uses for the `f`. - Use as a proxy to refer to dataframe columns (i.e. `f.x`, `f['x']`) - Use as the column name marker for `tribble`: ```python tribble( f.x, f.y 1, 2 3, 4 ) ``` !!! note If you want a sequence literal, other than using `base.seq()`, you can also use `base.c[]`. For example, ```python from datar.base import c from datar.tibble import tibble df = tibble(x=c[1:5]) # 1, 2, 3, 4 ``` ## If you don't like `f` ... Sometimes if you have mixed verbs with piping and you want to distinguish to proxies for different verbs: ```python # you can just replicate f with a different name g = f df = tibble(x=1, y=2) df >> left_join(df >> group_by(f.x), by=g.y) ``` Or you can instantiate a new `Symbolic` object: ```python from pipda.symbolic import Symbolic g = Symbolic() # assert f is g # f and g make no difference in execution technically ``` You can also alias `f` by: ```python from datar import f as g ``` ================================================ FILE: docs/import.md ================================================ ## Import submodule, verbs and functions from datar You can import everything (all verbs and functions) from datar by: ```python from datar.all import * ``` which is not recommended. Instead, you can import individual verbs or functions by: ```python from datar.all import mutate ``` !!! Attention When you use `from datar.all import *`, you need to pay attention to the python builtin names that are covered by `datar` (will warn by default). For example, `slice` will be `datar.dplyr.slice` instead of `builtins.slice`. To refer to the builtin one, you need to: ```python import builtins s = builtins.slice(None, 3, None) # [:3] ``` Or if you know the origin of the verb, you can also do: ```python from datar.dplyr import mutate ``` You can also keep the namespace: ```python from datar import dplyr # df = tibble(x=1) # then use it with the dplyr namespace: df >> dplyr.mutate(y=2) ``` If you feel those namespaces are annoying, you can always use `datar.all`: ```python from datar.all import mutate ``` ## Import datasets from datar !!! note Dataset has to be imported individually. This means `from datar.datasets import *` won't work (you don't want all datasets to exhaust your memory). You don't have to worry about other datasets to be imported and take up the memory when you import one. The dataset is only loaded into memory when you explictly import it individually. See also [datasets](../datasets) for details about available datasets. ## About python reserved names to be masked by `datar` Sometimes it will be confusing especially when python builtin functions are overriden by `datar`. There are a couple of datar (`r-base`, `dplyr`) functions with the same name as python builtin functions. For example: `filter`, which is a python builtin function, but also a `dplyr` function. You should use `filter_` instead. By default, `datar` will raise an error when you try to import `filter`. You can set this option to `True` to allow this behavior. ================================================ FILE: docs/notebooks/across.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:57.831736Z", "iopub.status.busy": "2021-07-16T22:27:57.831017Z", "iopub.status.idle": "2021-07-16T22:27:58.963601Z", "shell.execute_reply": "2021-07-16T22:27:58.963983Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ across
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "Apply the same transformation to multiple columns\n", "\n", " The original API:\n", " https://dplyr.tidyverse.org/reference/across.html\n", "\n", " Examples:\n", " #\n", " >>> iris >> mutate(across(c(f.Sepal_Length, f.Sepal_Width), round))\n", " Sepal_Length Sepal_Width Petal_Length Petal_Width Species\n", " \n", " 0 5.0 4.0 1.4 0.2 setosa\n", " 1 5.0 3.0 1.4 0.2 setosa\n", " .. ... ... ... ... ...\n", "\n", " >>> iris >> group_by(f.Species) >> summarise(\n", " >>> across(starts_with(\"Sepal\"), mean)\n", " >>> )\n", " Species Sepal_Length Sepal_Width\n", " \n", " 0 setosa 5.006 3.428\n", " 1 versicolor 5.936 2.770\n", " 2 virginica 6.588 2.974\n", "\n", " Args:\n", " _data: The dataframe.\n", " *args: If given, the first 2 elements should be columns and functions\n", " apply to each of the selected columns. The rest of them will be\n", " the arguments for the functions.\n", " _names: A glue specification that describes how to name\n", " the output columns. This can use `{_col}` to stand for the\n", " selected column name, and `{_fn}` to stand for the name of\n", " the function being applied.\n", " The default (None) is equivalent to `{_col}` for the\n", " single function case and `{_col}_{_fn}` for the case where\n", " a list is used for _fns. In such a case, `{_fn}` is 0-based.\n", " To use 1-based index, use `{_fn1}`\n", " _fn_context: Defines the context to evaluate the arguments for functions\n", " if they are plain functions.\n", " Note that registered functions will use its own context\n", " **kwargs: Keyword arguments for the functions\n", "\n", " Returns:\n", " A dataframe with one column for each column and each function.\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ if_any
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Apply the same predicate function to a selection of columns and combine\n", "the results True if any element is True. \n", "\n", "See Also: \n", "  [`across()`](datar.dplyr.across.across) \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ if_all
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Apply the same predicate function to a selection of columns and combine\n", "the results True if all elements are True. \n", "\n", "See Also: \n", "  [`across()`](datar.dplyr.across.across) \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ c_across
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Apply the same transformation to multiple columns rowwisely\n", "\n", "##### Args:\n", "  `_data`: The dataframe \n", "  `_cols`: The columns \n", "\n", "##### Returns:\n", "  A rowwise tibble \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%run nb_helpers.py\n", "\n", "from datar.data import iris\n", "from datar.all import *\n", "\n", "nb_header(across, if_any, if_all, c_across)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:58.975193Z", "iopub.status.busy": "2021-07-16T22:27:58.974632Z", "iopub.status.idle": "2021-07-16T22:27:59.039098Z", "shell.execute_reply": "2021-07-16T22:27:59.039487Z" } }, "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", "
Sepal_LengthSepal_WidthPetal_LengthPetal_WidthSpecies
<float64><float64><float64><float64><object>
05.04.01.40.2setosa
15.03.01.40.2setosa
25.03.01.30.2setosa
35.03.01.50.2setosa
..................
45.04.01.40.2setosa
1457.03.05.22.3virginica
1466.02.05.01.9virginica
1476.03.05.22.0virginica
1486.03.05.42.3virginica
1496.03.05.11.8virginica
\n", "

150 rows × 5 columns

\n", "
\n" ], "text/plain": [ " Sepal_Length Sepal_Width Petal_Length Petal_Width Species\n", " \n", "0 5.0 4.0 1.4 0.2 setosa\n", "1 5.0 3.0 1.4 0.2 setosa\n", "2 5.0 3.0 1.3 0.2 setosa\n", "3 5.0 3.0 1.5 0.2 setosa\n", ".. ... ... ... ... ...\n", "4 5.0 4.0 1.4 0.2 setosa\n", "145 7.0 3.0 5.2 2.3 virginica\n", "146 6.0 2.0 5.0 1.9 virginica\n", "147 6.0 3.0 5.2 2.0 virginica\n", "148 6.0 3.0 5.4 2.3 virginica\n", "149 6.0 3.0 5.1 1.8 virginica\n", "\n", "[150 rows x 5 columns]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# round not changing dtypes (Series.round)\n", "iris >> mutate(across(c(f.Sepal_Length, f.Sepal_Width), round))" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:59.064596Z", "iopub.status.busy": "2021-07-16T22:27:59.051917Z", "iopub.status.idle": "2021-07-16T22:27:59.071141Z", "shell.execute_reply": "2021-07-16T22:27:59.071735Z" } }, "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", "
Sepal_LengthSepal_WidthPetal_LengthPetal_WidthSpecies
<float64><float64><float64><float64><object>
05.04.01.40.2setosa
15.03.01.40.2setosa
25.03.01.30.2setosa
35.03.01.50.2setosa
..................
45.04.01.40.2setosa
1457.03.05.22.3virginica
1466.02.05.01.9virginica
1476.03.05.22.0virginica
1486.03.05.42.3virginica
1496.03.05.11.8virginica
\n", "

150 rows × 5 columns

\n", "
\n" ], "text/plain": [ " Sepal_Length Sepal_Width Petal_Length Petal_Width Species\n", " \n", "0 5.0 4.0 1.4 0.2 setosa\n", "1 5.0 3.0 1.4 0.2 setosa\n", "2 5.0 3.0 1.3 0.2 setosa\n", "3 5.0 3.0 1.5 0.2 setosa\n", ".. ... ... ... ... ...\n", "4 5.0 4.0 1.4 0.2 setosa\n", "145 7.0 3.0 5.2 2.3 virginica\n", "146 6.0 2.0 5.0 1.9 virginica\n", "147 6.0 3.0 5.2 2.0 virginica\n", "148 6.0 3.0 5.4 2.3 virginica\n", "149 6.0 3.0 5.1 1.8 virginica\n", "\n", "[150 rows x 5 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> mutate(across(c(0, 1), round))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:59.160629Z", "iopub.status.busy": "2021-07-16T22:27:59.159926Z", "iopub.status.idle": "2021-07-16T22:27:59.173929Z", "shell.execute_reply": "2021-07-16T22:27:59.174487Z" } }, "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", "
Sepal_LengthSepal_WidthPetal_LengthPetal_WidthSpecies
<float64><float64><float64><float64><object>
05.03.51.40.2setosa
15.03.01.40.2setosa
25.03.21.30.2setosa
35.03.11.50.2setosa
..................
45.03.61.40.2setosa
1457.03.05.22.3virginica
1466.02.55.01.9virginica
1476.03.05.22.0virginica
1486.03.45.42.3virginica
1496.03.05.11.8virginica
\n", "

150 rows × 5 columns

\n", "
\n" ], "text/plain": [ " Sepal_Length Sepal_Width Petal_Length Petal_Width Species\n", " \n", "0 5.0 3.5 1.4 0.2 setosa\n", "1 5.0 3.0 1.4 0.2 setosa\n", "2 5.0 3.2 1.3 0.2 setosa\n", "3 5.0 3.1 1.5 0.2 setosa\n", ".. ... ... ... ... ...\n", "4 5.0 3.6 1.4 0.2 setosa\n", "145 7.0 3.0 5.2 2.3 virginica\n", "146 6.0 2.5 5.0 1.9 virginica\n", "147 6.0 3.0 5.2 2.0 virginica\n", "148 6.0 3.4 5.4 2.3 virginica\n", "149 6.0 3.0 5.1 1.8 virginica\n", "\n", "[150 rows x 5 columns]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# use slice with column names\n", "iris >> mutate(across(c[:f.Sepal_Width], round)) " ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:59.189853Z", "iopub.status.busy": "2021-07-16T22:27:59.189233Z", "iopub.status.idle": "2021-07-16T22:27:59.203297Z", "shell.execute_reply": "2021-07-16T22:27:59.203820Z" } }, "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", "
Sepal_LengthSepal_WidthPetal_LengthPetal_WidthSpecies
<float64><float64><float64><float64><object>
05.04.01.40.2setosa
15.03.01.40.2setosa
25.03.01.30.2setosa
35.03.01.50.2setosa
..................
45.04.01.40.2setosa
1457.03.05.22.3virginica
1466.02.05.01.9virginica
1476.03.05.22.0virginica
1486.03.05.42.3virginica
1496.03.05.11.8virginica
\n", "

150 rows × 5 columns

\n", "
\n" ], "text/plain": [ " Sepal_Length Sepal_Width Petal_Length Petal_Width Species\n", " \n", "0 5.0 4.0 1.4 0.2 setosa\n", "1 5.0 3.0 1.4 0.2 setosa\n", "2 5.0 3.0 1.3 0.2 setosa\n", "3 5.0 3.0 1.5 0.2 setosa\n", ".. ... ... ... ... ...\n", "4 5.0 4.0 1.4 0.2 setosa\n", "145 7.0 3.0 5.2 2.3 virginica\n", "146 6.0 2.0 5.0 1.9 virginica\n", "147 6.0 3.0 5.2 2.0 virginica\n", "148 6.0 3.0 5.4 2.3 virginica\n", "149 6.0 3.0 5.1 1.8 virginica\n", "\n", "[150 rows x 5 columns]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# to include stop of slice\n", "iris >> mutate(across(c[:f.Sepal_Width:1], round)) " ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:59.216473Z", "iopub.status.busy": "2021-07-16T22:27:59.215938Z", "iopub.status.idle": "2021-07-16T22:27:59.261289Z", "shell.execute_reply": "2021-07-16T22:27:59.260707Z" } }, "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", "
Sepal_LengthSepal_WidthPetal_LengthPetal_WidthSpecies
<float64><float64><float64><float64><object>
05.04.01.40.2setosa
15.03.01.40.2setosa
25.03.01.30.2setosa
35.03.01.50.2setosa
..................
45.04.01.40.2setosa
1457.03.05.22.3virginica
1466.02.05.01.9virginica
1476.03.05.22.0virginica
1486.03.05.42.3virginica
1496.03.05.11.8virginica
\n", "

150 rows × 5 columns

\n", "
\n" ], "text/plain": [ " Sepal_Length Sepal_Width Petal_Length Petal_Width Species\n", " \n", "0 5.0 4.0 1.4 0.2 setosa\n", "1 5.0 3.0 1.4 0.2 setosa\n", "2 5.0 3.0 1.3 0.2 setosa\n", "3 5.0 3.0 1.5 0.2 setosa\n", ".. ... ... ... ... ...\n", "4 5.0 4.0 1.4 0.2 setosa\n", "145 7.0 3.0 5.2 2.3 virginica\n", "146 6.0 2.0 5.0 1.9 virginica\n", "147 6.0 3.0 5.2 2.0 virginica\n", "148 6.0 3.0 5.4 2.3 virginica\n", "149 6.0 3.0 5.1 1.8 virginica\n", "\n", "[150 rows x 5 columns]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> mutate(across(where(is_double) & ~c(f.Petal_Length, f.Petal_Width), round))" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:59.285086Z", "iopub.status.busy": "2021-07-16T22:27:59.283416Z", "iopub.status.idle": "2021-07-16T22:27:59.288781Z", "shell.execute_reply": "2021-07-16T22:27:59.288298Z" } }, "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", "
Sepal_LengthSepal_WidthPetal_LengthPetal_WidthSpecies
<float64><float64><float64><float64><category>
05.13.51.40.2setosa
14.93.01.40.2setosa
24.73.21.30.2setosa
34.63.11.50.2setosa
..................
45.03.61.40.2setosa
1456.73.05.22.3virginica
1466.32.55.01.9virginica
1476.53.05.22.0virginica
1486.23.45.42.3virginica
1495.93.05.11.8virginica
\n", "

150 rows × 5 columns

\n", "
\n" ], "text/plain": [ " Sepal_Length Sepal_Width Petal_Length Petal_Width Species\n", " \n", "0 5.1 3.5 1.4 0.2 setosa\n", "1 4.9 3.0 1.4 0.2 setosa\n", "2 4.7 3.2 1.3 0.2 setosa\n", "3 4.6 3.1 1.5 0.2 setosa\n", ".. ... ... ... ... ...\n", "4 5.0 3.6 1.4 0.2 setosa\n", "145 6.7 3.0 5.2 2.3 virginica\n", "146 6.3 2.5 5.0 1.9 virginica\n", "147 6.5 3.0 5.2 2.0 virginica\n", "148 6.2 3.4 5.4 2.3 virginica\n", "149 5.9 3.0 5.1 1.8 virginica\n", "\n", "[150 rows x 5 columns]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris = iris >> mutate(Species=as_factor(f.Species))\n", "iris" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:59.313067Z", "iopub.status.busy": "2021-07-16T22:27:59.312246Z", "iopub.status.idle": "2021-07-16T22:27:59.316329Z", "shell.execute_reply": "2021-07-16T22:27:59.316704Z" } }, "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", "
Sepal_LengthSepal_WidthPetal_LengthPetal_WidthSpecies
<float64><float64><float64><float64><object>
05.13.51.40.2setosa
14.93.01.40.2setosa
24.73.21.30.2setosa
34.63.11.50.2setosa
..................
45.03.61.40.2setosa
1456.73.05.22.3virginica
1466.32.55.01.9virginica
1476.53.05.22.0virginica
1486.23.45.42.3virginica
1495.93.05.11.8virginica
\n", "

150 rows × 5 columns

\n", "
\n" ], "text/plain": [ " Sepal_Length Sepal_Width Petal_Length Petal_Width Species\n", " \n", "0 5.1 3.5 1.4 0.2 setosa\n", "1 4.9 3.0 1.4 0.2 setosa\n", "2 4.7 3.2 1.3 0.2 setosa\n", "3 4.6 3.1 1.5 0.2 setosa\n", ".. ... ... ... ... ...\n", "4 5.0 3.6 1.4 0.2 setosa\n", "145 6.7 3.0 5.2 2.3 virginica\n", "146 6.3 2.5 5.0 1.9 virginica\n", "147 6.5 3.0 5.2 2.0 virginica\n", "148 6.2 3.4 5.4 2.3 virginica\n", "149 5.9 3.0 5.1 1.8 virginica\n", "\n", "[150 rows x 5 columns]" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris = iris >> mutate(across(where(is_factor), as_character))\n", "iris" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:59.323629Z", "iopub.status.busy": "2021-07-16T22:27:59.322970Z", "iopub.status.idle": "2021-07-16T22:27:59.430004Z", "shell.execute_reply": "2021-07-16T22:27:59.430376Z" } }, "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", "
SpeciesSepal_LengthSepal_Width
<object><float64><float64>
0setosa5.0063.428
1versicolor5.9362.770
2virginica6.5882.974
\n", "
\n" ], "text/plain": [ " Species Sepal_Length Sepal_Width\n", " \n", "0 setosa 5.006 3.428\n", "1 versicolor 5.936 2.770\n", "2 virginica 6.588 2.974" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> group_by(f.Species) >> summarise(\n", " across(starts_with(\"Sepal\"), mean)\n", ")" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:59.476402Z", "iopub.status.busy": "2021-07-16T22:27:59.464178Z", "iopub.status.idle": "2021-07-16T22:27:59.489956Z", "shell.execute_reply": "2021-07-16T22:27:59.489325Z" } }, "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", "
SpeciesSepal_Length_meanSepal_Length_sdSepal_Width_meanSepal_Width_sd
<object><float64><float64><float64><float64>
0setosa5.0060.3524903.4280.379064
1versicolor5.9360.5161712.7700.313798
2virginica6.5880.6358802.9740.322497
\n", "
\n" ], "text/plain": [ " Species Sepal_Length_mean Sepal_Length_sd Sepal_Width_mean \\\n", " \n", "0 setosa 5.006 0.352490 3.428 \n", "1 versicolor 5.936 0.516171 2.770 \n", "2 virginica 6.588 0.635880 2.974 \n", "\n", " Sepal_Width_sd \n", " \n", "0 0.379064 \n", "1 0.313798 \n", "2 0.322497 " ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> group_by(f.Species) >> summarise(\n", " across(starts_with(\"Sepal\"), dict(mean=mean, sd=sd))\n", ")" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:59.535876Z", "iopub.status.busy": "2021-07-16T22:27:59.534904Z", "iopub.status.idle": "2021-07-16T22:27:59.540790Z", "shell.execute_reply": "2021-07-16T22:27:59.541269Z" } }, "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", "
Speciesmean_Sepal_Lengthmean_Sepal_Width
<object><float64><float64>
0setosa5.0063.428
1versicolor5.9362.770
2virginica6.5882.974
\n", "
\n" ], "text/plain": [ " Species mean_Sepal_Length mean_Sepal_Width\n", " \n", "0 setosa 5.006 3.428\n", "1 versicolor 5.936 2.770\n", "2 virginica 6.588 2.974" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> group_by(f.Species) >> summarise(\n", " across(starts_with(\"Sepal\"), mean, _names = \"mean_{_col}\")\n", ")" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:59.603677Z", "iopub.status.busy": "2021-07-16T22:27:59.599601Z", "iopub.status.idle": "2021-07-16T22:27:59.632534Z", "shell.execute_reply": "2021-07-16T22:27:59.632981Z" } }, "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", "
SpeciesSepal_Length.meanSepal_Length.sdSepal_Width.meanSepal_Width.sd
<object><float64><float64><float64><float64>
0setosa5.0060.3524903.4280.379064
1versicolor5.9360.5161712.7700.313798
2virginica6.5880.6358802.9740.322497
\n", "
\n" ], "text/plain": [ " Species Sepal_Length.mean Sepal_Length.sd Sepal_Width.mean \\\n", " \n", "0 setosa 5.006 0.352490 3.428 \n", "1 versicolor 5.936 0.516171 2.770 \n", "2 virginica 6.588 0.635880 2.974 \n", "\n", " Sepal_Width.sd \n", " \n", "0 0.379064 \n", "1 0.313798 \n", "2 0.322497 " ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> group_by(f.Species) >> summarise(\n", " across(starts_with(\"Sepal\"), dict(mean=mean, sd=sd), _names = \"{_col}.{_fn}\")\n", ")" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:59.656313Z", "iopub.status.busy": "2021-07-16T22:27:59.646789Z", "iopub.status.idle": "2021-07-16T22:27:59.685316Z", "shell.execute_reply": "2021-07-16T22:27:59.686236Z" } }, "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", "
SpeciesSepal_Length.fn0Sepal_Length.fn1Sepal_Width.fn0Sepal_Width.fn1
<object><float64><float64><float64><float64>
0setosa5.0060.3524903.4280.379064
1versicolor5.9360.5161712.7700.313798
2virginica6.5880.6358802.9740.322497
\n", "
\n" ], "text/plain": [ " Species Sepal_Length.fn0 Sepal_Length.fn1 Sepal_Width.fn0 \\\n", " \n", "0 setosa 5.006 0.352490 3.428 \n", "1 versicolor 5.936 0.516171 2.770 \n", "2 virginica 6.588 0.635880 2.974 \n", "\n", " Sepal_Width.fn1 \n", " \n", "0 0.379064 \n", "1 0.313798 \n", "2 0.322497 " ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> group_by(f.Species) >> summarise(\n", " across(starts_with(\"Sepal\"), [mean, sd], _names = \"{_col}.fn{_fn}\")\n", ")" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:59.713809Z", "iopub.status.busy": "2021-07-16T22:27:59.707052Z", "iopub.status.idle": "2021-07-16T22:27:59.743071Z", "shell.execute_reply": "2021-07-16T22:27:59.742422Z" } }, "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", "
SpeciesSepal_Length.fn0Sepal_Length.fn1Sepal_Width.fn0Sepal_Width.fn1
<object><float64><float64><float64><float64>
0setosa5.0060.3524903.4280.379064
1versicolor5.9360.5161712.7700.313798
2virginica6.5880.6358802.9740.322497
\n", "
\n" ], "text/plain": [ " Species Sepal_Length.fn0 Sepal_Length.fn1 Sepal_Width.fn0 \\\n", " \n", "0 setosa 5.006 0.352490 3.428 \n", "1 versicolor 5.936 0.516171 2.770 \n", "2 virginica 6.588 0.635880 2.974 \n", "\n", " Sepal_Width.fn1 \n", " \n", "0 0.379064 \n", "1 0.313798 \n", "2 0.322497 " ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> group_by(f.Species) >> summarise(\n", " across(\n", " starts_with(\"Sepal\"), \n", " [mean, sd], \n", " _names=\"{_col}.fn{_fn}\", \n", " )\n", ")\n", "# or use _fn0\n", "\n", "# iris >> group_by(f.Species) >> summarise(\n", "# across(\n", "# starts_with(\"Sepal\"), \n", "# [mean, sd], \n", "# _names=\"{_col}.fn{_fn1}\", # _fn1 for 1-based\n", "# )\n", "# )\n" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:59.779281Z", "iopub.status.busy": "2021-07-16T22:27:59.765592Z", "iopub.status.idle": "2021-07-16T22:27:59.796747Z", "shell.execute_reply": "2021-07-16T22:27:59.797320Z" } }, "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", "
SpeciesSepal_Length.fn1Sepal_Length.fn2Sepal_Width.fn1Sepal_Width.fn2
<object><float64><float64><float64><float64>
0setosa5.0060.3524903.4280.379064
1versicolor5.9360.5161712.7700.313798
2virginica6.5880.6358802.9740.322497
\n", "
\n" ], "text/plain": [ " Species Sepal_Length.fn1 Sepal_Length.fn2 Sepal_Width.fn1 \\\n", " \n", "0 setosa 5.006 0.352490 3.428 \n", "1 versicolor 5.936 0.516171 2.770 \n", "2 virginica 6.588 0.635880 2.974 \n", "\n", " Sepal_Width.fn2 \n", " \n", "0 0.379064 \n", "1 0.313798 \n", "2 0.322497 " ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> group_by(f.Species) >> summarise(\n", " across(starts_with(\"Sepal\"), [mean, sd], _names = \"{_col}.fn{_fn1}\")\n", ")" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:59.844111Z", "iopub.status.busy": "2021-07-16T22:27:59.843152Z", "iopub.status.idle": "2021-07-16T22:27:59.848164Z", "shell.execute_reply": "2021-07-16T22:27:59.848519Z" } }, "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", "
Sepal_LengthSepal_WidthPetal_LengthPetal_WidthSpecies
<float64><float64><float64><float64><object>
155.74.41.50.4setosa
325.24.11.50.1setosa
335.54.21.40.2setosa
\n", "
\n" ], "text/plain": [ " Sepal_Length Sepal_Width Petal_Length Petal_Width Species\n", " \n", "15 5.7 4.4 1.5 0.4 setosa\n", "32 5.2 4.1 1.5 0.1 setosa\n", "33 5.5 4.2 1.4 0.2 setosa" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> filter(if_any(ends_with(\"Width\"), lambda x: x > 4))" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:59.905288Z", "iopub.status.busy": "2021-07-16T22:27:59.904617Z", "iopub.status.idle": "2021-07-16T22:27:59.908420Z", "shell.execute_reply": "2021-07-16T22:27:59.908759Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Sepal_LengthSepal_WidthPetal_LengthPetal_WidthSpecies
<float64><float64><float64><float64><object>
1006.33.36.02.5virginica
1027.13.05.92.1virginica
1046.53.05.82.2virginica
1057.63.06.62.1virginica
1097.23.66.12.5virginica
1126.83.05.52.1virginica
1145.82.85.12.4virginica
1156.43.25.32.3virginica
1177.73.86.72.2virginica
1187.72.66.92.3virginica
1206.93.25.72.3virginica
1246.73.35.72.1virginica
1286.42.85.62.1virginica
1326.42.85.62.2virginica
1357.73.06.12.3virginica
1366.33.45.62.4virginica
1396.93.15.42.1virginica
1406.73.15.62.4virginica
1416.93.15.12.3virginica
1436.83.25.92.3virginica
1446.73.35.72.5virginica
1456.73.05.22.3virginica
1486.23.45.42.3virginica
\n", "
\n" ], "text/plain": [ " Sepal_Length Sepal_Width Petal_Length Petal_Width Species\n", " \n", "100 6.3 3.3 6.0 2.5 virginica\n", "102 7.1 3.0 5.9 2.1 virginica\n", "104 6.5 3.0 5.8 2.2 virginica\n", "105 7.6 3.0 6.6 2.1 virginica\n", "109 7.2 3.6 6.1 2.5 virginica\n", "112 6.8 3.0 5.5 2.1 virginica\n", "114 5.8 2.8 5.1 2.4 virginica\n", "115 6.4 3.2 5.3 2.3 virginica\n", "117 7.7 3.8 6.7 2.2 virginica\n", "118 7.7 2.6 6.9 2.3 virginica\n", "120 6.9 3.2 5.7 2.3 virginica\n", "124 6.7 3.3 5.7 2.1 virginica\n", "128 6.4 2.8 5.6 2.1 virginica\n", "132 6.4 2.8 5.6 2.2 virginica\n", "135 7.7 3.0 6.1 2.3 virginica\n", "136 6.3 3.4 5.6 2.4 virginica\n", "139 6.9 3.1 5.4 2.1 virginica\n", "140 6.7 3.1 5.6 2.4 virginica\n", "141 6.9 3.1 5.1 2.3 virginica\n", "143 6.8 3.2 5.9 2.3 virginica\n", "144 6.7 3.3 5.7 2.5 virginica\n", "145 6.7 3.0 5.2 2.3 virginica\n", "148 6.2 3.4 5.4 2.3 virginica" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> filter(if_all(ends_with(\"Width\"), lambda x: x > 2))" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:59.920276Z", "iopub.status.busy": "2021-07-16T22:27:59.916671Z", "iopub.status.idle": "2021-07-16T22:28:00.168161Z", "shell.execute_reply": "2021-07-16T22:28:00.167035Z" }, "tags": [] }, "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", "
idwxyzsumsd
<int64><float64><float64><float64><float64><float64><float64>
010.9092930.8804560.1742130.3825931.9639620.416324
120.1029120.9528110.6325360.8459201.6882580.429225
230.4255920.3202750.8035150.8315331.5493820.254112
340.2184720.8491900.6378530.8879801.7055140.321026
\n", "
\n", "

TibbleRowwise: (n=4)" ], "text/plain": [ " id w x y z sum sd\n", " \n", "0 1 0.909293 0.880456 0.174213 0.382593 1.963962 0.416324\n", "1 2 0.102912 0.952811 0.632536 0.845920 1.688258 0.429225\n", "2 3 0.425592 0.320275 0.803515 0.831533 1.549382 0.254112\n", "3 4 0.218472 0.849190 0.637853 0.887980 1.705514 0.321026\n", "[TibbleRowwise: (n=4)]" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(\n", " id=[1, 2, 3, 4],\n", " w=runif(4), \n", " x=runif(4), \n", " y=runif(4), \n", " z=runif(4)\n", ")\n", "df >> rowwise() >> mutate(\n", " sum = sum(c_across(c[f.w:f.z])),\n", " sd = sd(c_across(c[f.w:f.z]))\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 4 } ================================================ FILE: docs/notebooks/add_column.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:27.609283Z", "iopub.status.busy": "2021-07-16T22:28:27.607781Z", "iopub.status.idle": "2021-07-16T22:28:28.439771Z", "shell.execute_reply": "2021-07-16T22:28:28.440308Z" } }, "outputs": [ { "data": { "text/html": [ "

Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ add_column
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Add one or more columns to an existing data frame.\n", "\n", "##### Args:\n", "  `_data`: Data frame to append to \n", "  `*args`: and \n", "  `**kwargs`: Name-value pairs to add to the data frame \n", "  `_before`: and \n", "  `_after`: Column index or name where to add the new columns \n", "    (default to add after the last column) \n", "\n", "  `_dtypes`: The dtypes for the new columns, either a uniform dtype or a \n", "    dict of dtypes with keys the column names \n", "\n", "##### Returns:\n", "  The dataframe with the added columns \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://tibble.tidyverse.org/reference/add_column.html\n", "\n", "from datar import f\n", "from datar.tibble import *\n", "from datar.base import seq\n", "from datar.core.names import NameNonUniqueError\n", "\n", "%run nb_helpers.py\n", "nb_header(add_column)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:28.449685Z", "iopub.status.busy": "2021-07-16T22:28:28.449088Z", "iopub.status.idle": "2021-07-16T22:28:28.691135Z", "shell.execute_reply": "2021-07-16T22:28:28.691675Z" } }, "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", "
xyzw
<int64><int64><int64><int64>
013-10
12200
23110
\n", "
\n" ], "text/plain": [ " x y z w\n", " \n", "0 1 3 -1 0\n", "1 2 2 0 0\n", "2 3 1 1 0" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x=seq(1,3), y=seq(3,1))\n", "df >> add_column(z=seq(-1,1), w=0)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:28.701403Z", "iopub.status.busy": "2021-07-16T22:28:28.700765Z", "iopub.status.idle": "2021-07-16T22:28:28.726181Z", "shell.execute_reply": "2021-07-16T22:28:28.725600Z" } }, "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", "
xzy
<int64><int64><int64>
01-13
1202
2311
\n", "
\n" ], "text/plain": [ " x z y\n", " \n", "0 1 -1 3\n", "1 2 0 2\n", "2 3 1 1" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> add_column(z=seq(-1,1), _before=f.y)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:28.734549Z", "iopub.status.busy": "2021-07-16T22:28:28.733777Z", "iopub.status.idle": "2021-07-16T22:28:28.751592Z", "shell.execute_reply": "2021-07-16T22:28:28.751990Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Names must be unique: x\n" ] } ], "source": [ "# You can't overwrite existing columns\n", "try:\n", " df >> add_column(x = seq(4,6))\n", "except NameNonUniqueError as err:\n", " print(err)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:28.760324Z", "iopub.status.busy": "2021-07-16T22:28:28.759646Z", "iopub.status.idle": "2021-07-16T22:28:28.776413Z", "shell.execute_reply": "2021-07-16T22:28:28.776819Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[ValueError] Value has incompatible index.\n" ] } ], "source": [ "# You can't create new observations\n", "with try_catch():\n", " df >> add_column(z = seq(1,5))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 2 } ================================================ FILE: docs/notebooks/add_row.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:37.155229Z", "iopub.status.busy": "2021-07-16T22:28:37.154001Z", "iopub.status.idle": "2021-07-16T22:28:38.126642Z", "shell.execute_reply": "2021-07-16T22:28:38.126158Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ add_row
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Add one or more rows of data to an existing data frame.\n", "\n", "Aliases `add_case` \n", "\n", "##### Args:\n", "  `_data`: Data frame to append to. \n", "  `*args`: and \n", "  `**kwargs`: Name-value pairs to add to the data frame. \n", "  `_before`: and \n", "  `_after`: row index where to add the new rows. \n", "    (default to add after the last row) \n", "\n", "##### Returns:\n", "  The dataframe with the added rows \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://tibble.tidyverse.org/reference/add_row.html\n", "\n", "from datar.tibble import *\n", "from datar.base import seq\n", "\n", "%run nb_helpers.py\n", "nb_header(add_row)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:38.136586Z", "iopub.status.busy": "2021-07-16T22:28:38.135976Z", "iopub.status.idle": "2021-07-16T22:28:38.352815Z", "shell.execute_reply": "2021-07-16T22:28:38.353207Z" } }, "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", "
xy
<int64><int64>
013
122
231
340
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 1 3\n", "1 2 2\n", "2 3 1\n", "3 4 0" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x=seq(1,3), y=seq(3,1))\n", "\n", "df >> add_row(x=4, y=0)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:38.358707Z", "iopub.status.busy": "2021-07-16T22:28:38.358197Z", "iopub.status.idle": "2021-07-16T22:28:38.384681Z", "shell.execute_reply": "2021-07-16T22:28:38.385116Z" } }, "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", "
xy
<int64><int64>
013
122
240
331
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 1 3\n", "1 2 2\n", "2 4 0\n", "3 3 1" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> add_row(x=4, y=0, _before=2) # 0-based" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:38.391117Z", "iopub.status.busy": "2021-07-16T22:28:38.390590Z", "iopub.status.idle": "2021-07-16T22:28:38.413779Z", "shell.execute_reply": "2021-07-16T22:28:38.412299Z" } }, "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", "
xy
<int64><int64>
013
122
231
340
45-1
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 1 3\n", "1 2 2\n", "2 3 1\n", "3 4 0\n", "4 5 -1" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> add_row(x=[4,5], y=[0,-1])" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:38.424155Z", "iopub.status.busy": "2021-07-16T22:28:38.423508Z", "iopub.status.idle": "2021-07-16T22:28:38.462307Z", "shell.execute_reply": "2021-07-16T22:28:38.461644Z" } }, "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", "
xy
<int64><int64>
013
122
231
340
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 1 3\n", "1 2 2\n", "2 3 1\n", "3 4 0" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> add_row(tibble_row(x = 4, y = 0))" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:38.468293Z", "iopub.status.busy": "2021-07-16T22:28:38.467594Z", "iopub.status.idle": "2021-07-16T22:28:38.490614Z", "shell.execute_reply": "2021-07-16T22:28:38.490121Z" } }, "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", "
xy
<int64><float64>
013.0
122.0
231.0
34NaN
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 1 3.0\n", "1 2 2.0\n", "2 3 1.0\n", "3 4 NaN" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Absent variables get missing values\n", "df >> add_row(x = 4)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:38.496679Z", "iopub.status.busy": "2021-07-16T22:28:38.495337Z", "iopub.status.idle": "2021-07-16T22:28:38.510857Z", "shell.execute_reply": "2021-07-16T22:28:38.510477Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[ValueError] New rows can't add columns: ['z']\n" ] } ], "source": [ "# You can't create new variables\n", "with try_catch():\n", " df >> add_row(z = 10)" ] } ], "metadata": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" }, "kernelspec": { "display_name": "Python 3.7.8 64-bit ('base': conda)", "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.9.5" } }, "nbformat": 4, "nbformat_minor": 2 } ================================================ FILE: docs/notebooks/arrange.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:27.284608Z", "iopub.status.busy": "2021-07-16T22:27:27.283990Z", "iopub.status.idle": "2021-07-16T22:27:28.422024Z", "shell.execute_reply": "2021-07-16T22:27:28.420765Z" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ arrange
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### orders the rows of a data frame by the values of selected columns.\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/arrange.html \n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `*series`: Variables, or functions of variables. \n", "    Use desc() to sort a variable in descending order. \n", "\n", "  `_by_group`: If TRUE, will sort first by grouping variable. \n", "    Applies to grouped data frames only. \n", "\n", "  `**kwargs`: Name-value pairs that apply with mutate \n", "\n", "##### Returns:\n", "  An object of the same type as _data. \n", "  The output has the following properties: \n", "    All rows appear in the output, but (usually) in a different place. \n", "    Columns are not modified. \n", "    Groups are not modified. \n", "    Data frame attributes are preserved. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%run nb_helpers.py\n", "from datar.data import mtcars, iris\n", "from datar.all import *\n", "\n", "nb_header(arrange)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:28.459542Z", "iopub.status.busy": "2021-07-16T22:27:28.458987Z", "iopub.status.idle": "2021-07-16T22:27:28.666964Z", "shell.execute_reply": "2021-07-16T22:27:28.667381Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Toyota Corolla33.9471.1654.221.83519.901141
Honda Civic30.4475.7524.931.61518.521142
Fiat 12832.4478.7664.082.20019.471141
Fiat X1-927.3479.0664.081.93518.901141
Lotus Europa30.4495.11133.771.51316.901152
Datsun 71022.84108.0933.852.32018.611141
Toyota Corona21.54120.1973.702.46520.011031
Porsche 914-226.04120.3914.432.14016.700152
Volvo 142E21.44121.01094.112.78018.601142
Merc 23022.84140.8953.923.15022.901042
Merc 240D24.44146.7623.693.19020.001042
Ferrari Dino19.76145.01753.622.77015.500156
Mazda RX421.06160.01103.902.62016.460144
Mazda RX4 Wag21.06160.01103.902.87517.020144
Merc 28019.26167.61233.923.44018.301044
Merc 280C17.86167.61233.923.44018.901044
Valiant18.16225.01052.763.46020.221031
Hornet 4 Drive21.46258.01103.083.21519.441031
Merc 450SE16.48275.81803.074.07017.400033
Merc 450SL17.38275.81803.073.73017.600033
Merc 450SLC15.28275.81803.073.78018.000033
Maserati Bora15.08301.03353.543.57014.600158
AMC Javelin15.28304.01503.153.43517.300032
Dodge Challenger15.58318.01502.763.52016.870032
Camaro Z2813.38350.02453.733.84015.410034
Ford Pantera L15.88351.02644.223.17014.500154
Hornet Sportabout18.78360.01753.153.44017.020032
Duster 36014.38360.02453.213.57015.840034
Pontiac Firebird19.28400.01753.083.84517.050032
Chrysler Imperial14.78440.02303.235.34517.420034
Lincoln Continental10.48460.02153.005.42417.820034
Cadillac Fleetwood10.48472.02052.935.25017.980034
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt \\\n", " \n", "Toyota Corolla 33.9 4 71.1 65 4.22 1.835 \n", "Honda Civic 30.4 4 75.7 52 4.93 1.615 \n", "Fiat 128 32.4 4 78.7 66 4.08 2.200 \n", "Fiat X1-9 27.3 4 79.0 66 4.08 1.935 \n", "Lotus Europa 30.4 4 95.1 113 3.77 1.513 \n", "Datsun 710 22.8 4 108.0 93 3.85 2.320 \n", "Toyota Corona 21.5 4 120.1 97 3.70 2.465 \n", "Porsche 914-2 26.0 4 120.3 91 4.43 2.140 \n", "Volvo 142E 21.4 4 121.0 109 4.11 2.780 \n", "Merc 230 22.8 4 140.8 95 3.92 3.150 \n", "Merc 240D 24.4 4 146.7 62 3.69 3.190 \n", "Ferrari Dino 19.7 6 145.0 175 3.62 2.770 \n", "Mazda RX4 21.0 6 160.0 110 3.90 2.620 \n", "Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 \n", "Merc 280 19.2 6 167.6 123 3.92 3.440 \n", "Merc 280C 17.8 6 167.6 123 3.92 3.440 \n", "Valiant 18.1 6 225.0 105 2.76 3.460 \n", "Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 \n", "Merc 450SE 16.4 8 275.8 180 3.07 4.070 \n", "Merc 450SL 17.3 8 275.8 180 3.07 3.730 \n", "Merc 450SLC 15.2 8 275.8 180 3.07 3.780 \n", "Maserati Bora 15.0 8 301.0 335 3.54 3.570 \n", "AMC Javelin 15.2 8 304.0 150 3.15 3.435 \n", "Dodge Challenger 15.5 8 318.0 150 2.76 3.520 \n", "Camaro Z28 13.3 8 350.0 245 3.73 3.840 \n", "Ford Pantera L 15.8 8 351.0 264 4.22 3.170 \n", "Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 \n", "Duster 360 14.3 8 360.0 245 3.21 3.570 \n", "Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 \n", "Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 \n", "Lincoln Continental 10.4 8 460.0 215 3.00 5.424 \n", "Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 \n", "\n", " qsec vs am gear carb \n", " \n", "Toyota Corolla 19.90 1 1 4 1 \n", "Honda Civic 18.52 1 1 4 2 \n", "Fiat 128 19.47 1 1 4 1 \n", "Fiat X1-9 18.90 1 1 4 1 \n", "Lotus Europa 16.90 1 1 5 2 \n", "Datsun 710 18.61 1 1 4 1 \n", "Toyota Corona 20.01 1 0 3 1 \n", "Porsche 914-2 16.70 0 1 5 2 \n", "Volvo 142E 18.60 1 1 4 2 \n", "Merc 230 22.90 1 0 4 2 \n", "Merc 240D 20.00 1 0 4 2 \n", "Ferrari Dino 15.50 0 1 5 6 \n", "Mazda RX4 16.46 0 1 4 4 \n", "Mazda RX4 Wag 17.02 0 1 4 4 \n", "Merc 280 18.30 1 0 4 4 \n", "Merc 280C 18.90 1 0 4 4 \n", "Valiant 20.22 1 0 3 1 \n", "Hornet 4 Drive 19.44 1 0 3 1 \n", "Merc 450SE 17.40 0 0 3 3 \n", "Merc 450SL 17.60 0 0 3 3 \n", "Merc 450SLC 18.00 0 0 3 3 \n", "Maserati Bora 14.60 0 1 5 8 \n", "AMC Javelin 17.30 0 0 3 2 \n", "Dodge Challenger 16.87 0 0 3 2 \n", "Camaro Z28 15.41 0 0 3 4 \n", "Ford Pantera L 14.50 0 1 5 4 \n", "Hornet Sportabout 17.02 0 0 3 2 \n", "Duster 360 15.84 0 0 3 4 \n", "Pontiac Firebird 17.05 0 0 3 2 \n", "Chrysler Imperial 17.42 0 0 3 4 \n", "Lincoln Continental 17.82 0 0 3 4 \n", "Cadillac Fleetwood 17.98 0 0 3 4 " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arrange(mtcars, f.cyl, f.disp)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:28.702043Z", "iopub.status.busy": "2021-07-16T22:27:28.701441Z", "iopub.status.idle": "2021-07-16T22:27:28.708757Z", "shell.execute_reply": "2021-07-16T22:27:28.709182Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Cadillac Fleetwood10.48472.02052.935.25017.980034
Lincoln Continental10.48460.02153.005.42417.820034
Chrysler Imperial14.78440.02303.235.34517.420034
Pontiac Firebird19.28400.01753.083.84517.050032
Hornet Sportabout18.78360.01753.153.44017.020032
Duster 36014.38360.02453.213.57015.840034
Ford Pantera L15.88351.02644.223.17014.500154
Camaro Z2813.38350.02453.733.84015.410034
Dodge Challenger15.58318.01502.763.52016.870032
AMC Javelin15.28304.01503.153.43517.300032
Maserati Bora15.08301.03353.543.57014.600158
Merc 450SE16.48275.81803.074.07017.400033
Merc 450SL17.38275.81803.073.73017.600033
Merc 450SLC15.28275.81803.073.78018.000033
Hornet 4 Drive21.46258.01103.083.21519.441031
Valiant18.16225.01052.763.46020.221031
Merc 28019.26167.61233.923.44018.301044
Merc 280C17.86167.61233.923.44018.901044
Mazda RX421.06160.01103.902.62016.460144
Mazda RX4 Wag21.06160.01103.902.87517.020144
Merc 240D24.44146.7623.693.19020.001042
Ferrari Dino19.76145.01753.622.77015.500156
Merc 23022.84140.8953.923.15022.901042
Volvo 142E21.44121.01094.112.78018.601142
Porsche 914-226.04120.3914.432.14016.700152
Toyota Corona21.54120.1973.702.46520.011031
Datsun 71022.84108.0933.852.32018.611141
Lotus Europa30.4495.11133.771.51316.901152
Fiat X1-927.3479.0664.081.93518.901141
Fiat 12832.4478.7664.082.20019.471141
Honda Civic30.4475.7524.931.61518.521142
Toyota Corolla33.9471.1654.221.83519.901141
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt \\\n", " \n", "Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 \n", "Lincoln Continental 10.4 8 460.0 215 3.00 5.424 \n", "Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 \n", "Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 \n", "Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 \n", "Duster 360 14.3 8 360.0 245 3.21 3.570 \n", "Ford Pantera L 15.8 8 351.0 264 4.22 3.170 \n", "Camaro Z28 13.3 8 350.0 245 3.73 3.840 \n", "Dodge Challenger 15.5 8 318.0 150 2.76 3.520 \n", "AMC Javelin 15.2 8 304.0 150 3.15 3.435 \n", "Maserati Bora 15.0 8 301.0 335 3.54 3.570 \n", "Merc 450SE 16.4 8 275.8 180 3.07 4.070 \n", "Merc 450SL 17.3 8 275.8 180 3.07 3.730 \n", "Merc 450SLC 15.2 8 275.8 180 3.07 3.780 \n", "Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 \n", "Valiant 18.1 6 225.0 105 2.76 3.460 \n", "Merc 280 19.2 6 167.6 123 3.92 3.440 \n", "Merc 280C 17.8 6 167.6 123 3.92 3.440 \n", "Mazda RX4 21.0 6 160.0 110 3.90 2.620 \n", "Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 \n", "Merc 240D 24.4 4 146.7 62 3.69 3.190 \n", "Ferrari Dino 19.7 6 145.0 175 3.62 2.770 \n", "Merc 230 22.8 4 140.8 95 3.92 3.150 \n", "Volvo 142E 21.4 4 121.0 109 4.11 2.780 \n", "Porsche 914-2 26.0 4 120.3 91 4.43 2.140 \n", "Toyota Corona 21.5 4 120.1 97 3.70 2.465 \n", "Datsun 710 22.8 4 108.0 93 3.85 2.320 \n", "Lotus Europa 30.4 4 95.1 113 3.77 1.513 \n", "Fiat X1-9 27.3 4 79.0 66 4.08 1.935 \n", "Fiat 128 32.4 4 78.7 66 4.08 2.200 \n", "Honda Civic 30.4 4 75.7 52 4.93 1.615 \n", "Toyota Corolla 33.9 4 71.1 65 4.22 1.835 \n", "\n", " qsec vs am gear carb \n", " \n", "Cadillac Fleetwood 17.98 0 0 3 4 \n", "Lincoln Continental 17.82 0 0 3 4 \n", "Chrysler Imperial 17.42 0 0 3 4 \n", "Pontiac Firebird 17.05 0 0 3 2 \n", "Hornet Sportabout 17.02 0 0 3 2 \n", "Duster 360 15.84 0 0 3 4 \n", "Ford Pantera L 14.50 0 1 5 4 \n", "Camaro Z28 15.41 0 0 3 4 \n", "Dodge Challenger 16.87 0 0 3 2 \n", "AMC Javelin 17.30 0 0 3 2 \n", "Maserati Bora 14.60 0 1 5 8 \n", "Merc 450SE 17.40 0 0 3 3 \n", "Merc 450SL 17.60 0 0 3 3 \n", "Merc 450SLC 18.00 0 0 3 3 \n", "Hornet 4 Drive 19.44 1 0 3 1 \n", "Valiant 20.22 1 0 3 1 \n", "Merc 280 18.30 1 0 4 4 \n", "Merc 280C 18.90 1 0 4 4 \n", "Mazda RX4 16.46 0 1 4 4 \n", "Mazda RX4 Wag 17.02 0 1 4 4 \n", "Merc 240D 20.00 1 0 4 2 \n", "Ferrari Dino 15.50 0 1 5 6 \n", "Merc 230 22.90 1 0 4 2 \n", "Volvo 142E 18.60 1 1 4 2 \n", "Porsche 914-2 16.70 0 1 5 2 \n", "Toyota Corona 20.01 1 0 3 1 \n", "Datsun 710 18.61 1 1 4 1 \n", "Lotus Europa 16.90 1 1 5 2 \n", "Fiat X1-9 18.90 1 1 4 1 \n", "Fiat 128 19.47 1 1 4 1 \n", "Honda Civic 18.52 1 1 4 2 \n", "Toyota Corolla 19.90 1 1 4 1 " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> arrange(desc(f.disp))" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:28.765555Z", "iopub.status.busy": "2021-07-16T22:27:28.761172Z", "iopub.status.idle": "2021-07-16T22:27:28.771559Z", "shell.execute_reply": "2021-07-16T22:27:28.771941Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
010.48460.02153.005.42417.820034
114.78440.02303.235.34517.420034
210.48472.02052.935.25017.980034
316.48275.81803.074.07017.400033
419.28400.01753.083.84517.050032
513.38350.02453.733.84015.410034
615.28275.81803.073.78018.000033
717.38275.81803.073.73017.600033
815.08301.03353.543.57014.600158
914.38360.02453.213.57015.840034
1015.58318.01502.763.52016.870032
1118.16225.01052.763.46020.221031
1219.26167.61233.923.44018.301044
1318.78360.01753.153.44017.020032
1417.86167.61233.923.44018.901044
1515.28304.01503.153.43517.300032
1621.46258.01103.083.21519.441031
1724.44146.7623.693.19020.001042
1815.88351.02644.223.17014.500154
1922.84140.8953.923.15022.901042
2021.06160.01103.902.87517.020144
2121.44121.01094.112.78018.601142
2219.76145.01753.622.77015.500156
2321.06160.01103.902.62016.460144
2421.54120.1973.702.46520.011031
2522.84108.0933.852.32018.611141
2632.4478.7664.082.20019.471141
2726.04120.3914.432.14016.700152
2827.3479.0664.081.93518.901141
2933.9471.1654.221.83519.901141
3030.4475.7524.931.61518.521142
3130.4495.11133.771.51316.901152
\n", "
\n", "

TibbleGrouped: cyl (n=3)" ], "text/plain": [ " mpg cyl disp hp drat wt qsec vs \\\n", " \n", "0 10.4 8 460.0 215 3.00 5.424 17.82 0 \n", "1 14.7 8 440.0 230 3.23 5.345 17.42 0 \n", "2 10.4 8 472.0 205 2.93 5.250 17.98 0 \n", "3 16.4 8 275.8 180 3.07 4.070 17.40 0 \n", "4 19.2 8 400.0 175 3.08 3.845 17.05 0 \n", "5 13.3 8 350.0 245 3.73 3.840 15.41 0 \n", "6 15.2 8 275.8 180 3.07 3.780 18.00 0 \n", "7 17.3 8 275.8 180 3.07 3.730 17.60 0 \n", "8 15.0 8 301.0 335 3.54 3.570 14.60 0 \n", "9 14.3 8 360.0 245 3.21 3.570 15.84 0 \n", "10 15.5 8 318.0 150 2.76 3.520 16.87 0 \n", "11 18.1 6 225.0 105 2.76 3.460 20.22 1 \n", "12 19.2 6 167.6 123 3.92 3.440 18.30 1 \n", "13 18.7 8 360.0 175 3.15 3.440 17.02 0 \n", "14 17.8 6 167.6 123 3.92 3.440 18.90 1 \n", "15 15.2 8 304.0 150 3.15 3.435 17.30 0 \n", "16 21.4 6 258.0 110 3.08 3.215 19.44 1 \n", "17 24.4 4 146.7 62 3.69 3.190 20.00 1 \n", "18 15.8 8 351.0 264 4.22 3.170 14.50 0 \n", "19 22.8 4 140.8 95 3.92 3.150 22.90 1 \n", "20 21.0 6 160.0 110 3.90 2.875 17.02 0 \n", "21 21.4 4 121.0 109 4.11 2.780 18.60 1 \n", "22 19.7 6 145.0 175 3.62 2.770 15.50 0 \n", "23 21.0 6 160.0 110 3.90 2.620 16.46 0 \n", "24 21.5 4 120.1 97 3.70 2.465 20.01 1 \n", "25 22.8 4 108.0 93 3.85 2.320 18.61 1 \n", "26 32.4 4 78.7 66 4.08 2.200 19.47 1 \n", "27 26.0 4 120.3 91 4.43 2.140 16.70 0 \n", "28 27.3 4 79.0 66 4.08 1.935 18.90 1 \n", "29 33.9 4 71.1 65 4.22 1.835 19.90 1 \n", "30 30.4 4 75.7 52 4.93 1.615 18.52 1 \n", "31 30.4 4 95.1 113 3.77 1.513 16.90 1 \n", "\n", " am gear carb \n", " \n", "0 0 3 4 \n", "1 0 3 4 \n", "2 0 3 4 \n", "3 0 3 3 \n", "4 0 3 2 \n", "5 0 3 4 \n", "6 0 3 3 \n", "7 0 3 3 \n", "8 1 5 8 \n", "9 0 3 4 \n", "10 0 3 2 \n", "11 0 3 1 \n", "12 0 4 4 \n", "13 0 3 2 \n", "14 0 4 4 \n", "15 0 3 2 \n", "16 0 3 1 \n", "17 0 4 2 \n", "18 1 5 4 \n", "19 0 4 2 \n", "20 1 4 4 \n", "21 1 4 2 \n", "22 1 5 6 \n", "23 1 4 4 \n", "24 0 3 1 \n", "25 1 4 1 \n", "26 1 4 1 \n", "27 1 5 2 \n", "28 1 4 1 \n", "29 1 4 1 \n", "30 1 4 2 \n", "31 1 5 2 \n", "[TibbleGrouped: cyl (n=3)]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "by_cyl = mtcars >> group_by(f.cyl)\n", "by_cyl >> arrange(desc(f.wt)) " ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:28.885725Z", "iopub.status.busy": "2021-07-16T22:27:28.885074Z", "iopub.status.idle": "2021-07-16T22:27:28.930266Z", "shell.execute_reply": "2021-07-16T22:27:28.933444Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
024.44146.7623.693.19020.001042
122.84140.8953.923.15022.901042
221.44121.01094.112.78018.601142
321.54120.1973.702.46520.011031
422.84108.0933.852.32018.611141
532.4478.7664.082.20019.471141
626.04120.3914.432.14016.700152
727.3479.0664.081.93518.901141
833.9471.1654.221.83519.901141
930.4475.7524.931.61518.521142
1030.4495.11133.771.51316.901152
1118.16225.01052.763.46020.221031
1219.26167.61233.923.44018.301044
1317.86167.61233.923.44018.901044
1421.46258.01103.083.21519.441031
1521.06160.01103.902.87517.020144
1619.76145.01753.622.77015.500156
1721.06160.01103.902.62016.460144
1810.48460.02153.005.42417.820034
1914.78440.02303.235.34517.420034
2010.48472.02052.935.25017.980034
2116.48275.81803.074.07017.400033
2219.28400.01753.083.84517.050032
2313.38350.02453.733.84015.410034
2415.28275.81803.073.78018.000033
2517.38275.81803.073.73017.600033
2614.38360.02453.213.57015.840034
2715.08301.03353.543.57014.600158
2815.58318.01502.763.52016.870032
2918.78360.01753.153.44017.020032
3015.28304.01503.153.43517.300032
3115.88351.02644.223.17014.500154
\n", "
\n", "

TibbleGrouped: cyl (n=3)" ], "text/plain": [ " mpg cyl disp hp drat wt qsec vs \\\n", " \n", "0 24.4 4 146.7 62 3.69 3.190 20.00 1 \n", "1 22.8 4 140.8 95 3.92 3.150 22.90 1 \n", "2 21.4 4 121.0 109 4.11 2.780 18.60 1 \n", "3 21.5 4 120.1 97 3.70 2.465 20.01 1 \n", "4 22.8 4 108.0 93 3.85 2.320 18.61 1 \n", "5 32.4 4 78.7 66 4.08 2.200 19.47 1 \n", "6 26.0 4 120.3 91 4.43 2.140 16.70 0 \n", "7 27.3 4 79.0 66 4.08 1.935 18.90 1 \n", "8 33.9 4 71.1 65 4.22 1.835 19.90 1 \n", "9 30.4 4 75.7 52 4.93 1.615 18.52 1 \n", "10 30.4 4 95.1 113 3.77 1.513 16.90 1 \n", "11 18.1 6 225.0 105 2.76 3.460 20.22 1 \n", "12 19.2 6 167.6 123 3.92 3.440 18.30 1 \n", "13 17.8 6 167.6 123 3.92 3.440 18.90 1 \n", "14 21.4 6 258.0 110 3.08 3.215 19.44 1 \n", "15 21.0 6 160.0 110 3.90 2.875 17.02 0 \n", "16 19.7 6 145.0 175 3.62 2.770 15.50 0 \n", "17 21.0 6 160.0 110 3.90 2.620 16.46 0 \n", "18 10.4 8 460.0 215 3.00 5.424 17.82 0 \n", "19 14.7 8 440.0 230 3.23 5.345 17.42 0 \n", "20 10.4 8 472.0 205 2.93 5.250 17.98 0 \n", "21 16.4 8 275.8 180 3.07 4.070 17.40 0 \n", "22 19.2 8 400.0 175 3.08 3.845 17.05 0 \n", "23 13.3 8 350.0 245 3.73 3.840 15.41 0 \n", "24 15.2 8 275.8 180 3.07 3.780 18.00 0 \n", "25 17.3 8 275.8 180 3.07 3.730 17.60 0 \n", "26 14.3 8 360.0 245 3.21 3.570 15.84 0 \n", "27 15.0 8 301.0 335 3.54 3.570 14.60 0 \n", "28 15.5 8 318.0 150 2.76 3.520 16.87 0 \n", "29 18.7 8 360.0 175 3.15 3.440 17.02 0 \n", "30 15.2 8 304.0 150 3.15 3.435 17.30 0 \n", "31 15.8 8 351.0 264 4.22 3.170 14.50 0 \n", "\n", " am gear carb \n", " \n", "0 0 4 2 \n", "1 0 4 2 \n", "2 1 4 2 \n", "3 0 3 1 \n", "4 1 4 1 \n", "5 1 4 1 \n", "6 1 5 2 \n", "7 1 4 1 \n", "8 1 4 1 \n", "9 1 4 2 \n", "10 1 5 2 \n", "11 0 3 1 \n", "12 0 4 4 \n", "13 0 4 4 \n", "14 0 3 1 \n", "15 1 4 4 \n", "16 1 5 6 \n", "17 1 4 4 \n", "18 0 3 4 \n", "19 0 3 4 \n", "20 0 3 4 \n", "21 0 3 3 \n", "22 0 3 2 \n", "23 0 3 4 \n", "24 0 3 3 \n", "25 0 3 3 \n", "26 0 3 4 \n", "27 1 5 8 \n", "28 0 3 2 \n", "29 0 3 2 \n", "30 0 3 2 \n", "31 1 5 4 \n", "[TibbleGrouped: cyl (n=3)]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "by_cyl >> arrange(desc(f.wt), _by_group=True) " ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:28.971525Z", "iopub.status.busy": "2021-07-16T22:27:28.970960Z", "iopub.status.idle": "2021-07-16T22:27:28.983870Z", "shell.execute_reply": "2021-07-16T22:27:28.984279Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Lincoln Continental10.48460.02153.005.42417.820034
Cadillac Fleetwood10.48472.02052.935.25017.980034
Camaro Z2813.38350.02453.733.84015.410034
Duster 36014.38360.02453.213.57015.840034
Chrysler Imperial14.78440.02303.235.34517.420034
Maserati Bora15.08301.03353.543.57014.600158
Merc 450SLC15.28275.81803.073.78018.000033
AMC Javelin15.28304.01503.153.43517.300032
Dodge Challenger15.58318.01502.763.52016.870032
Ford Pantera L15.88351.02644.223.17014.500154
Merc 450SE16.48275.81803.074.07017.400033
Merc 450SL17.38275.81803.073.73017.600033
Merc 280C17.86167.61233.923.44018.901044
Valiant18.16225.01052.763.46020.221031
Hornet Sportabout18.78360.01753.153.44017.020032
Merc 28019.26167.61233.923.44018.301044
Pontiac Firebird19.28400.01753.083.84517.050032
Ferrari Dino19.76145.01753.622.77015.500156
Mazda RX421.06160.01103.902.62016.460144
Mazda RX4 Wag21.06160.01103.902.87517.020144
Hornet 4 Drive21.46258.01103.083.21519.441031
Volvo 142E21.44121.01094.112.78018.601142
Toyota Corona21.54120.1973.702.46520.011031
Merc 23022.84140.8953.923.15022.901042
Datsun 71022.84108.0933.852.32018.611141
Merc 240D24.44146.7623.693.19020.001042
Porsche 914-226.04120.3914.432.14016.700152
Fiat X1-927.3479.0664.081.93518.901141
Lotus Europa30.4495.11133.771.51316.901152
Honda Civic30.4475.7524.931.61518.521142
Fiat 12832.4478.7664.082.20019.471141
Toyota Corolla33.9471.1654.221.83519.901141
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt \\\n", " \n", "Lincoln Continental 10.4 8 460.0 215 3.00 5.424 \n", "Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 \n", "Camaro Z28 13.3 8 350.0 245 3.73 3.840 \n", "Duster 360 14.3 8 360.0 245 3.21 3.570 \n", "Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 \n", "Maserati Bora 15.0 8 301.0 335 3.54 3.570 \n", "Merc 450SLC 15.2 8 275.8 180 3.07 3.780 \n", "AMC Javelin 15.2 8 304.0 150 3.15 3.435 \n", "Dodge Challenger 15.5 8 318.0 150 2.76 3.520 \n", "Ford Pantera L 15.8 8 351.0 264 4.22 3.170 \n", "Merc 450SE 16.4 8 275.8 180 3.07 4.070 \n", "Merc 450SL 17.3 8 275.8 180 3.07 3.730 \n", "Merc 280C 17.8 6 167.6 123 3.92 3.440 \n", "Valiant 18.1 6 225.0 105 2.76 3.460 \n", "Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 \n", "Merc 280 19.2 6 167.6 123 3.92 3.440 \n", "Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 \n", "Ferrari Dino 19.7 6 145.0 175 3.62 2.770 \n", "Mazda RX4 21.0 6 160.0 110 3.90 2.620 \n", "Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 \n", "Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 \n", "Volvo 142E 21.4 4 121.0 109 4.11 2.780 \n", "Toyota Corona 21.5 4 120.1 97 3.70 2.465 \n", "Merc 230 22.8 4 140.8 95 3.92 3.150 \n", "Datsun 710 22.8 4 108.0 93 3.85 2.320 \n", "Merc 240D 24.4 4 146.7 62 3.69 3.190 \n", "Porsche 914-2 26.0 4 120.3 91 4.43 2.140 \n", "Fiat X1-9 27.3 4 79.0 66 4.08 1.935 \n", "Lotus Europa 30.4 4 95.1 113 3.77 1.513 \n", "Honda Civic 30.4 4 75.7 52 4.93 1.615 \n", "Fiat 128 32.4 4 78.7 66 4.08 2.200 \n", "Toyota Corolla 33.9 4 71.1 65 4.22 1.835 \n", "\n", " qsec vs am gear carb \n", " \n", "Lincoln Continental 17.82 0 0 3 4 \n", "Cadillac Fleetwood 17.98 0 0 3 4 \n", "Camaro Z28 15.41 0 0 3 4 \n", "Duster 360 15.84 0 0 3 4 \n", "Chrysler Imperial 17.42 0 0 3 4 \n", "Maserati Bora 14.60 0 1 5 8 \n", "Merc 450SLC 18.00 0 0 3 3 \n", "AMC Javelin 17.30 0 0 3 2 \n", "Dodge Challenger 16.87 0 0 3 2 \n", "Ford Pantera L 14.50 0 1 5 4 \n", "Merc 450SE 17.40 0 0 3 3 \n", "Merc 450SL 17.60 0 0 3 3 \n", "Merc 280C 18.90 1 0 4 4 \n", "Valiant 20.22 1 0 3 1 \n", "Hornet Sportabout 17.02 0 0 3 2 \n", "Merc 280 18.30 1 0 4 4 \n", "Pontiac Firebird 17.05 0 0 3 2 \n", "Ferrari Dino 15.50 0 1 5 6 \n", "Mazda RX4 16.46 0 1 4 4 \n", "Mazda RX4 Wag 17.02 0 1 4 4 \n", "Hornet 4 Drive 19.44 1 0 3 1 \n", "Volvo 142E 18.60 1 1 4 2 \n", "Toyota Corona 20.01 1 0 3 1 \n", "Merc 230 22.90 1 0 4 2 \n", "Datsun 710 18.61 1 1 4 1 \n", "Merc 240D 20.00 1 0 4 2 \n", "Porsche 914-2 16.70 0 1 5 2 \n", "Fiat X1-9 18.90 1 1 4 1 \n", "Lotus Europa 16.90 1 1 5 2 \n", "Honda Civic 18.52 1 1 4 2 \n", "Fiat 128 19.47 1 1 4 1 \n", "Toyota Corolla 19.90 1 1 4 1 " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# use subscription for f-expression\n", "def tidy_eval_arrange(_data, var):\n", " return _data >> arrange(f[var])\n", " \n", "tidy_eval_arrange(mtcars, 'mpg')" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:29.025786Z", "iopub.status.busy": "2021-07-16T22:27:29.025219Z", "iopub.status.idle": "2021-07-16T22:27:29.034157Z", "shell.execute_reply": "2021-07-16T22:27:29.035035Z" } }, "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", "
Sepal_LengthSepal_WidthPetal_LengthPetal_WidthSpecies
<float64><float64><float64><float64><object>
134.33.01.10.1setosa
84.42.91.40.2setosa
384.43.01.30.2setosa
424.43.21.30.2setosa
..................
414.52.31.30.3setosa
1187.72.66.92.3virginica
1227.72.86.72.0virginica
1357.73.06.12.3virginica
1177.73.86.72.2virginica
1317.93.86.42.0virginica
\n", "

150 rows × 5 columns

\n", "
\n" ], "text/plain": [ " Sepal_Length Sepal_Width Petal_Length Petal_Width Species\n", " \n", "13 4.3 3.0 1.1 0.1 setosa\n", "8 4.4 2.9 1.4 0.2 setosa\n", "38 4.4 3.0 1.3 0.2 setosa\n", "42 4.4 3.2 1.3 0.2 setosa\n", ".. ... ... ... ... ...\n", "41 4.5 2.3 1.3 0.3 setosa\n", "118 7.7 2.6 6.9 2.3 virginica\n", "122 7.7 2.8 6.7 2.0 virginica\n", "135 7.7 3.0 6.1 2.3 virginica\n", "117 7.7 3.8 6.7 2.2 virginica\n", "131 7.9 3.8 6.4 2.0 virginica\n", "\n", "[150 rows x 5 columns]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> arrange(across(starts_with(\"Sepal\")))" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:29.068181Z", "iopub.status.busy": "2021-07-16T22:27:29.067601Z", "iopub.status.idle": "2021-07-16T22:27:29.094667Z", "shell.execute_reply": "2021-07-16T22:27:29.095672Z" } }, "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", "
Sepal_LengthSepal_WidthPetal_LengthPetal_WidthSpecies
<float64><float64><float64><float64><object>
1317.93.86.42.0virginica
1177.73.86.72.2virginica
1357.73.06.12.3virginica
1227.72.86.72.0virginica
..................
1187.72.66.92.3virginica
414.52.31.30.3setosa
424.43.21.30.2setosa
384.43.01.30.2setosa
84.42.91.40.2setosa
134.33.01.10.1setosa
\n", "

150 rows × 5 columns

\n", "
\n" ], "text/plain": [ " Sepal_Length Sepal_Width Petal_Length Petal_Width Species\n", " \n", "131 7.9 3.8 6.4 2.0 virginica\n", "117 7.7 3.8 6.7 2.2 virginica\n", "135 7.7 3.0 6.1 2.3 virginica\n", "122 7.7 2.8 6.7 2.0 virginica\n", ".. ... ... ... ... ...\n", "118 7.7 2.6 6.9 2.3 virginica\n", "41 4.5 2.3 1.3 0.3 setosa\n", "42 4.4 3.2 1.3 0.2 setosa\n", "38 4.4 3.0 1.3 0.2 setosa\n", "8 4.4 2.9 1.4 0.2 setosa\n", "13 4.3 3.0 1.1 0.1 setosa\n", "\n", "[150 rows x 5 columns]" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> arrange(across(starts_with(\"Sepal\"), desc))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 4 } ================================================ FILE: docs/notebooks/base-arithmetic.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ sum_
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the sum of a vector\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "  `na_rm`: Whether to remove `NA` values \n", "\n", "##### Returns:\n", "  The sum of the vector \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ prod
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the product of a vector\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "  `na_rm`: Whether to remove `NA` values \n", "\n", "##### Returns:\n", "  The product of the vector \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ mean
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the mean of a vector\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "  `na_rm`: Whether to remove `NA` values \n", "\n", "##### Returns:\n", "  The mean of the vector \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ median
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the median of a vector\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "  `na_rm`: Whether to remove `NA` values \n", "\n", "##### Returns:\n", "  The median of the vector \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ min_
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the minimum of a vector\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "  `na_rm`: Whether to remove `NA` values \n", "\n", "##### Returns:\n", "  The minimum of the vector \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ max_
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the maximum of a vector\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "  `na_rm`: Whether to remove `NA` values \n", "\n", "##### Returns:\n", "  The maximum of the vector \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ var
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the variance of a vector\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "  `y`: None or a vector, matrix or data frame with \n", "    compatible dimensions to `x`. The default is equivalent to \n", "    `y = x` \n", "\n", "  `na_rm`: Whether to remove `NA` values \n", "  `ddof`: The degrees of freedom \n", "\n", "##### Returns:\n", "  The variance of the vector \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ pmin
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Returns the (regular or Parallel) maxima and minima of the input\n", "  values. \n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "  `more`: One or more values \n", "  `na_rm`: Whether to remove `NA` values \n", "\n", "##### Returns:\n", "  The minimum of the vector and the values \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ pmax
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Returns the (regular or Parallel) maxima and minima of the input\n", "  values. \n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "  `more`: One or more values \n", "  `na_rm`: Whether to remove `NA` values \n", "\n", "##### Returns:\n", "  The maximum of the vector and the values \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ round_
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Round the values of a vector\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "  `digits`: The number of digits to round to \n", "\n", "##### Returns:\n", "  The rounded values \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ sqrt
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the square root of a vector\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "\n", "##### Returns:\n", "  The square root of the vector \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ abs_
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the absolute value of a vector\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "\n", "##### Returns:\n", "  The absolute values of the vector \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ sign
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the sign of a vector\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "\n", "##### Returns:\n", "  The signs of the vector \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ trunc
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Truncate the values of a vector\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "\n", "##### Returns:\n", "  The truncated values \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ ceiling
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Round up to the nearest integer\n", "\n", "##### Args:\n", "  `x`: The value to be rounded up \n", "\n", "##### Returns:\n", "  The rounded up value \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ floor
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Round down to the nearest integer\n", "\n", "##### Args:\n", "  `x`: The value to be rounded down \n", "\n", "##### Returns:\n", "  The rounded down value \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ signif
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Round the values of a vector to a given number of significant digits\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "  `digits`: The number of significant digits to round to \n", "\n", "##### Returns:\n", "  The rounded values \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ log
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the logarithm of a vector\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "  `base`: The base of the logarithm \n", "\n", "##### Returns:\n", "  The logarithm values \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ exp
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the exponential of a vector\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "\n", "##### Returns:\n", "  The exponential values \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ log2
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the base-2 logarithm of a vector\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "\n", "##### Returns:\n", "  The logarithm values \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ log10
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the base 10 logarithm of a vector\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "\n", "##### Returns:\n", "  The logarithm values \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ log1p
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the logarithm of one plus a vector\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "\n", "##### Returns:\n", "  The logarithm values \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ cov
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute pairwise covariance between two variables\n", "\n", "##### Args:\n", "  `x`: a numeric vector, matrix or data frame. \n", "  `y`: None or a vector, matrix or data frame with \n", "    compatible dimensions to `x`. The default is equivalent to \n", "    `y = x` \n", "\n", "  `na_rm`: If `True`, remove missing values before computing \n", "    the covariance. \n", "\n", "  `ddof`: The denominator degrees of freedom. \n", "\n", "##### Returns:\n", "  The covariance matrix \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ scale
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Center and/or scale the data\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "  `center`: Whether to center the data \n", "  `scale_`: Whether to scale the data \n", "\n", "##### Returns:\n", "  The scaled data \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ col_sums
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the column sums of a matrix\n", "\n", "##### Args:\n", "  `x`: A numeric matrix \n", "  `na_rm`: Whether to remove `NA` values \n", "\n", "##### Returns:\n", "  The column sums of the matrix \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ row_sums
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the row sums of a matrix\n", "\n", "##### Args:\n", "  `x`: A numeric matrix \n", "  `na_rm`: Whether to remove `NA` values \n", "\n", "##### Returns:\n", "  The row sums of the matrix \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ col_means
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the column means of a matrix\n", "\n", "##### Args:\n", "  `x`: A numeric matrix \n", "  `na_rm`: Whether to remove `NA` values \n", "\n", "##### Returns:\n", "  The column means of the matrix \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ row_means
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the row means of a matrix\n", "\n", "##### Args:\n", "  `x`: A numeric matrix \n", "  `na_rm`: Whether to remove `NA` values \n", "\n", "##### Returns:\n", "  The row means of the matrix \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ col_sds
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the column standard deviations of a matrix\n", "\n", "##### Args:\n", "  `x`: A numeric matrix \n", "  `na_rm`: Whether to remove `NA` values \n", "\n", "##### Returns:\n", "  The column standard deviations of the matrix \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ row_sds
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the row standard deviations of a matrix\n", "\n", "##### Args:\n", "  `x`: A numeric matrix \n", "  `na_rm`: Whether to remove `NA` values \n", "\n", "##### Returns:\n", "  The row standard deviations of the matrix \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ col_medians
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the column medians of a matrix\n", "\n", "##### Args:\n", "  `x`: A numeric matrix \n", "  `na_rm`: Whether to remove `NA` values \n", "\n", "##### Returns:\n", "  The column medians of the matrix \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ row_medians
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the row medians of a matrix\n", "\n", "##### Args:\n", "  `x`: A numeric matrix \n", "  `na_rm`: Whether to remove `NA` values \n", "\n", "##### Returns:\n", "  The row medians of the matrix \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ quantile
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the quantiles of a vector\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "  `probs`: The probabilities to use \n", "\n", "##### Returns:\n", "  The quantiles of the vector \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ sd
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the standard deviation of a vector\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "  `na_rm`: Whether to remove `NA` values \n", "\n", "##### Returns:\n", "  The standard deviation of the vector \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ weighted_mean
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Compute the weighted mean of a vector\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "  `w`: The weights to use \n", "  `na_rm`: Whether to remove `NA` values \n", "\n", "##### Returns:\n", "  The weighted mean of the vector \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%run nb_helpers.py\n", "\n", "from datar.all import *\n", "\n", "debug_kwargs = {'prefix': '\\n', 'sep': f'\\n{\"-\" * 20}\\n'}\n", "nb_header(\n", " sum, prod, mean, median, min, max, var, pmin, pmax,\n", " round, sqrt, abs, sign, trunc, ceiling, floor, signif,\n", " log, exp, log2, log10, log1p, cov, scale, col_sums,\n", " row_sums, col_means, row_means, col_sds, row_sds,\n", " col_medians, row_medians, quantile, sd, weighted_mean\n", ")" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "sum([1,2,4,6])\n", "--------------------\n", "13\n", "\n", "prod([1,2,4,6])\n", "--------------------\n", "48\n", "\n", "mean([1,2,4,6])\n", "--------------------\n", "3.25\n", "\n", "median([1,2,4,6])\n", "--------------------\n", "3.0\n", "\n", "min([1,2,4,6])\n", "--------------------\n", "1\n", "\n", "max([1,2,4,6])\n", "--------------------\n", "6\n", "\n", "var([1,2,4,6])\n", "--------------------\n", "4.916666666666667\n", "\n", "pmin([1,4], [2,3])\n", "--------------------\n", "array([1, 3])\n", "\n", "pmax([1,4], [2,3])\n", "--------------------\n", "array([2, 4])\n" ] } ], "source": [ "\n", "debug(\n", " sum([1,2,4,6]),\n", " prod([1,2,4,6]),\n", " mean([1,2,4,6]),\n", " median([1,2,4,6]),\n", " min([1,2,4,6]),\n", " max([1,2,4,6]),\n", " var([1,2,4,6]),\n", " pmin([1,4], [2,3]),\n", " pmax([1,4], [2,3]),\n", " **debug_kwargs\n", ")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "round([1.4, 1.5])\n", "--------------------\n", "array([1., 2.])\n", "\n", "sqrt([1.1, 2.1])\n", "--------------------\n", "array([1.04880885, 1.44913767])\n", "\n", "abs([1, -1])\n", "--------------------\n", "array([1, 1])\n", "\n", "sign([10, -10])\n", "--------------------\n", "array([ 1, -1])\n", "\n", "trunc([1.1, 2.1])\n", "--------------------\n", "array([1., 2.])\n", "\n", "ceiling([1.1, 2.1])\n", "--------------------\n", "array([2., 3.])\n", "\n", "floor([1.1, 2.1])\n", "--------------------\n", "array([1., 2.])\n", "\n", "signif(3.14567e-10, 3)\n", "--------------------\n", "array(3.15e-10)\n" ] } ], "source": [ "debug(\n", " round([1.4, 1.5]),\n", " sqrt([1.1, 2.1]),\n", " abs([1, -1]),\n", " sign([10, -10]),\n", " trunc([1.1, 2.1]),\n", " ceiling([1.1, 2.1]),\n", " floor([1.1, 2.1]),\n", " signif(3.14567e-10, 3),\n", " **debug_kwargs\n", ")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "log(exp(2))\n", "--------------------\n", "2.0\n", "\n", "exp(2)\n", "--------------------\n", "7.38905609893065\n", "\n", "log2(4)\n", "--------------------\n", "2.0\n", "\n", "log10(100)\n", "--------------------\n", "2.0\n", "\n", "log1p(exp(1)-1)\n", "--------------------\n", "1.0\n", "\n", "cov([1, 2, 3], [3, 2, 1])\n", "--------------------\n", "-1.0\n", "\n", "scale([1, 2, 3])\n", "--------------------\n", "array([-1., 0., 1.])\n" ] } ], "source": [ "debug(\n", " log(exp(2)),\n", " exp(2),\n", " log2(4),\n", " log10(100),\n", " log1p(exp(1)-1),\n", " cov([1, 2, 3], [3, 2, 1]),\n", " scale([1, 2, 3]),\n", " **debug_kwargs\n", ")" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "df\n", "--------------------\n", " v1 v2 v3\n", " \n", "0 0.067273 0.015561 -0.633373\n", "1 -0.911285 1.526871 0.540873\n", "2 1.140124 -0.596385 1.933209\n", "3 -0.147867 -0.945199 0.994281\n", "4 -2.492679 -1.536482 -0.473660\n", "\n", "col_sums(df)\n", "--------------------\n", "v1 -2.344435\n", "v2 -1.535634\n", "v3 2.361329\n", "dtype: float64\n", "\n", "row_sums(df)\n", "--------------------\n", "0 -0.550539\n", "1 1.156458\n", "2 2.476947\n", "3 -0.098786\n", "4 -4.502821\n", "dtype: float64\n", "\n", "col_means(df)\n", "--------------------\n", "v1 -0.468887\n", "v2 -0.307127\n", "v3 0.472266\n", "dtype: float64\n", "\n", "row_means(df)\n", "--------------------\n", "0 -0.183513\n", "1 0.385486\n", "2 0.825649\n", "3 -0.032929\n", "4 -1.500940\n", "dtype: float64\n", "\n", "col_sds(df)\n", "--------------------\n", "v1 1.348229\n", "v2 1.169380\n", "v3 1.064046\n", "dtype: float64\n", "\n", "row_sds(df)\n", "--------------------\n", "0 0.390447\n", "1 1.226483\n", "2 1.293786\n", "3 0.974835\n", "4 1.009978\n", "dtype: float64\n", "\n", "col_medians(df)\n", "--------------------\n", "v1 -0.147867\n", "v2 -0.596385\n", "v3 0.540873\n", "dtype: float64\n", "\n", "row_medians(df)\n", "--------------------\n", "0 0.015561\n", "1 0.540873\n", "2 1.140124\n", "3 -0.147867\n", "4 -1.536482\n", "dtype: float64\n" ] } ], "source": [ "# column and row stats\n", "\n", "df = tribble(f.v1, f.v2, f.v3, *rnorm(15))\n", "debug(\n", " df,\n", " col_sums(df),\n", " row_sums(df),\n", " col_means(df),\n", " row_means(df),\n", " col_sds(df),\n", " row_sds(df),\n", " col_medians(df),\n", " row_medians(df),\n", " **debug_kwargs,\n", ")\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "quantile([1, 2, 3, 4, 5])\n", "--------------------\n", "array([1., 2., 3., 4., 5.])\n", "\n", "quantile([1, 2, 3, 4, 5], [0, 1])\n", "--------------------\n", "array([1, 5])\n", "\n", "sd([1, 2, 3, 4, 5])\n", "--------------------\n", "1.5811388300841898\n", "\n", "weighted_mean([1, 2, 3, 4, 5])\n", "--------------------\n", "3.0\n", "\n", "weighted_mean([1, 2, 3, 4, 5], [5, 4, 3, 2, 1])\n", "--------------------\n", "2.3333333333333335\n" ] } ], "source": [ "debug(\n", " quantile([1, 2, 3, 4, 5]),\n", " quantile([1, 2, 3, 4, 5], [0, 1]),\n", " sd([1, 2, 3, 4, 5]),\n", " weighted_mean([1, 2, 3, 4, 5]),\n", " weighted_mean([1, 2, 3, 4, 5], [5, 4, 3, 2, 1]),\n", " **debug_kwargs,\n", ")" ] } ], "metadata": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" }, "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 } ================================================ FILE: docs/notebooks/base-funs.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ cut
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Cut a numeric vector into bins\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "  `breaks`: The breaks \n", "  `labels`: The labels \n", "  `include_lowest`: Whether to include the lowest value \n", "  `right`: Whether to include the rightmost value \n", "  `dig_lab`: The number of digits for labels \n", "  `ordered_result`: Whether to return an ordered factor \n", "\n", "##### Returns:\n", "  The factor vector \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ diff
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Difference of a numeric vector\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "  `lag`: The lag to use. Could be negative. \n", "    It always calculates `x[lag:] - x[:-lag]` even when `lag` is \n", "    negative \n", "\n", "  `differences`: The order of the difference \n", "\n", "##### Returns:\n", "  An array of `x[lag:] – x[:-lag]`. \n", "  If `differences > 1`, the rule applies `differences` times on `x` \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ identity
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Identity function\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "\n", "##### Returns:\n", "  The same vector \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ expand_grid
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Expand a grid\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "  `*args`: Additional numeric vectors \n", "  `**kwargs`: Additional keyword arguments \n", "\n", "##### Returns:\n", "  The expanded grid \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ outer
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Outer product of two vectors\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "  `y`: A numeric vector \n", "  `fun`: The function to handle how the result of the elements from \n", "    the first and second vectors should be computed. \n", "    The function has to be vectorized at the second argument, and \n", "    return the same shape as y. \n", "\n", "##### Returns:\n", "  The outer product \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ make_names
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Make names for a vector\n", "\n", "##### Args:\n", "  `names`: character vector to be coerced to syntactically valid names. \n", "    This is coerced to character if necessary. \n", "\n", "  `unique`: Whether to make the names unique \n", "\n", "##### Returns:\n", "  The names \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ make_unique
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Make a vector unique\n", "\n", "##### Args:\n", "  `names`: a character vector \n", "\n", "##### Returns:\n", "  The unique vector \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ rank
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Rank a numeric vector\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "  `na_last`: Whether to put NA at the end \n", "  `ties_method`: The method to handle ties. One of \"average\", \"first\", \n", "    \"last\", \"random\", \"max\", \"min\" \n", "\n", "##### Returns:\n", "  The ranks \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%run nb_helpers.py\n", "\n", "from datar.all import *\n", "\n", "debug_kwargs = {'prefix': '\\n', 'sep': f'\\n{\"-\" * 20}\\n'}\n", "nb_header(\n", " cut, diff, identity, expand_grid, outer, \n", " make_names, make_unique, rank,\n", ")" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 13:26:45][datar][WARNING] New names:\n", "[2022-12-02 13:26:45][datar][WARNING] * '_1' -> '__0'\n", "[2022-12-02 13:26:45][datar][WARNING] * '_2' -> '__1'\n", "[2022-12-02 13:26:45][datar][WARNING] * '_3' -> '__2'\n", "[2022-12-02 13:26:45][datar][WARNING] New names:\n", "[2022-12-02 13:26:45][datar][WARNING] * '_1' -> '__0'\n", "[2022-12-02 13:26:45][datar][WARNING] * '_1' -> '__1'\n", "[2022-12-02 13:26:45][datar][WARNING] * '_1' -> '__2'\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "cut(seq(1,10), 3)\n", "--------------------\n", "[(0.99, 4.0], (0.99, 4.0], (0.99, 4.0], (0.99, 4.0], (4.0, 7.0], (4.0, 7.0], (4.0, 7.0], (7.0, 10.0], (7.0, 10.0], (7.0, 10.0]]\n", "Categories (3, interval[float64, right]): [(0.99, 4.0] < (4.0, 7.0] < (7.0, 10.0]]\n", "\n", "diff([1, 2, 3])\n", "--------------------\n", "array([1, 1])\n", "\n", "identity(1.23)\n", "--------------------\n", "1.23\n", "\n", "expand_grid([1,2], [3,4])\n", "--------------------\n", " _VAR_0 _VAR_1\n", " \n", "0 1 3\n", "1 1 4\n", "2 2 3\n", "3 2 4\n", "\n", "outer([1,2], [3,4])\n", "--------------------\n", " 0 1\n", " \n", "0 3 4\n", "1 6 8\n", "\n", "make_names([1, 2, 3])\n", "--------------------\n", "['__0', '__1', '__2']\n", "\n", "make_unique([1, 1, 1])\n", "--------------------\n", "['__0', '__1', '__2']\n", "\n", "rank([3, 4, 1, -1])\n", "--------------------\n", "array([3., 4., 2., 1.])\n" ] } ], "source": [ "debug(\n", " cut(seq(1,10), 3), \n", " diff([1, 2, 3]),\n", " identity(1.23),\n", " expand_grid([1,2], [3,4]),\n", " outer([1,2], [3,4]),\n", " make_names([1, 2, 3]),\n", " make_unique([1, 1, 1]),\n", " rank([3, 4, 1, -1]),\n", " **debug_kwargs\n", ")" ] } ], "metadata": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" }, "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 } ================================================ FILE: docs/notebooks/base.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "453624fc", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:45.263092Z", "iopub.status.busy": "2021-07-16T22:27:45.262361Z", "iopub.status.idle": "2021-07-16T22:27:46.079093Z", "shell.execute_reply": "2021-07-16T22:27:46.079498Z" } }, "outputs": [], "source": [ "%run nb_helpers.py\n", "import numpy\n", "from datar import f\n", "from datar.base import *\n", "from datar.tibble import tibble\n", "\n", "debug_kwargs = {'prefix': '\\n', 'sep': f'\\n{\"-\" * 20}\\n'}" ] }, { "cell_type": "code", "execution_count": 2, "id": "5d888318", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:46.084436Z", "iopub.status.busy": "2021-07-16T22:27:46.083689Z", "iopub.status.idle": "2021-07-16T22:27:46.184011Z", "shell.execute_reply": "2021-07-16T22:27:46.184453Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "pi\n", "--------------------\n", "3.141592653589793\n", "\n", "Inf\n", "--------------------\n", "inf\n", "\n", "letters\n", "--------------------\n", "array(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',\n", " 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],\n", " dtype=' \n", "row1 1 2 3\n", "\n", "dim(df)\n", "--------------------\n", "(1, 3)\n", "\n", "nrow(df)\n", "--------------------\n", "1\n", "\n", "ncol(df)\n", "--------------------\n", "3\n", "\n", "diag(1, 3)\n", "--------------------\n", " 0 1 2\n", " \n", "0 1 0 0\n", "1 0 1 0\n", "2 0 0 1\n", "\n", "diag(diag(1, 3))\n", "--------------------\n", "array([1, 1, 1])\n", "\n", "t(df)\n", "--------------------\n", " 0\n", " \n", "x 1\n", "y 2\n", "z 3\n", "\n", "intersect([1,2], [2,3])\n", "--------------------\n", "array([2])\n", "\n", "setdiff([1,2], [2,3])\n", "--------------------\n", "array([1])\n", "\n", "union([1,2], [2,3])\n", "--------------------\n", "array([1, 2, 3])\n", "\n", "setequal([1,2], [2,1])\n", "--------------------\n", "True\n", "\n", "duplicated([1,1,2,2])\n", "--------------------\n", "array([False, True, False, True])\n", "\n", "duplicated([1,1,2,2], from_last=True)\n", "--------------------\n", "array([ True, False, True, False])\n" ] } ], "source": [ "# verbs\n", "df = tibble(x=1, y=2, z=3)\n", "\n", "debug(\n", " colnames(df),\n", " colnames(df, ['a', 'b', 'c']),\n", " rownames(df),\n", " set_rownames(df, ['row1']),\n", " dim(df),\n", " nrow(df),\n", " ncol(df),\n", " diag(1, 3),\n", " diag(diag(1, 3)),\n", " t(df),\n", " intersect([1,2], [2,3]),\n", " setdiff([1,2], [2,3]),\n", " union([1,2], [2,3]),\n", " setequal([1,2], [2,1]),\n", " duplicated([1,1,2,2]),\n", " duplicated([1,1,2,2], from_last=True),\n", " **debug_kwargs\n", ")" ] }, { "cell_type": "code", "execution_count": 6, "id": "b16d91c0", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:46.935879Z", "iopub.status.busy": "2021-07-16T22:27:46.935027Z", "iopub.status.idle": "2021-07-16T22:27:47.089544Z", "shell.execute_reply": "2021-07-16T22:27:47.089118Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "bessel_i([1,2,3], 1)\n", "--------------------\n", "array([0.5651591 , 1.59063685, 3.95337022])\n", "\n", "bessel_j([1,2,3], 1)\n", "--------------------\n", "array([0.44005059, 0.57672481, 0.33905896])\n", "\n", "bessel_k([1,2,3], 1)\n", "--------------------\n", "array([0.60190723, 0.13986588, 0.04015643])\n", "\n", "bessel_y([1,2,3], 1)\n", "--------------------\n", "array([-0.78121282, -0.10703243, 0.32467442])\n" ] } ], "source": [ "# bessel\n", "debug(\n", " bessel_i([1,2,3], 1),\n", " bessel_j([1,2,3], 1),\n", " bessel_k([1,2,3], 1),\n", " bessel_y([1,2,3], 1),\n", " **debug_kwargs\n", ")" ] }, { "cell_type": "code", "execution_count": 4, "id": "31c3ce8d", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:47.103826Z", "iopub.status.busy": "2021-07-16T22:27:47.103131Z", "iopub.status.idle": "2021-07-16T22:27:47.117362Z", "shell.execute_reply": "2021-07-16T22:27:47.117944Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "as_integer([1, 2.1])\n", "--------------------\n", "array([1, 2])\n", "\n", "as_double(['1', 2, 'nan'])\n", "--------------------\n", "array([ 1., 2., nan])\n", "\n", "as_numeric(['1', 2, 'nan'])\n", "--------------------\n", "array([ 1., 2., nan])\n" ] } ], "source": [ "# casting\n", "debug(\n", " as_integer([1, 2.1]),\n", " as_double(['1', 2, 'nan']),\n", " as_numeric(['1', 2, 'nan']),\n", " **debug_kwargs\n", ")\n" ] }, { "cell_type": "code", "execution_count": 5, "id": "aa15cc6b", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:47.138109Z", "iopub.status.busy": "2021-07-16T22:27:47.137450Z", "iopub.status.idle": "2021-07-16T22:27:47.151939Z", "shell.execute_reply": "2021-07-16T22:27:47.151185Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "im(cm)\n", "--------------------\n", "2.0\n", "\n", "re(cm)\n", "--------------------\n", "1.0\n", "\n", "mod(cm)\n", "--------------------\n", "2.23606797749979\n", "\n", "conj(cm)\n", "--------------------\n", "(1-2j)\n", "\n", "is_complex(cm)\n", "--------------------\n", "True\n", "\n", "as_complex(1)\n", "--------------------\n", "(1+0j)\n" ] } ], "source": [ "# complex numbers\n", "cm = 1 + 2j\n", "debug(\n", " im(cm),\n", " re(cm),\n", " mod(cm),\n", " conj(cm),\n", " is_complex(cm),\n", " as_complex(1),\n", " **debug_kwargs\n", ")" ] }, { "cell_type": "code", "execution_count": 6, "id": "b435f3d6", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:47.164962Z", "iopub.status.busy": "2021-07-16T22:27:47.164427Z", "iopub.status.idle": "2021-07-16T22:27:47.174228Z", "shell.execute_reply": "2021-07-16T22:27:47.173668Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "cumsum(a)\n", "--------------------\n", "array([ 1, 4, 6, 10])\n", "\n", "cumprod(a)\n", "--------------------\n", "array([ 1, 3, 6, 24])\n", "\n", "cummin(a)\n", "--------------------\n", "array([1, 1, 1, 1])\n", "\n", "cummax(a)\n", "--------------------\n", "array([1, 3, 3, 4])\n" ] } ], "source": [ "# cum stats\n", "a = [1,3,2,4]\n", "\n", "debug(\n", " cumsum(a),\n", " cumprod(a),\n", " cummin(a),\n", " cummax(a),\n", " **debug_kwargs\n", ")" ] }, { "cell_type": "code", "execution_count": 9, "id": "d3067c02", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:47.188127Z", "iopub.status.busy": "2021-07-16T22:27:47.187588Z", "iopub.status.idle": "2021-07-16T22:27:47.199207Z", "shell.execute_reply": "2021-07-16T22:27:47.199626Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "as_date([\"1jan1960\", \"2jan1960\", \"31mar1960\", \"30jul1960\"], format=\"%d%b%Y\")\n", "--------------------\n", "array([datetime.date(1960, 1, 1), datetime.date(1960, 1, 2),\n", " datetime.date(1960, 3, 31), datetime.date(1960, 7, 30)],\n", " dtype=object)\n", "\n", "as_date([\"02/27/92\", \"02/27/92\", \"01/14/92\", \"02/28/92\", \"02/01/92\"], format=\"%m/%d/%y\")\n", "--------------------\n", "array([datetime.date(1992, 2, 27), datetime.date(1992, 2, 27),\n", " datetime.date(1992, 1, 14), datetime.date(1992, 2, 28),\n", " datetime.date(1992, 2, 1)], dtype=object)\n", "\n", "as_date(32768, origin=\"1900-01-01\")\n", "--------------------\n", "datetime.date(1989, 9, 19)\n" ] } ], "source": [ "# date\n", "debug(\n", " as_date([\"1jan1960\", \"2jan1960\", \"31mar1960\", \"30jul1960\"], format=\"%d%b%Y\"),\n", " as_date([\"02/27/92\", \"02/27/92\", \"01/14/92\", \"02/28/92\", \"02/01/92\"], format=\"%m/%d/%y\"),\n", " as_date(32768, origin=\"1900-01-01\"),\n", " **debug_kwargs\n", ")" ] }, { "cell_type": "code", "execution_count": 10, "id": "ffafcee8", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:47.211713Z", "iopub.status.busy": "2021-07-16T22:27:47.211124Z", "iopub.status.idle": "2021-07-16T22:27:47.220254Z", "shell.execute_reply": "2021-07-16T22:27:47.220640Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "levels(fct)\n", "--------------------\n", "array([1, 2, 3, 4])\n", "\n", "droplevels(fct)\n", "--------------------\n", "[1, 2, 3]\n", "Categories (3, int64): [1, 2, 3]\n", "\n", "is_factor(fct)\n", "--------------------\n", "True\n", "\n", "as_factor([1,2,3])\n", "--------------------\n", "[1, 2, 3]\n", "Categories (3, int64): [1, 2, 3]\n" ] } ], "source": [ "# factor\n", "fct = factor([1,2,3], levels=[1,2,3,4])\n", "debug(\n", " levels(fct),\n", " droplevels(fct),\n", " is_factor(fct),\n", " as_factor([1,2,3]),\n", " **debug_kwargs\n", ")" ] }, { "cell_type": "code", "execution_count": 11, "id": "20f4bae9", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:47.235532Z", "iopub.status.busy": "2021-07-16T22:27:47.235022Z", "iopub.status.idle": "2021-07-16T22:27:47.253216Z", "shell.execute_reply": "2021-07-16T22:27:47.252791Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "TRUE\n", "--------------------\n", "True\n", "\n", "FALSE\n", "--------------------\n", "False\n", "\n", "is_true(TRUE)\n", "--------------------\n", "True\n", "\n", "not is_true([TRUE, TRUE])\n", "--------------------\n", "True\n", "\n", "is_false(FALSE)\n", "--------------------\n", "True\n", "\n", "is_logical(TRUE)\n", "--------------------\n", "True\n", "\n", "is_logical([TRUE, FALSE])\n", "--------------------\n", "True\n", "\n", "as_logical([0, 1])\n", "--------------------\n", "array([False, True])\n" ] } ], "source": [ "# logical\n", "\n", "debug(\n", " TRUE,\n", " FALSE,\n", " is_true(TRUE),\n", " not is_true([TRUE, TRUE]),\n", " is_false(FALSE),\n", " is_logical(TRUE),\n", " is_logical([TRUE, FALSE]),\n", " as_logical([0, 1]),\n", " **debug_kwargs\n", ")" ] }, { "cell_type": "code", "execution_count": 12, "id": "0314c145", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:47.264422Z", "iopub.status.busy": "2021-07-16T22:27:47.263869Z", "iopub.status.idle": "2021-07-16T22:27:47.283925Z", "shell.execute_reply": "2021-07-16T22:27:47.284345Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "NA\n", "--------------------\n", "nan\n", "\n", "NaN\n", "--------------------\n", "nan\n", "\n", "NA is NaN\n", "--------------------\n", "True\n", "\n", "type(NA)\n", "--------------------\n", "\n", "\n", "is_na([NA, NaN, None])\n", "--------------------\n", "array([ True, True, True])\n", "\n", "any_na([1,2, NA])\n", "--------------------\n", "True\n", "\n", "numpy.array([1,2,NA])\n", "--------------------\n", "array([ 1., 2., nan])\n", "\n", "numpy.array(['a', 'b', NA])\n", "--------------------\n", "array(['a', 'b', 'nan'], dtype='\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ab
<int64><int64>
count44
\n", "\n" ], "text/plain": [ " a b\n", " \n", "count 4 4" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# table\n", "\n", "table(rep(['a', 'b'], each=4))" ] }, { "cell_type": "code", "execution_count": 21, "id": "07f292c9", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:48.381917Z", "iopub.status.busy": "2021-07-16T22:27:48.334838Z", "iopub.status.idle": "2021-07-16T22:27:48.389093Z", "shell.execute_reply": "2021-07-16T22:27:48.389462Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "is_double(numpy.array([1,2]))\n", "--------------------\n", "False\n", "\n", "is_integer(numpy.array([1,2]))\n", "--------------------\n", "True\n", "\n", "is_numeric(numpy.array([1,2]))\n", "--------------------\n", "True\n", "\n", "is_double(numpy.array([1,2], dtype=numpy.double))\n", "--------------------\n", "True\n", "\n", "is_atomic(\"abc\")\n", "--------------------\n", "True\n", "\n", "is_element(1, [1,2])\n", "--------------------\n", "array(True)\n" ] } ], "source": [ "# testing\n", "debug(\n", " is_double(numpy.array([1,2])),\n", " is_integer(numpy.array([1,2])),\n", " is_numeric(numpy.array([1,2])),\n", " is_double(numpy.array([1,2], dtype=numpy.double)),\n", " is_atomic(\"abc\"),\n", " is_element(1, [1,2]),\n", " **debug_kwargs\n", ")" ] }, { "cell_type": "code", "execution_count": 22, "id": "5238cf10", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:48.446511Z", "iopub.status.busy": "2021-07-16T22:27:48.445881Z", "iopub.status.idle": "2021-07-16T22:27:48.531680Z", "shell.execute_reply": "2021-07-16T22:27:48.532084Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "cos(.5)\n", "--------------------\n", "0.8775825618903728\n", "\n", "sin(.5)\n", "--------------------\n", "0.479425538604203\n", "\n", "tan(.5)\n", "--------------------\n", "0.5463024898437905\n", "\n", "acos(.5)\n", "--------------------\n", "1.0471975511965979\n", "\n", "asin(.5)\n", "--------------------\n", "0.5235987755982989\n", "\n", "atan2(.5, 1)\n", "--------------------\n", "0.4636476090008061\n", "\n", "cospi(.5)\n", "--------------------\n", "6.123233995736766e-17\n", "\n", "sinpi(.5)\n", "--------------------\n", "1.0\n", "\n", "tanpi(.5)\n", "--------------------\n", "1.633123935319537e+16\n", "\n", "cosh(.5)\n", "--------------------\n", "1.1276259652063807\n", "\n", "sinh(.5)\n", "--------------------\n", "0.5210953054937474\n", "\n", "tanh(.5)\n", "--------------------\n", "0.46211715726000974\n", "\n", "acosh(1)\n", "--------------------\n", "0.0\n", "\n", "asinh(.5)\n", "--------------------\n", "0.48121182505960347\n", "\n", "atanh(.5)\n", "--------------------\n", "0.5493061443340548\n" ] } ], "source": [ "# trig/hb\n", "debug(\n", " cos(.5),\n", " sin(.5),\n", " tan(.5),\n", " acos(.5),\n", " asin(.5),\n", " atan2(.5, 1),\n", " cospi(.5),\n", " sinpi(.5),\n", " tanpi(.5),\n", " cosh(.5),\n", " sinh(.5),\n", " tanh(.5),\n", " acosh(1),\n", " asinh(.5),\n", " atanh(.5),\n", " **debug_kwargs\n", ")" ] }, { "cell_type": "code", "execution_count": 23, "id": "c1e0a5ae", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:48.568013Z", "iopub.status.busy": "2021-07-16T22:27:48.567391Z", "iopub.status.idle": "2021-07-16T22:27:48.572315Z", "shell.execute_reply": "2021-07-16T22:27:48.572907Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "which([True, False, True])\n", "--------------------\n", "array([0, 2])\n", "\n", "which_max([3,2,4,1])\n", "--------------------\n", "2\n", "\n", "which_min([3,2,4,1])\n", "--------------------\n", "3\n" ] } ], "source": [ "# which\n", "\n", "debug(\n", " which([True, False, True]),\n", " which_max([3,2,4,1]),\n", " which_min([3,2,4,1]),\n", " **debug_kwargs\n", ")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/between.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "5fcd666d", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:26.208715Z", "iopub.status.busy": "2021-07-16T22:28:26.208137Z", "iopub.status.idle": "2021-07-16T22:28:27.046740Z", "shell.execute_reply": "2021-07-16T22:28:27.047111Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ between
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Check if a value is between two other values\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/between.html \n", "\n", "##### Args:\n", "  `x`: A value \n", "  `left`: The left bound \n", "  `right`: The right bound \n", "  `inclusive`: Either `both`, `neither`, `left` or `right`. \n", "    Include boundaries. Whether to set each bound as closed or open. \n", "\n", "##### Returns:\n", "  A bool value if `x` is scalar, otherwise an array of boolean values \n", "  Note that it will be always False when NA appears in x, left or right. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/between.html\n", "%run nb_helpers.py\n", "\n", "from datar.data import starwars\n", "from datar.all import *\n", "\n", "nb_header(between)" ] }, { "cell_type": "code", "execution_count": 2, "id": "6b3effe3", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:27.052648Z", "iopub.status.busy": "2021-07-16T22:28:27.051869Z", "iopub.status.idle": "2021-07-16T22:28:27.073636Z", "shell.execute_reply": "2021-07-16T22:28:27.074124Z" } }, "outputs": [ { "data": { "text/plain": [ "0 False\n", "1 False\n", "2 False\n", "3 False\n", "4 False\n", "5 False\n", "6 True\n", "7 True\n", "8 True\n", "9 False\n", "10 False\n", "11 False\n", "dtype: bool" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "between(range(1, 13), 7, 9)" ] }, { "cell_type": "code", "execution_count": 3, "id": "302aa8fc", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:27.088657Z", "iopub.status.busy": "2021-07-16T22:28:27.087235Z", "iopub.status.idle": "2021-07-16T22:28:27.093992Z", "shell.execute_reply": "2021-07-16T22:28:27.094418Z" } }, "outputs": [ { "data": { "text/plain": [ "array([ 0.83452786, 0.10189189, 0.74650094, 0.47880049, 0.55936638,\n", " -0.70022441, 0.43960076, -0.06383017, 0.28146185, -0.5502206 ,\n", " 0.21524796, 0.50479523, 0.60164882, 0.51928143, -0.01063673,\n", " 0.84926787, 0.2968923 , -0.91378905, 0.75111234, -0.00124731,\n", " 0.90624557, -0.80836519, -0.64955713, 0.06907295, 0.55666354,\n", " -0.60156603, -0.18858712, -0.34637117, 0.75442128, 0.6532232 ,\n", " -0.10773449, 0.39341492, -0.33727655, 0.16413264, -0.82122347,\n", " 0.85301267, 0.68354877, -0.39180811, 0.54156329, -0.87504542,\n", " -0.59525048, -0.94089336, -0.22030511, 0.13365225, -0.35710286,\n", " 0.48904832, -0.58548603, 0.11360724, -0.14562895, -0.04248941,\n", " -0.4088952 , 0.20738685, 0.16683007, -0.78370598, -0.57202633,\n", " -0.04414652, 0.10903364, -0.20484245, 0.03577897, -0.66212973,\n", " 0.15423302, -0.16953601, 0.9420302 , -0.91207817, 0.62976181])" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = rnorm(100)\n", "x[between(x, -1, 1)]" ] }, { "cell_type": "code", "execution_count": 4, "id": "d1b79572", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:27.118770Z", "iopub.status.busy": "2021-07-16T22:28:27.118138Z", "iopub.status.idle": "2021-07-16T22:28:27.123518Z", "shell.execute_reply": "2021-07-16T22:28:27.122366Z" } }, "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", "
nameheightmasshair_colorskin_coloreye_colorbirth_yearsexgenderhomeworldspecies
<object><float64><float64><object><object><object><float64><object><object><object><object>
4Leia Organa150.049.0brownlightbrown19.0femalefeminineAlderaanHuman
26Mon Mothma150.0NaNauburnfairblue48.0femalefeminineChandrilaHuman
37Watto137.0NaNblackblue, greyyellowNaNmalemasculineToydariaToydarian
38Sebulba112.040.0nonegrey, redorangeNaNmalemasculineMalastareDug
45Gasgano122.0NaNnonewhite, blueblackNaNmalemasculineTroikenXexto
\n", "
\n" ], "text/plain": [ " name height mass hair_color skin_color eye_color \\\n", " \n", "4 Leia Organa 150.0 49.0 brown light brown \n", "26 Mon Mothma 150.0 NaN auburn fair blue \n", "37 Watto 137.0 NaN black blue, grey yellow \n", "38 Sebulba 112.0 40.0 none grey, red orange \n", "45 Gasgano 122.0 NaN none white, blue black \n", "\n", " birth_year sex gender homeworld species \n", " \n", "4 19.0 female feminine Alderaan Human \n", "26 48.0 female feminine Chandrila Human \n", "37 NaN male masculine Toydaria Toydarian \n", "38 NaN male masculine Malastare Dug \n", "45 NaN male masculine Troiken Xexto " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> filter(between(f.height, 100, 150))" ] }, { "cell_type": "code", "execution_count": 5, "id": "1e52d002", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:27.145532Z", "iopub.status.busy": "2021-07-16T22:28:27.144908Z", "iopub.status.idle": "2021-07-16T22:28:27.148229Z", "shell.execute_reply": "2021-07-16T22:28:27.148637Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
nameheightmasshair_colorskin_coloreye_colorbirth_yearsexgenderhomeworldspecies
<object><float64><float64><object><object><object><float64><object><object><object><object>
2R2-D296.032.0NaNwhite, bluered33.0nonemasculineNabooDroid
4Leia Organa150.049.0brownlightbrown19.0femalefeminineAlderaanHuman
7R5-D497.032.0NaNwhite, redredNaNnonemasculineTatooineDroid
18Yoda66.017.0whitegreenbrown896.0malemasculineNaNYoda's species
26Mon Mothma150.0NaNauburnfairblue48.0femalefeminineChandrilaHuman
28Wicket Systri Warrick88.020.0brownbrownbrown8.0malemasculineEndorEwok
37Watto137.0NaNblackblue, greyyellowNaNmalemasculineToydariaToydarian
38Sebulba112.040.0nonegrey, redorangeNaNmalemasculineMalastareDug
44Dud Bolt94.045.0noneblue, greyyellowNaNmalemasculineVulpterVulptereen
45Gasgano122.0NaNnonewhite, blueblackNaNmalemasculineTroikenXexto
71Ratts Tyerell79.015.0nonegrey, blueunknownNaNmalemasculineAleen MinorAleena
72R4-P1796.0NaNnonesilver, redred, blueNaNnonefeminineNaNDroid
\n", "
\n" ], "text/plain": [ " name height mass hair_color skin_color \\\n", " \n", "2 R2-D2 96.0 32.0 NaN white, blue \n", "4 Leia Organa 150.0 49.0 brown light \n", "7 R5-D4 97.0 32.0 NaN white, red \n", "18 Yoda 66.0 17.0 white green \n", "26 Mon Mothma 150.0 NaN auburn fair \n", "28 Wicket Systri Warrick 88.0 20.0 brown brown \n", "37 Watto 137.0 NaN black blue, grey \n", "38 Sebulba 112.0 40.0 none grey, red \n", "44 Dud Bolt 94.0 45.0 none blue, grey \n", "45 Gasgano 122.0 NaN none white, blue \n", "71 Ratts Tyerell 79.0 15.0 none grey, blue \n", "72 R4-P17 96.0 NaN none silver, red \n", "\n", " eye_color birth_year sex gender homeworld species \n", " \n", "2 red 33.0 none masculine Naboo Droid \n", "4 brown 19.0 female feminine Alderaan Human \n", "7 red NaN none masculine Tatooine Droid \n", "18 brown 896.0 male masculine NaN Yoda's species \n", "26 blue 48.0 female feminine Chandrila Human \n", "28 brown 8.0 male masculine Endor Ewok \n", "37 yellow NaN male masculine Toydaria Toydarian \n", "38 orange NaN male masculine Malastare Dug \n", "44 yellow NaN male masculine Vulpter Vulptereen \n", "45 black NaN male masculine Troiken Xexto \n", "71 unknown NaN male masculine Aleen Minor Aleena \n", "72 red, blue NaN none feminine NaN Droid " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> filter(100 <= f.height <= 150) # not as expected" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/bind.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "bbd58535", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:47.370728Z", "iopub.status.busy": "2021-07-16T22:27:47.370065Z", "iopub.status.idle": "2021-07-16T22:27:48.337075Z", "shell.execute_reply": "2021-07-16T22:27:48.337476Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ bind_rows
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Bind rows of give dataframes\n", "\n", "Original APIs https://dplyr.tidyverse.org/reference/bind.html \n", "\n", "##### Args:\n", "  `*data`: Dataframes to combine \n", "  `_id`: The name of the id columns \n", "  `_copy`: If `False`, do not copy data unnecessarily. \n", "    Original API does not support this. This argument will be \n", "    passed by to `pandas.concat()` as `copy` argument. \n", "\n", "  `**kwargs`: A mapping of dataframe, keys will be used as _id col. \n", "\n", "##### Returns:\n", "  The combined dataframe \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ bind_cols
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Bind columns of give dataframes\n", "\n", "Note that unlike `dplyr`, mismatched dimensions are allowed and \n", "missing rows will be filled with `NA`s \n", "\n", "##### Args:\n", "  `*data`: Dataframes to bind \n", "  `_name_repair`: treatment of problematic column names: \n", "    - \"minimal\": No name repair or checks, beyond basic existence,\n", "\n", "    - \"unique\": Make sure names are unique and not empty,\n", "\n", "    - \"check_unique\": (default value), no name repair,\n", "      but check they are unique, \n", "\n", "    - \"universal\": Make the names unique and syntactic\n", "\n", "    - a function: apply custom name repair\n", "\n", "  `_copy`: If `False`, do not copy data unnecessarily. \n", "    Original API does not support this. This argument will be \n", "    passed by to `pandas.concat()` as `copy` argument. \n", "\n", "##### Returns:\n", "  The combined dataframe \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/bind.html\n", "%run nb_helpers.py\n", "\n", "from datar.data import starwars\n", "from datar.all import *\n", "\n", "nb_header(bind_rows, bind_cols, book='bind')" ] }, { "cell_type": "code", "execution_count": 2, "id": "d90cc5b5", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:48.387921Z", "iopub.status.busy": "2021-07-16T22:27:48.387279Z", "iopub.status.idle": "2021-07-16T22:27:48.396036Z", "shell.execute_reply": "2021-07-16T22:27:48.393251Z" } }, "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", "
nameheightmasshair_colorskin_coloreye_colorbirth_yearsexgenderhomeworldspecies
<object><float64><float64><object><object><object><float64><object><object><object><object>
0Luke Skywalker172.077.0blondfairblue19.0malemasculineTatooineHuman
1C-3PO167.075.0NaNgoldyellow112.0nonemasculineTatooineDroid
2R2-D296.032.0NaNwhite, bluered33.0nonemasculineNabooDroid
3Darth Vader202.0136.0nonewhiteyellow41.9malemasculineTatooineHuman
4Obi-Wan Kenobi182.077.0auburn, whitefairblue-gray57.0malemasculineStewjonHuman
5Anakin Skywalker188.084.0blondfairblue41.9malemasculineTatooineHuman
6Wilhuff Tarkin180.0NaNauburn, greyfairblue64.0malemasculineEriaduHuman
\n", "
\n" ], "text/plain": [ " name height mass hair_color skin_color \\\n", " \n", "0 Luke Skywalker 172.0 77.0 blond fair \n", "1 C-3PO 167.0 75.0 NaN gold \n", "2 R2-D2 96.0 32.0 NaN white, blue \n", "3 Darth Vader 202.0 136.0 none white \n", "4 Obi-Wan Kenobi 182.0 77.0 auburn, white fair \n", "5 Anakin Skywalker 188.0 84.0 blond fair \n", "6 Wilhuff Tarkin 180.0 NaN auburn, grey fair \n", "\n", " eye_color birth_year sex gender homeworld species \n", " \n", "0 blue 19.0 male masculine Tatooine Human \n", "1 yellow 112.0 none masculine Tatooine Droid \n", "2 red 33.0 none masculine Naboo Droid \n", "3 yellow 41.9 male masculine Tatooine Human \n", "4 blue-gray 57.0 male masculine Stewjon Human \n", "5 blue 41.9 male masculine Tatooine Human \n", "6 blue 64.0 male masculine Eriadu Human " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "one = starwars >> slice(c[:4])\n", "two = starwars >> slice(c[9:12])\n", "\n", "one >> bind_rows(two)" ] }, { "cell_type": "code", "execution_count": 3, "id": "c79c4827", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:48.432896Z", "iopub.status.busy": "2021-07-16T22:27:48.431469Z", "iopub.status.idle": "2021-07-16T22:27:48.440809Z", "shell.execute_reply": "2021-07-16T22:27:48.441223Z" } }, "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", "
nameheightmasshair_colorskin_coloreye_colorbirth_yearsexgenderhomeworldspecies
<object><float64><float64><object><object><object><float64><object><object><object><object>
0Luke Skywalker172.077.0blondfairblue19.0malemasculineTatooineHuman
1C-3PO167.075.0NaNgoldyellow112.0nonemasculineTatooineDroid
2R2-D296.032.0NaNwhite, bluered33.0nonemasculineNabooDroid
3Darth Vader202.0136.0nonewhiteyellow41.9malemasculineTatooineHuman
4Obi-Wan Kenobi182.077.0auburn, whitefairblue-gray57.0malemasculineStewjonHuman
5Anakin Skywalker188.084.0blondfairblue41.9malemasculineTatooineHuman
6Wilhuff Tarkin180.0NaNauburn, greyfairblue64.0malemasculineEriaduHuman
\n", "
\n" ], "text/plain": [ " name height mass hair_color skin_color \\\n", " \n", "0 Luke Skywalker 172.0 77.0 blond fair \n", "1 C-3PO 167.0 75.0 NaN gold \n", "2 R2-D2 96.0 32.0 NaN white, blue \n", "3 Darth Vader 202.0 136.0 none white \n", "4 Obi-Wan Kenobi 182.0 77.0 auburn, white fair \n", "5 Anakin Skywalker 188.0 84.0 blond fair \n", "6 Wilhuff Tarkin 180.0 NaN auburn, grey fair \n", "\n", " eye_color birth_year sex gender homeworld species \n", " \n", "0 blue 19.0 male masculine Tatooine Human \n", "1 yellow 112.0 none masculine Tatooine Droid \n", "2 red 33.0 none masculine Naboo Droid \n", "3 yellow 41.9 male masculine Tatooine Human \n", "4 blue-gray 57.0 male masculine Stewjon Human \n", "5 blue 41.9 male masculine Tatooine Human \n", "6 blue 64.0 male masculine Eriadu Human " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bind_rows([one, two])" ] }, { "cell_type": "code", "execution_count": 4, "id": "2521fa9b", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:48.487046Z", "iopub.status.busy": "2021-07-16T22:27:48.486088Z", "iopub.status.idle": "2021-07-16T22:27:48.496550Z", "shell.execute_reply": "2021-07-16T22:27:48.496975Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
nameheightmasshair_colorskin_coloreye_colorbirth_yearsexgenderhomeworldspecies
<object><float64><float64><object><object><object><float64><object><object><object><object>
0Luke Skywalker172.077.0blondfairblue19.0malemasculineTatooineHuman
1C-3PO167.075.0NaNgoldyellow112.0nonemasculineTatooineDroid
2R2-D296.032.0NaNwhite, bluered33.0nonemasculineNabooDroid
3Darth Vader202.0136.0nonewhiteyellow41.9malemasculineTatooineHuman
4Obi-Wan Kenobi182.077.0auburn, whitefairblue-gray57.0malemasculineStewjonHuman
5Anakin Skywalker188.084.0blondfairblue41.9malemasculineTatooineHuman
6Wilhuff Tarkin180.0NaNauburn, greyfairblue64.0malemasculineEriaduHuman
7Obi-Wan Kenobi182.077.0auburn, whitefairblue-gray57.0malemasculineStewjonHuman
8Anakin Skywalker188.084.0blondfairblue41.9malemasculineTatooineHuman
9Wilhuff Tarkin180.0NaNauburn, greyfairblue64.0malemasculineEriaduHuman
10Luke Skywalker172.077.0blondfairblue19.0malemasculineTatooineHuman
11C-3PO167.075.0NaNgoldyellow112.0nonemasculineTatooineDroid
12R2-D296.032.0NaNwhite, bluered33.0nonemasculineNabooDroid
13Darth Vader202.0136.0nonewhiteyellow41.9malemasculineTatooineHuman
\n", "
\n" ], "text/plain": [ " name height mass hair_color skin_color \\\n", " \n", "0 Luke Skywalker 172.0 77.0 blond fair \n", "1 C-3PO 167.0 75.0 NaN gold \n", "2 R2-D2 96.0 32.0 NaN white, blue \n", "3 Darth Vader 202.0 136.0 none white \n", "4 Obi-Wan Kenobi 182.0 77.0 auburn, white fair \n", "5 Anakin Skywalker 188.0 84.0 blond fair \n", "6 Wilhuff Tarkin 180.0 NaN auburn, grey fair \n", "7 Obi-Wan Kenobi 182.0 77.0 auburn, white fair \n", "8 Anakin Skywalker 188.0 84.0 blond fair \n", "9 Wilhuff Tarkin 180.0 NaN auburn, grey fair \n", "10 Luke Skywalker 172.0 77.0 blond fair \n", "11 C-3PO 167.0 75.0 NaN gold \n", "12 R2-D2 96.0 32.0 NaN white, blue \n", "13 Darth Vader 202.0 136.0 none white \n", "\n", " eye_color birth_year sex gender homeworld species \n", " \n", "0 blue 19.0 male masculine Tatooine Human \n", "1 yellow 112.0 none masculine Tatooine Droid \n", "2 red 33.0 none masculine Naboo Droid \n", "3 yellow 41.9 male masculine Tatooine Human \n", "4 blue-gray 57.0 male masculine Stewjon Human \n", "5 blue 41.9 male masculine Tatooine Human \n", "6 blue 64.0 male masculine Eriadu Human \n", "7 blue-gray 57.0 male masculine Stewjon Human \n", "8 blue 41.9 male masculine Tatooine Human \n", "9 blue 64.0 male masculine Eriadu Human \n", "10 blue 19.0 male masculine Tatooine Human \n", "11 yellow 112.0 none masculine Tatooine Droid \n", "12 red 33.0 none masculine Naboo Droid \n", "13 yellow 41.9 male masculine Tatooine Human " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bind_rows([one, two], [two, one])" ] }, { "cell_type": "code", "execution_count": 5, "id": "e4a9545e", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:48.523072Z", "iopub.status.busy": "2021-07-16T22:27:48.522454Z", "iopub.status.idle": "2021-07-16T22:27:48.725303Z", "shell.execute_reply": "2021-07-16T22:27:48.725813Z" } }, "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", "
ab
<int64><int64>
012
134
\n", "
\n" ], "text/plain": [ " a b\n", " \n", "0 1 2\n", "1 3 4" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tibble(a=1, b=2) >> bind_rows(tibble(a=3, b=4))" ] }, { "cell_type": "code", "execution_count": 6, "id": "415463c0", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:48.736260Z", "iopub.status.busy": "2021-07-16T22:27:48.735678Z", "iopub.status.idle": "2021-07-16T22:27:48.804662Z", "shell.execute_reply": "2021-07-16T22:27:48.805265Z" } }, "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", "
ab
<int64><int64>
012
135
246
378
\n", "
\n" ], "text/plain": [ " a b\n", " \n", "0 1 2\n", "1 3 5\n", "2 4 6\n", "3 7 8" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tibble(a=1, b=2) >> bind_rows(\n", " tibble(a=[3, 4], b=[5, 6]),\n", " tibble(a=7, b=8)\n", ")" ] }, { "cell_type": "code", "execution_count": 7, "id": "0c880f14", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:48.848911Z", "iopub.status.busy": "2021-07-16T22:27:48.848099Z", "iopub.status.idle": "2021-07-16T22:27:48.865280Z", "shell.execute_reply": "2021-07-16T22:27:48.865796Z" } }, "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", "
idnameheightmasshair_colorskin_coloreye_colorbirth_yearsexgenderhomeworldspecies
<int64><object><float64><float64><object><object><object><float64><object><object><object><object>
00Luke Skywalker172.077.0blondfairblue19.0malemasculineTatooineHuman
10C-3PO167.075.0NaNgoldyellow112.0nonemasculineTatooineDroid
20R2-D296.032.0NaNwhite, bluered33.0nonemasculineNabooDroid
30Darth Vader202.0136.0nonewhiteyellow41.9malemasculineTatooineHuman
41Obi-Wan Kenobi182.077.0auburn, whitefairblue-gray57.0malemasculineStewjonHuman
51Anakin Skywalker188.084.0blondfairblue41.9malemasculineTatooineHuman
61Wilhuff Tarkin180.0NaNauburn, greyfairblue64.0malemasculineEriaduHuman
\n", "
\n" ], "text/plain": [ " id name height mass hair_color skin_color \\\n", " \n", "0 0 Luke Skywalker 172.0 77.0 blond fair \n", "1 0 C-3PO 167.0 75.0 NaN gold \n", "2 0 R2-D2 96.0 32.0 NaN white, blue \n", "3 0 Darth Vader 202.0 136.0 none white \n", "4 1 Obi-Wan Kenobi 182.0 77.0 auburn, white fair \n", "5 1 Anakin Skywalker 188.0 84.0 blond fair \n", "6 1 Wilhuff Tarkin 180.0 NaN auburn, grey fair \n", "\n", " eye_color birth_year sex gender homeworld species \n", " \n", "0 blue 19.0 male masculine Tatooine Human \n", "1 yellow 112.0 none masculine Tatooine Droid \n", "2 red 33.0 none masculine Naboo Droid \n", "3 yellow 41.9 male masculine Tatooine Human \n", "4 blue-gray 57.0 male masculine Stewjon Human \n", "5 blue 41.9 male masculine Tatooine Human \n", "6 blue 64.0 male masculine Eriadu Human " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bind_rows([one, two], _id = \"id\")" ] }, { "cell_type": "code", "execution_count": 9, "id": "fd18f54b", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:49.002368Z", "iopub.status.busy": "2021-07-16T22:27:49.001748Z", "iopub.status.idle": "2021-07-16T22:27:49.009472Z", "shell.execute_reply": "2021-07-16T22:27:49.008227Z" } }, "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", "
idnameheightmasshair_colorskin_coloreye_colorbirth_yearsexgenderhomeworldspecies
<object><object><float64><float64><object><object><object><float64><object><object><object><object>
0aLuke Skywalker172.077.0blondfairblue19.0malemasculineTatooineHuman
1aC-3PO167.075.0NaNgoldyellow112.0nonemasculineTatooineDroid
2aR2-D296.032.0NaNwhite, bluered33.0nonemasculineNabooDroid
3aDarth Vader202.0136.0nonewhiteyellow41.9malemasculineTatooineHuman
4bObi-Wan Kenobi182.077.0auburn, whitefairblue-gray57.0malemasculineStewjonHuman
5bAnakin Skywalker188.084.0blondfairblue41.9malemasculineTatooineHuman
6bWilhuff Tarkin180.0NaNauburn, greyfairblue64.0malemasculineEriaduHuman
\n", "
\n" ], "text/plain": [ " id name height mass hair_color skin_color \\\n", " \n", "0 a Luke Skywalker 172.0 77.0 blond fair \n", "1 a C-3PO 167.0 75.0 NaN gold \n", "2 a R2-D2 96.0 32.0 NaN white, blue \n", "3 a Darth Vader 202.0 136.0 none white \n", "4 b Obi-Wan Kenobi 182.0 77.0 auburn, white fair \n", "5 b Anakin Skywalker 188.0 84.0 blond fair \n", "6 b Wilhuff Tarkin 180.0 NaN auburn, grey fair \n", "\n", " eye_color birth_year sex gender homeworld species \n", " \n", "0 blue 19.0 male masculine Tatooine Human \n", "1 yellow 112.0 none masculine Tatooine Droid \n", "2 red 33.0 none masculine Naboo Droid \n", "3 yellow 41.9 male masculine Tatooine Human \n", "4 blue-gray 57.0 male masculine Stewjon Human \n", "5 blue 41.9 male masculine Tatooine Human \n", "6 blue 64.0 male masculine Eriadu Human " ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# If we need a name for one\n", "bind_rows(a=one, b=two, _id = \"id\")" ] }, { "cell_type": "code", "execution_count": 10, "id": "85f9ae65", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:49.041312Z", "iopub.status.busy": "2021-07-16T22:27:49.040714Z", "iopub.status.idle": "2021-07-16T22:27:49.048263Z", "shell.execute_reply": "2021-07-16T22:27:49.048687Z" } }, "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", "
groupsnameheightmasshair_colorskin_coloreye_colorbirth_yearsexgenderhomeworldspecies
<object><object><float64><float64><object><object><object><float64><object><object><object><object>
0group 1Luke Skywalker172.077.0blondfairblue19.0malemasculineTatooineHuman
1group 1C-3PO167.075.0NaNgoldyellow112.0nonemasculineTatooineDroid
2group 1R2-D296.032.0NaNwhite, bluered33.0nonemasculineNabooDroid
3group 1Darth Vader202.0136.0nonewhiteyellow41.9malemasculineTatooineHuman
4group 2Obi-Wan Kenobi182.077.0auburn, whitefairblue-gray57.0malemasculineStewjonHuman
5group 2Anakin Skywalker188.084.0blondfairblue41.9malemasculineTatooineHuman
6group 2Wilhuff Tarkin180.0NaNauburn, greyfairblue64.0malemasculineEriaduHuman
\n", "
\n" ], "text/plain": [ " groups name height mass hair_color skin_color \\\n", " \n", "0 group 1 Luke Skywalker 172.0 77.0 blond fair \n", "1 group 1 C-3PO 167.0 75.0 NaN gold \n", "2 group 1 R2-D2 96.0 32.0 NaN white, blue \n", "3 group 1 Darth Vader 202.0 136.0 none white \n", "4 group 2 Obi-Wan Kenobi 182.0 77.0 auburn, white fair \n", "5 group 2 Anakin Skywalker 188.0 84.0 blond fair \n", "6 group 2 Wilhuff Tarkin 180.0 NaN auburn, grey fair \n", "\n", " eye_color birth_year sex gender homeworld species \n", " \n", "0 blue 19.0 male masculine Tatooine Human \n", "1 yellow 112.0 none masculine Tatooine Droid \n", "2 red 33.0 none masculine Naboo Droid \n", "3 yellow 41.9 male masculine Tatooine Human \n", "4 blue-gray 57.0 male masculine Stewjon Human \n", "5 blue 41.9 male masculine Tatooine Human \n", "6 blue 64.0 male masculine Eriadu Human " ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bind_rows(**{\"group 1\": one, \"group 2\": two}, _id = \"groups\")" ] }, { "cell_type": "code", "execution_count": 11, "id": "203c53a8", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:49.084971Z", "iopub.status.busy": "2021-07-16T22:27:49.084405Z", "iopub.status.idle": "2021-07-16T22:27:49.090833Z", "shell.execute_reply": "2021-07-16T22:27:49.091248Z" } }, "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", "
xy
<float64><float64>
00.0NaN
11.0NaN
22.0NaN
3NaN0.0
4NaN1.0
5NaN2.0
6NaN3.0
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 0.0 NaN\n", "1 1.0 NaN\n", "2 2.0 NaN\n", "3 NaN 0.0\n", "4 NaN 1.0\n", "5 NaN 2.0\n", "6 NaN 3.0" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tibble(x=range(3)) >> bind_rows(\n", " tibble(y=range(4))\n", ")" ] }, { "cell_type": "code", "execution_count": 12, "id": "0aeecbc1", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:49.131490Z", "iopub.status.busy": "2021-07-16T22:27:49.130939Z", "iopub.status.idle": "2021-07-16T22:27:49.136968Z", "shell.execute_reply": "2021-07-16T22:27:49.137351Z" } }, "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", "
xy
<int64><float64>
000.0
111.0
22NaN
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 0 0.0\n", "1 1 1.0\n", "2 2 NaN" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# NAs filled for missed rows\n", "tibble(x=range(3)) >> bind_cols(\n", " tibble(y=range(2))\n", ")" ] }, { "cell_type": "code", "execution_count": 13, "id": "655c5124", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:49.173671Z", "iopub.status.busy": "2021-07-16T22:27:49.173009Z", "iopub.status.idle": "2021-07-16T22:27:49.182534Z", "shell.execute_reply": "2021-07-16T22:27:49.182938Z" } }, "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", "
x
<int64>
00
11
22
\n", "
\n" ], "text/plain": [ " x\n", " \n", "0 0\n", "1 1\n", "2 2" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tibble(x = range(3)) >> bind_cols(tibble())" ] }, { "cell_type": "code", "execution_count": 14, "id": "f9281c6c", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:49.191452Z", "iopub.status.busy": "2021-07-16T22:27:49.190862Z", "iopub.status.idle": "2021-07-16T22:27:49.340765Z", "shell.execute_reply": "2021-07-16T22:27:49.341239Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 13:42:54][datar][WARNING] New names:\n", "[2022-12-02 13:42:54][datar][WARNING] * 'name' -> 'name__0'\n", "[2022-12-02 13:42:54][datar][WARNING] * 'height' -> 'height__1'\n", "[2022-12-02 13:42:54][datar][WARNING] * 'mass' -> 'mass__2'\n", "[2022-12-02 13:42:54][datar][WARNING] * 'hair_color' -> 'hair_color__3'\n", "[2022-12-02 13:42:54][datar][WARNING] * 'skin_color' -> 'skin_color__4'\n", "[2022-12-02 13:42:54][datar][WARNING] * 'eye_color' -> 'eye_color__5'\n", "[2022-12-02 13:42:54][datar][WARNING] * 'birth_year' -> 'birth_year__6'\n", "[2022-12-02 13:42:54][datar][WARNING] * 'sex' -> 'sex__7'\n", "[2022-12-02 13:42:54][datar][WARNING] * 'gender' -> 'gender__8'\n", "[2022-12-02 13:42:54][datar][WARNING] * 'homeworld' -> 'homeworld__9'\n", "[2022-12-02 13:42:54][datar][WARNING] * 'species' -> 'species__10'\n", "[2022-12-02 13:42:54][datar][WARNING] * 'name' -> 'name__11'\n", "[2022-12-02 13:42:54][datar][WARNING] * 'height' -> 'height__12'\n", "[2022-12-02 13:42:54][datar][WARNING] * 'mass' -> 'mass__13'\n", "[2022-12-02 13:42:54][datar][WARNING] * 'hair_color' -> 'hair_color__14'\n", "[2022-12-02 13:42:54][datar][WARNING] * 'skin_color' -> 'skin_color__15'\n", "[2022-12-02 13:42:54][datar][WARNING] * 'eye_color' -> 'eye_color__16'\n", "[2022-12-02 13:42:54][datar][WARNING] * 'birth_year' -> 'birth_year__17'\n", "[2022-12-02 13:42:54][datar][WARNING] * 'sex' -> 'sex__18'\n", "[2022-12-02 13:42:54][datar][WARNING] * 'gender' -> 'gender__19'\n", "[2022-12-02 13:42:54][datar][WARNING] * 'homeworld' -> 'homeworld__20'\n", "[2022-12-02 13:42:54][datar][WARNING] * 'species' -> 'species__21'\n" ] }, { "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
name__0height__1mass__2hair_color__3skin_color__4eye_color__5birth_year__6sex__7gender__8homeworld__9...height__12mass__13hair_color__14skin_color__15eye_color__16birth_year__17sex__18gender__19homeworld__20species__21
<object><float64><float64><object><object><object><float64><object><object><object>...<float64><float64><object><object><object><float64><object><object><object><object>
0Luke Skywalker172.077.0blondfairblue19.0malemasculineTatooine...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
1C-3PO167.075.0NaNgoldyellow112.0nonemasculineTatooine...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
2R2-D296.032.0NaNwhite, bluered33.0nonemasculineNaboo...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
3Darth Vader202.0136.0nonewhiteyellow41.9malemasculineTatooine...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
9NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN...182.077.0auburn, whitefairblue-gray57.0malemasculineStewjonHuman
10NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN...188.084.0blondfairblue41.9malemasculineTatooineHuman
11NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN...180.0NaNauburn, greyfairblue64.0malemasculineEriaduHuman
\n", "

7 rows × 22 columns

\n", "
\n" ], "text/plain": [ " name__0 height__1 mass__2 hair_color__3 skin_color__4 \\\n", " \n", "0 Luke Skywalker 172.0 77.0 blond fair \n", "1 C-3PO 167.0 75.0 NaN gold \n", "2 R2-D2 96.0 32.0 NaN white, blue \n", "3 Darth Vader 202.0 136.0 none white \n", "9 NaN NaN NaN NaN NaN \n", "10 NaN NaN NaN NaN NaN \n", "11 NaN NaN NaN NaN NaN \n", "\n", " eye_color__5 birth_year__6 sex__7 gender__8 homeworld__9 ... \\\n", " ... \n", "0 blue 19.0 male masculine Tatooine ... \n", "1 yellow 112.0 none masculine Tatooine ... \n", "2 red 33.0 none masculine Naboo ... \n", "3 yellow 41.9 male masculine Tatooine ... \n", "9 NaN NaN NaN NaN NaN ... \n", "10 NaN NaN NaN NaN NaN ... \n", "11 NaN NaN NaN NaN NaN \n", "\n", " height__12 mass__13 hair_color__14 skin_color__15 eye_color__16 \\\n", " \n", "0 NaN NaN NaN NaN NaN \n", "1 NaN NaN NaN NaN NaN \n", "2 NaN NaN NaN NaN NaN \n", "3 NaN NaN NaN NaN NaN \n", "9 182.0 77.0 auburn, white fair blue-gray \n", "10 188.0 84.0 blond fair blue \n", "11 180.0 NaN auburn, grey fair blue \n", "\n", " birth_year__17 sex__18 gender__19 homeworld__20 species__21 \n", " \n", "0 NaN NaN NaN NaN NaN \n", "1 NaN NaN NaN NaN NaN \n", "2 NaN NaN NaN NaN NaN \n", "3 NaN NaN NaN NaN NaN \n", "9 57.0 male masculine Stewjon Human \n", "10 41.9 male masculine Tatooine Human \n", "11 64.0 male masculine Eriadu Human \n", "\n", "[7 rows x 22 columns]" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "one >> bind_cols(two)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/case_when.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "registered-ghost", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:14.044369Z", "iopub.status.busy": "2021-07-16T22:27:14.043571Z", "iopub.status.idle": "2021-07-16T22:27:15.175374Z", "shell.execute_reply": "2021-07-16T22:27:15.175875Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ case_when
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Vectorise multiple `if_else()` statements.\n", "\n", "##### Args:\n", "  `cond`: A boolean vector \n", "  `value`: A vector with values to replace \n", "  `*more_cases`: A list of tuples (cond, value) \n", "\n", "##### Returns:\n", "  A vector with values replaced. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/case_when.html\n", "%run nb_helpers.py\n", "\n", "from datar.data import starwars \n", "from datar.all import *\n", "\n", "nb_header(case_when)" ] }, { "cell_type": "code", "execution_count": 2, "id": "inclusive-benjamin", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.227937Z", "iopub.status.busy": "2021-07-16T22:27:15.227306Z", "iopub.status.idle": "2021-07-16T22:27:15.536094Z", "shell.execute_reply": "2021-07-16T22:27:15.537184Z" } }, "outputs": [ { "data": { "text/plain": [ "array(['1', '2', '3', '4', 'fizz', '6', 'buzz', '8', '9', 'fizz', '11',\n", " '12', '13', 'buzz', 'fizz', '16', '17', '18', '19', 'fizz', 'buzz',\n", " '22', '23', '24', 'fizz', '26', '27', 'buzz', '29', 'fizz', '31',\n", " '32', '33', '34', 'fizz buzz', '36', '37', '38', '39', 'fizz',\n", " '41', 'buzz', '43', '44', 'fizz', '46', '47', '48', 'buzz', 'fizz'],\n", " dtype=object)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x=range(1,51))\n", "df >> mutate(y=case_when(\n", " f.x % 35 == 0, \"fizz buzz\",\n", " f.x % 5 == 0, \"fizz\",\n", " f.x % 7 == 0, \"buzz\",\n", " True, as_character(f.x)\n", ")) >> pull(f.y, to=\"array\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "affecting-supervision", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.608577Z", "iopub.status.busy": "2021-07-16T22:27:15.608002Z", "iopub.status.idle": "2021-07-16T22:27:15.623803Z", "shell.execute_reply": "2021-07-16T22:27:15.624350Z" } }, "outputs": [ { "data": { "text/plain": [ "array(['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12',\n", " '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23',\n", " '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34',\n", " '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45',\n", " '46', '47', '48', '49', '50'], dtype=object)" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> mutate(y=case_when(\n", " True, as_character(f.x),\n", " f.x % 5 == 0, \"fizz\",\n", " f.x % 7 == 0, \"buzz\",\n", " f.x % 35 == 0, \"fizz buzz\"\n", ")) >> pull(f.y, to=\"array\")" ] }, { "cell_type": "code", "execution_count": 4, "id": "contrary-infrastructure", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.660776Z", "iopub.status.busy": "2021-07-16T22:27:15.659888Z", "iopub.status.idle": "2021-07-16T22:27:15.681510Z", "shell.execute_reply": "2021-07-16T22:27:15.681883Z" } }, "outputs": [ { "data": { "text/plain": [ "array([nan, nan, nan, nan, 'fizz', nan, 'buzz', nan, nan, 'fizz', nan,\n", " nan, nan, 'buzz', 'fizz', nan, nan, nan, nan, 'fizz', 'buzz', nan,\n", " nan, nan, 'fizz', nan, nan, 'buzz', nan, 'fizz', nan, nan, nan,\n", " nan, 'fizz', nan, nan, nan, nan, 'fizz', nan, 'buzz', nan, nan,\n", " 'fizz', nan, nan, nan, 'buzz', 'fizz'], dtype=object)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> mutate(y=case_when(\n", " f.x % 5 == 0, \"fizz\",\n", " f.x % 7 == 0, \"buzz\",\n", " f.x % 35 == 0, \"fizz buzz\"\n", ")) >> pull(f.y, to=\"array\")" ] }, { "cell_type": "code", "execution_count": 5, "id": "usual-paragraph", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.724536Z", "iopub.status.busy": "2021-07-16T22:27:15.723876Z", "iopub.status.idle": "2021-07-16T22:27:15.746479Z", "shell.execute_reply": "2021-07-16T22:27:15.746895Z" } }, "outputs": [ { "data": { "text/plain": [ "array(['1.0', 'nope', 'nope', 'nope', 'fizz', '6.0', 'buzz', '8.0', '9.0',\n", " 'fizz', '11.0', '12.0', '13.0', 'buzz', 'fizz', '16.0', '17.0',\n", " '18.0', '19.0', 'fizz', 'buzz', '22.0', '23.0', '24.0', 'fizz',\n", " '26.0', '27.0', 'buzz', '29.0', 'fizz', '31.0', '32.0', '33.0',\n", " '34.0', 'fizz buzz', '36.0', '37.0', '38.0', '39.0', 'fizz',\n", " '41.0', 'buzz', '43.0', '44.0', 'fizz', '46.0', '47.0', '48.0',\n", " 'buzz', 'fizz'], dtype=object)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.iloc[[1,2,3], 0] = NA\n", "\n", "df >> mutate(y=case_when(\n", " f.x % 35 == 0, \"fizz buzz\",\n", " f.x % 5 == 0, \"fizz\",\n", " f.x % 7 == 0, \"buzz\",\n", " is_na(f.x), \"nope\",\n", " True, as_character(f.x)\n", ")) >> pull(f.y, to=\"array\")" ] }, { "cell_type": "code", "execution_count": 6, "id": "waiting-jurisdiction", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.789908Z", "iopub.status.busy": "2021-07-16T22:27:15.789318Z", "iopub.status.idle": "2021-07-16T22:27:15.804195Z", "shell.execute_reply": "2021-07-16T22:27:15.804900Z" } }, "outputs": [ { "data": { "text/plain": [ "array(['1.0', 'nan', 'nan', 'nan', 'fizz', '6.0', 'buzz', '8.0', '9.0',\n", " 'fizz', '11.0', '12.0', '13.0', 'buzz', 'fizz', '16.0', '17.0',\n", " '18.0', '19.0', 'fizz', 'buzz', '22.0', '23.0', '24.0', 'fizz',\n", " '26.0', '27.0', 'buzz', '29.0', 'fizz', '31.0', '32.0', '33.0',\n", " '34.0', nan, '36.0', '37.0', '38.0', '39.0', 'fizz', '41.0',\n", " 'buzz', '43.0', '44.0', 'fizz', '46.0', '47.0', '48.0', 'buzz',\n", " 'fizz'], dtype=object)" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> mutate(y=case_when(\n", " f.x % 35 == 0, NA,\n", " f.x % 5 == 0, \"fizz\",\n", " f.x % 7 == 0, \"buzz\",\n", " True, as_character(f.x)\n", ")) >> pull(f.y, to=\"array\")" ] }, { "cell_type": "code", "execution_count": 7, "id": "requested-ladder", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.825575Z", "iopub.status.busy": "2021-07-16T22:27:15.824959Z", "iopub.status.idle": "2021-07-16T22:27:15.853124Z", "shell.execute_reply": "2021-07-16T22:27:15.853650Z" } }, "outputs": [ { "data": { "text/plain": [ "array([nan, nan, nan, nan, 5., nan, 7., nan, nan, 5., nan, nan, nan,\n", " 7., 5., nan, nan, nan, nan, 5., 7., nan, nan, nan, 5., nan,\n", " nan, 7., nan, 5., nan, nan, nan, nan, 35., nan, nan, nan, nan,\n", " 5., nan, 7., nan, nan, 5., nan, nan, nan, 7., 5.])" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> mutate(y=case_when(\n", " f.x % 35 == 0, 35,\n", " f.x % 5 == 0, 5,\n", " f.x % 7 == 0, 7,\n", " True, NA)\n", ") >> pull(f.y, to=\"array\")" ] }, { "cell_type": "code", "execution_count": 8, "id": "varying-terminology", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.884632Z", "iopub.status.busy": "2021-07-16T22:27:15.883974Z", "iopub.status.idle": "2021-07-16T22:27:15.908989Z", "shell.execute_reply": "2021-07-16T22:27:15.909500Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "RuntimeWarning: invalid value encountered in sqrt\n" ] }, { "data": { "text/plain": [ "array([-2. , -1.5 , -1. , -0.5 , 0. ,\n", " 0.70710678, 1. , 1.22474487, 1.41421356])" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x=seq(-2, 2.1, by=.5))\n", "df >> mutate(y=case_when(\n", " f.x >= 0, sqrt(f.x),\n", " True, f.x\n", ")) >> pull(f.y, to=\"array\")" ] }, { "cell_type": "code", "execution_count": 9, "id": "intermediate-edmonton", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.965870Z", "iopub.status.busy": "2021-07-16T22:27:15.965261Z", "iopub.status.idle": "2021-07-16T22:27:16.065510Z", "shell.execute_reply": "2021-07-16T22:27:16.064592Z" } }, "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", "
nameheightmassgenderspeciestype
<object><float64><float64><object><object><object>
0Luke Skywalker172.077.0masculineHumanother
1C-3PO167.075.0masculineDroidrobot
2R2-D296.032.0masculineDroidrobot
3Darth Vader202.0136.0masculineHumanlarge
.....................
4Leia Organa150.049.0feminineHumanother
82ReyNaNNaNfeminineHumanother
83Poe DameronNaNNaNmasculineHumanother
84BB8NaNNaNmasculineDroidrobot
85Captain PhasmaNaNNaNNaNNaNother
86Padmé Amidala165.045.0feminineHumanother
\n", "

87 rows × 6 columns

\n", "
\n" ], "text/plain": [ " name height mass gender species type\n", " \n", "0 Luke Skywalker 172.0 77.0 masculine Human other\n", "1 C-3PO 167.0 75.0 masculine Droid robot\n", "2 R2-D2 96.0 32.0 masculine Droid robot\n", "3 Darth Vader 202.0 136.0 masculine Human large\n", ".. ... ... ... ... ... ...\n", "4 Leia Organa 150.0 49.0 feminine Human other\n", "82 Rey NaN NaN feminine Human other\n", "83 Poe Dameron NaN NaN masculine Human other\n", "84 BB8 NaN NaN masculine Droid robot\n", "85 Captain Phasma NaN NaN NaN NaN other\n", "86 Padmé Amidala 165.0 45.0 feminine Human other\n", "\n", "[87 rows x 6 columns]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> \\\n", " select(f[f.name:f.hair_color], f.gender, f.species) >> \\\n", " mutate(\n", " type = case_when(\n", " (f.height > 200) | (f.mass > 200), \"large\",\n", " f.species == \"Droid\" , \"robot\",\n", " True , \"other\"\n", " )\n", " )" ] }, { "cell_type": "code", "execution_count": 10, "id": "metallic-wilderness", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:16.098307Z", "iopub.status.busy": "2021-07-16T22:27:16.097560Z", "iopub.status.idle": "2021-07-16T22:27:16.126493Z", "shell.execute_reply": "2021-07-16T22:27:16.120350Z" } }, "outputs": [ { "data": { "text/plain": [ "array(['other', 'robot', 'robot', 'large', 'other', 'other', 'other',\n", " 'robot', 'other', 'other', 'other', 'other', 'large', 'other',\n", " 'other', 'large', 'other', 'other', 'other', 'other', 'other',\n", " 'robot', 'other', 'other', 'other', 'other', 'other', 'other',\n", " 'other', 'other', 'other', 'other', 'other', 'other', 'large',\n", " 'large', 'other', 'other', 'other', 'other', 'other', 'other',\n", " 'other', 'other', 'other', 'other', 'other', 'other', 'other',\n", " 'other', 'other', 'other', 'other', 'large', 'other', 'other',\n", " 'other', 'other', 'other', 'other', 'other', 'other', 'other',\n", " 'other', 'other', 'other', 'other', 'other', 'large', 'large',\n", " 'other', 'other', 'robot', 'other', 'other', 'other', 'large',\n", " 'large', 'other', 'other', 'large', 'other', 'other', 'other',\n", " 'robot', 'other', 'other'], dtype=object)" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> \\\n", " mutate(type=case_when(\n", " (f.height > 200) | (f.mass > 200), \"large\",\n", " f.species == \"Droid\", \"robot\",\n", " True, \"other\"\n", " )) >> \\\n", " pull(f.type, to=\"array\")" ] }, { "cell_type": "code", "execution_count": null, "id": "closed-student", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/chop.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:27.286090Z", "iopub.status.busy": "2021-07-16T22:27:27.285455Z", "iopub.status.idle": "2021-07-16T22:27:28.515179Z", "shell.execute_reply": "2021-07-16T22:27:28.515573Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ chop
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Makes data frame shorter by converting rows within each group\n", "into list-columns. \n", "\n", "##### Args:\n", "  `data`: A data frame \n", "  `cols`: Columns to chop \n", "\n", "##### Returns:\n", "  Data frame with selected columns chopped \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ unchop
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Makes df longer by expanding list-columns so that each element\n", "of the list-column gets its own row in the output. \n", "\n", "See https://tidyr.tidyverse.org/reference/chop.html \n", "\n", "Recycling size-1 elements might be different from `tidyr` \n", "  >>> df = tibble(x=[1, [2,3]], y=[[2,3], 1]) \n", "  >>> df >> unchop([f.x, f.y]) \n", "  >>> # tibble(x=[1,2,3], y=[2,3,1]) \n", "  >>> # instead of following in tidyr \n", "  >>> # tibble(x=[1,1,2,3], y=[2,3,1,1]) \n", "\n", "##### Args:\n", "  `data`: A data frame. \n", "  `cols`: Columns to unchop. \n", "  `keep_empty`: By default, you get one row of output for each element \n", "    of the list your unchopping/unnesting. \n", "    This means that if there's a size-0 element \n", "    (like NULL or an empty data frame), that entire row will be \n", "    dropped from the output. \n", "    If you want to preserve all rows, use `keep_empty` = `True` to \n", "    replace size-0 elements with a single row of missing values. \n", "\n", "  `dtypes`: Providing the dtypes for the output columns. \n", "    Could be a single dtype, which will be applied to all columns, or \n", "    a dictionary of dtypes with keys for the columns and values the \n", "    dtypes. \n", "    For nested data frames, we need to specify `col$a` as key. If `col` \n", "    is used as key, all columns of the nested data frames will be casted \n", "    into that dtype. \n", "\n", "##### Returns:\n", "  A data frame with selected columns unchopped. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%run nb_helpers.py\n", "from datar.all import *\n", "\n", "nb_header(chop, unchop)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:28.543116Z", "iopub.status.busy": "2021-07-16T22:27:28.542535Z", "iopub.status.idle": "2021-07-16T22:27:29.066795Z", "shell.execute_reply": "2021-07-16T22:27:29.067215Z" } }, "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", "
xdata
<int64><object>
01<DF 3x2>
12<DF 2x2>
23<DF 1x2>
\n", "
\n" ], "text/plain": [ " x data\n", " \n", "0 1 \n", "1 2 \n", "2 3 " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x = c(1, 1, 1, 2, 2, 3), y = c[1:6:1], z = c[6:1:-1])\n", "df >> nest(data = c(f.y, f.z))\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:29.120819Z", "iopub.status.busy": "2021-07-16T22:27:29.119994Z", "iopub.status.idle": "2021-07-16T22:27:29.125071Z", "shell.execute_reply": "2021-07-16T22:27:29.125427Z" } }, "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", "
xyz
<int64><object><object>
01[1, 2, 3][6, 5, 4]
12[4, 5][3, 2]
23[6][1]
\n", "
\n" ], "text/plain": [ " x y z\n", " \n", "0 1 [1, 2, 3] [6, 5, 4]\n", "1 2 [4, 5] [3, 2]\n", "2 3 [6] [1]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> chop(c(f.y, f.z))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:29.135078Z", "iopub.status.busy": "2021-07-16T22:27:29.132452Z", "iopub.status.idle": "2021-07-16T22:27:29.170637Z", "shell.execute_reply": "2021-07-16T22:27:29.171085Z" } }, "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", "
xy
<int64><object>
021.0
131.0
232.0
341.0
442.0
543.0
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 2 1.0\n", "1 3 1.0\n", "2 3 2.0\n", "3 4 1.0\n", "4 4 2.0\n", "5 4 3.0" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Unchop\n", "df = tibble(x = c[1:5], y = [[], [1], [1,2], [1,2,3]])\n", "df >> unchop(f.y)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:29.195709Z", "iopub.status.busy": "2021-07-16T22:27:29.194859Z", "iopub.status.idle": "2021-07-16T22:27:29.202582Z", "shell.execute_reply": "2021-07-16T22:27:29.203047Z" } }, "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", "
xy
<int64><int64>
021
131
232
341
442
543
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 2 1\n", "1 3 1\n", "2 3 2\n", "3 4 1\n", "4 4 2\n", "5 4 3" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> unchop(f.y, keep_empty=True, dtypes=int)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:29.210591Z", "iopub.status.busy": "2021-07-16T22:27:29.209992Z", "iopub.status.idle": "2021-07-16T22:27:29.242975Z", "shell.execute_reply": "2021-07-16T22:27:29.243396Z" } }, "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", "
xy
<int64><object>
01a
111
212
313
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 1 a\n", "1 1 1\n", "2 1 2\n", "3 1 3" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x = c[1:2], y = [\"a\", [1,2,3]])\n", "df >> unchop(f.y)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:29.251668Z", "iopub.status.busy": "2021-07-16T22:27:29.250803Z", "iopub.status.idle": "2021-07-16T22:27:29.255881Z", "shell.execute_reply": "2021-07-16T22:27:29.256244Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[ValueError] invalid literal for int() with base 10: 'a'\n" ] } ], "source": [ "with try_catch():\n", " df >> unchop(f.y, dtypes=int)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:29.265947Z", "iopub.status.busy": "2021-07-16T22:27:29.263748Z", "iopub.status.idle": "2021-07-16T22:27:29.354094Z", "shell.execute_reply": "2021-07-16T22:27:29.354709Z" } }, "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", "
xy$xy$y
<int64><float64><float64>
021.0NaN
13NaN1.0
23NaN2.0
\n", "
\n" ], "text/plain": [ " x y$x y$y\n", " \n", "0 2 1.0 NaN\n", "1 3 NaN 1.0\n", "2 3 NaN 2.0" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x = c[1:4], y = [NULL, tibble(x = 1), tibble(y = c[1:3])])\n", "df >> unchop(f.y)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:29.376449Z", "iopub.status.busy": "2021-07-16T22:27:29.375398Z", "iopub.status.idle": "2021-07-16T22:27:29.386210Z", "shell.execute_reply": "2021-07-16T22:27:29.384289Z" } }, "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", "
xy$xy$y
<int64><float64><float64>
01NaNNaN
121.0NaN
23NaN1.0
33NaN2.0
\n", "
\n" ], "text/plain": [ " x y$x y$y\n", " \n", "0 1 NaN NaN\n", "1 2 1.0 NaN\n", "2 3 NaN 1.0\n", "3 3 NaN 2.0" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> unchop(f.y, keep_empty=True)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 2 } ================================================ FILE: docs/notebooks/coalesce.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "applicable-fault", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:49.903448Z", "iopub.status.busy": "2021-07-16T22:27:49.902768Z", "iopub.status.idle": "2021-07-16T22:27:50.871433Z", "shell.execute_reply": "2021-07-16T22:27:50.871879Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ coalesce
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Replace missing values with the first non-missing value\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/coalesce.html \n", "\n", "##### Args:\n", "  `x`: A vector \n", "  `*replace`: Values to replace missing values with. \n", "\n", "##### Returns:\n", "  An array of values \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/coalesce.html\n", "%run nb_helpers.py\n", "\n", "from datar.all import *\n", "\n", "nb_header(coalesce)" ] }, { "cell_type": "code", "execution_count": 2, "id": "smoking-gilbert", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:50.894245Z", "iopub.status.busy": "2021-07-16T22:27:50.893678Z", "iopub.status.idle": "2021-07-16T22:27:51.105408Z", "shell.execute_reply": "2021-07-16T22:27:51.103096Z" } }, "outputs": [ { "data": { "text/plain": [ "0 5.0\n", "1 4.0\n", "2 3.0\n", "3 0.0\n", "4 2.0\n", "5 0.0\n", "6 1.0\n", "7 0.0\n", "Name: y, dtype: float64" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x=[5,4,3,NA,2,NA,1,NA])\n", "df >> mutate(y=coalesce(f.x, 0)) >> pull(f.y)" ] }, { "cell_type": "code", "execution_count": 3, "id": "intense-liver", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:51.132360Z", "iopub.status.busy": "2021-07-16T22:27:51.131696Z", "iopub.status.idle": "2021-07-16T22:27:51.159635Z", "shell.execute_reply": "2021-07-16T22:27:51.158647Z" } }, "outputs": [ { "data": { "text/plain": [ "0 1.0\n", "1 2.0\n", "2 3.0\n", "3 4.0\n", "4 5.0\n", "Name: m, dtype: float64" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(\n", " y=[1,2,NA,NA,5],\n", " z=[NA,NA,3,4,5]\n", ")\n", "df >> mutate(m=coalesce(f.y, f.z)) >> pull(f.m)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/complete.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:34.998675Z", "iopub.status.busy": "2021-07-16T22:27:34.998111Z", "iopub.status.idle": "2021-07-16T22:27:36.207004Z", "shell.execute_reply": "2021-07-16T22:27:36.207419Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ complete
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Turns implicit missing values into explicit missing values.\n", "\n", "##### Args:\n", "  `data`: A data frame \n", "  `*args`: columns to expand. Columns can be atomic lists. \n", "    - To find all unique combinations of x, y and z, including\n", "      those not present in the data, supply each variable as a \n", "      separate argument: `expand(df, x, y, z)`. \n", "\n", "    - To find only the combinations that occur in the data, use\n", "      `nesting`: `expand(df, nesting(x, y, z))`. \n", "\n", "    - You can combine the two forms. For example,\n", "      `expand(df, nesting(school_id, student_id), date)` would \n", "      produce a row for each present school-student combination \n", "      for all possible dates. \n", "\n", "  `fill`: A named list that for each variable supplies a single value \n", "    to use instead of NA for missing combinations. \n", "\n", "  `explict`: Should both implicit (newly created) and explicit \n", "    (pre-existing) missing values be filled by fill? By default, \n", "    this is TRUE, but if set to FALSE this will limit the fill to only \n", "    implicit missing values. \n", "\n", "##### Returns:\n", "  Data frame with missing values completed \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%run nb_helpers.py\n", "from datar.all import *\n", "\n", "nb_header(complete)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:36.225638Z", "iopub.status.busy": "2021-07-16T22:27:36.224907Z", "iopub.status.idle": "2021-07-16T22:27:36.764033Z", "shell.execute_reply": "2021-07-16T22:27:36.764473Z" } }, "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", "
groupitem_iditem_namevalue1value2
<int64><int64><object><float64><float64>
011a1.04.0
112b3.06.0
221aNaNNaN
322b2.05.0
\n", "
\n" ], "text/plain": [ " group item_id item_name value1 value2\n", " \n", "0 1 1 a 1.0 4.0\n", "1 1 2 b 3.0 6.0\n", "2 2 1 a NaN NaN\n", "3 2 2 b 2.0 5.0" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(\n", " group = c(c[1:2:1], 1),\n", " item_id = c(c[1:2:1], 2),\n", " item_name = c(\"a\", \"b\", \"b\"),\n", " value1 = c[1:3:1],\n", " value2 = c[4:6:1]\n", ")\n", "df >> complete(f.group, nesting(f.item_id, f.item_name))" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:36.825971Z", "iopub.status.busy": "2021-07-16T22:27:36.825401Z", "iopub.status.idle": "2021-07-16T22:27:36.886733Z", "shell.execute_reply": "2021-07-16T22:27:36.887338Z" } }, "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", "
groupitem_iditem_namevalue1value2
<int64><int64><object><float64><float64>
011a1.04.0
112b3.06.0
221a0.0NaN
322b2.05.0
\n", "
\n" ], "text/plain": [ " group item_id item_name value1 value2\n", " \n", "0 1 1 a 1.0 4.0\n", "1 1 2 b 3.0 6.0\n", "2 2 1 a 0.0 NaN\n", "3 2 2 b 2.0 5.0" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> complete(f.group, nesting(f.item_id, f.item_name), fill=dict(value1=0))" ] } ], "metadata": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" }, "kernelspec": { "display_name": "Python 3.7.8 64-bit ('base': conda)", "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.9.5" } }, "nbformat": 4, "nbformat_minor": 2 } ================================================ FILE: docs/notebooks/context.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "3d8dbd18", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:22.688903Z", "iopub.status.busy": "2021-07-16T22:28:22.687968Z", "iopub.status.idle": "2021-07-16T22:28:23.757532Z", "shell.execute_reply": "2021-07-16T22:28:23.758081Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ cur_group_id
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Get the current group id\n", "\n", "##### Args:\n", "  `_data`: The dataframe \n", "\n", "##### Returns:\n", "  The current group id \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ cur_group_rows
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Get the current group row indices\n", "\n", "##### Args:\n", "  `_data`: The dataframe \n", "\n", "##### Returns:\n", "  The current group rows \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ cur_data
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Get the current dataframe\n", "\n", "##### Args:\n", "  `_data`: The dataframe \n", "\n", "##### Returns:\n", "  The current dataframe \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ cur_data_all
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Get the current data for the current group including\n", "the grouping variables \n", "\n", "##### Args:\n", "  `_data`: The dataframe \n", "\n", "##### Returns:\n", "  The current dataframe \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ cur_column
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Get the current column\n", "\n", "##### Args:\n", "  `_data`: The dataframe \n", "  `_name`: The column name \n", "\n", "##### Returns:\n", "  The current column \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/context.html\n", "%run nb_helpers.py\n", "from datar.all import *\n", "\n", "nb_header(cur_group_id, cur_group_rows, cur_data, cur_data_all, cur_column, book='context')" ] }, { "cell_type": "code", "execution_count": 2, "id": "ec43ebdc", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:23.769370Z", "iopub.status.busy": "2021-07-16T22:28:23.767355Z", "iopub.status.idle": "2021-07-16T22:28:24.044934Z", "shell.execute_reply": "2021-07-16T22:28:24.045340Z" } }, "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", "
gn
<object><int64>
0a1
1b2
2c3
\n", "
\n" ], "text/plain": [ " g n\n", " \n", "0 a 1\n", "1 b 2\n", "2 c 3" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(\n", " g=['a'] + ['b'] * 2 + ['c'] * 3,\n", " x=runif(6),\n", " y=runif(6)\n", ")\n", "gf = df >> group_by(f.g)\n", "\n", "gf >> summarise(n = n())" ] }, { "cell_type": "code", "execution_count": 3, "id": "d162c09b", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:24.060058Z", "iopub.status.busy": "2021-07-16T22:28:24.059390Z", "iopub.status.idle": "2021-07-16T22:28:24.063439Z", "shell.execute_reply": "2021-07-16T22:28:24.064000Z" } }, "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", "
gxy
<object><float64><float64>
0a0.8797330.242456
1b0.7895500.165711
2b0.0738770.198040
3c0.6778260.186310
4c0.3240690.212226
5c0.5898810.990174
\n", "
\n", "

TibbleGrouped: g (n=3)" ], "text/plain": [ " g x y\n", " \n", "0 a 0.879733 0.242456\n", "1 b 0.789550 0.165711\n", "2 b 0.073877 0.198040\n", "3 c 0.677826 0.186310\n", "4 c 0.324069 0.212226\n", "5 c 0.589881 0.990174\n", "[TibbleGrouped: g (n=3)]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gf" ] }, { "cell_type": "code", "execution_count": 4, "id": "78aae172", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:24.093244Z", "iopub.status.busy": "2021-07-16T22:28:24.092669Z", "iopub.status.idle": "2021-07-16T22:28:24.251043Z", "shell.execute_reply": "2021-07-16T22:28:24.251600Z" } }, "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", "
gxyid
<object><float64><float64><int64>
0a0.8797330.2424560
1b0.7895500.1657111
2b0.0738770.1980401
3c0.6778260.1863102
4c0.3240690.2122262
5c0.5898810.9901742
\n", "
\n", "

TibbleGrouped: g (n=3)" ], "text/plain": [ " g x y id\n", " \n", "0 a 0.879733 0.242456 0\n", "1 b 0.789550 0.165711 1\n", "2 b 0.073877 0.198040 1\n", "3 c 0.677826 0.186310 2\n", "4 c 0.324069 0.212226 2\n", "5 c 0.589881 0.990174 2\n", "[TibbleGrouped: g (n=3)]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gf >> mutate(id=cur_group_id()) " ] }, { "cell_type": "code", "execution_count": 5, "id": "49c59913", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:24.293049Z", "iopub.status.busy": "2021-07-16T22:28:24.292380Z", "iopub.status.idle": "2021-07-16T22:28:24.301115Z", "shell.execute_reply": "2021-07-16T22:28:24.301811Z" } }, "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", "
grow
<object><object>
0a[0]
1b[1, 2]
2c[3, 4, 5]
\n", "
\n" ], "text/plain": [ " g row\n", " \n", "0 a [0]\n", "1 b [1, 2]\n", "2 c [3, 4, 5]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gf >> summarise(row=cur_group_rows()) " ] }, { "cell_type": "code", "execution_count": 6, "id": "cb760a8a", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:24.335103Z", "iopub.status.busy": "2021-07-16T22:28:24.334457Z", "iopub.status.idle": "2021-07-16T22:28:24.348919Z", "shell.execute_reply": "2021-07-16T22:28:24.349292Z" } }, "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", "
gdata
<object><object>
0a<DF 1x1>
1b<DF 1x1>
2c<DF 1x1>
\n", "
\n" ], "text/plain": [ " g data\n", " \n", "0 a \n", "1 b \n", "2 c " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gf_group = gf >> summarise(data=cur_group())\n", "gf_group " ] }, { "cell_type": "code", "execution_count": 7, "id": "4c25f162", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:24.367887Z", "iopub.status.busy": "2021-07-16T22:28:24.367244Z", "iopub.status.idle": "2021-07-16T22:28:24.381979Z", "shell.execute_reply": "2021-07-16T22:28:24.382350Z" } }, "outputs": [ { "data": { "text/plain": [ "0 \n", "1 \n", "2 \n", "Name: data, dtype: object" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gf_group >> pull(f.data)" ] }, { "cell_type": "code", "execution_count": 8, "id": "71996f23", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:24.447148Z", "iopub.status.busy": "2021-07-16T22:28:24.446024Z", "iopub.status.idle": "2021-07-16T22:28:24.467264Z", "shell.execute_reply": "2021-07-16T22:28:24.467729Z" } }, "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", "
gdata
<object><object>
0a<DF 1x2>
1b<DF 2x2>
2c<DF 3x2>
\n", "
\n" ], "text/plain": [ " g data\n", " \n", "0 a \n", "1 b \n", "2 c " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gf_data = gf >> summarise(data=cur_data())\n", "gf_data" ] }, { "cell_type": "code", "execution_count": 9, "id": "9b37d097", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:24.496469Z", "iopub.status.busy": "2021-07-16T22:28:24.495880Z", "iopub.status.idle": "2021-07-16T22:28:24.515602Z", "shell.execute_reply": "2021-07-16T22:28:24.516019Z" } }, "outputs": [ { "data": { "text/plain": [ "[ x y\n", " \n", " 0 0.879733 0.242456,\n", " x y\n", " \n", " 1 0.789550 0.165711\n", " 2 0.073877 0.198040,\n", " x y\n", " \n", " 3 0.677826 0.186310\n", " 4 0.324069 0.212226\n", " 5 0.589881 0.990174]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gf_data >> pull(f.data, to='list')" ] }, { "cell_type": "code", "execution_count": 10, "id": "03c07299", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:24.549672Z", "iopub.status.busy": "2021-07-16T22:28:24.548821Z", "iopub.status.idle": "2021-07-16T22:28:24.555222Z", "shell.execute_reply": "2021-07-16T22:28:24.555691Z" } }, "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", "
gdata
<object><object>
0a<DF 1x3>
1b<DF 2x3>
2c<DF 3x3>
\n", "
\n" ], "text/plain": [ " g data\n", " \n", "0 a \n", "1 b \n", "2 c " ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gf_data_all = gf >> summarise(data=cur_data_all())\n", "gf_data_all" ] }, { "cell_type": "code", "execution_count": 11, "id": "4cc41680", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:24.571425Z", "iopub.status.busy": "2021-07-16T22:28:24.570212Z", "iopub.status.idle": "2021-07-16T22:28:24.578675Z", "shell.execute_reply": "2021-07-16T22:28:24.579169Z" } }, "outputs": [ { "data": { "text/plain": [ "[ g x y\n", " \n", " 0 a 0.879733 0.242456,\n", " g x y\n", " \n", " 1 b 0.789550 0.165711\n", " 2 b 0.073877 0.198040,\n", " g x y\n", " \n", " 3 c 0.677826 0.186310\n", " 4 c 0.324069 0.212226\n", " 5 c 0.589881 0.990174]" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gf_data_all >> pull(f.data, to='list')" ] }, { "cell_type": "code", "execution_count": 12, "id": "fe4097d2", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:24.595194Z", "iopub.status.busy": "2021-07-16T22:28:24.593255Z", "iopub.status.idle": "2021-07-16T22:28:24.671560Z", "shell.execute_reply": "2021-07-16T22:28:24.672013Z" } }, "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", "
xy
<object><object>
0x 0.7739296633011361y 0.05878489331508395
1x 0.6233885082054422y 0.027460112154048803
2x 0.005457753705443728y 0.03921965587769912
3x 0.45944873370090106y 0.034711398724083777
4x 0.10502100613889181y 0.04504004423820979
5x 0.3479600358358678y 0.9804449881028017
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 x 0.7739296633011361 y 0.05878489331508395\n", "1 x 0.6233885082054422 y 0.027460112154048803\n", "2 x 0.005457753705443728 y 0.03921965587769912\n", "3 x 0.45944873370090106 y 0.034711398724083777\n", "4 x 0.10502100613889181 y 0.04504004423820979\n", "5 x 0.3479600358358678 y 0.9804449881028017" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> select(f.x, f.y) >> mutate(\n", " across(\n", " everything(), \n", " lambda x, cc: [cc + ' '] * x.shape[0] + (x**2).astype(str), cc=cur_column()\n", " )\n", ")" ] }, { "cell_type": "code", "execution_count": 13, "id": "c99b8dee", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:24.695778Z", "iopub.status.busy": "2021-07-16T22:28:24.695126Z", "iopub.status.idle": "2021-07-16T22:28:24.699137Z", "shell.execute_reply": "2021-07-16T22:28:24.699704Z" } }, "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", "
gxy
<object><object><object>
0ax 0.7739296633011361y 0.05878489331508395
1bx 0.6233885082054422y 0.027460112154048803
2bx 0.005457753705443728y 0.03921965587769912
3cx 0.45944873370090106y 0.034711398724083777
4cx 0.10502100613889181y 0.04504004423820979
5cx 0.3479600358358678y 0.9804449881028017
\n", "
\n" ], "text/plain": [ " g x y\n", " \n", "0 a x 0.7739296633011361 y 0.05878489331508395\n", "1 b x 0.6233885082054422 y 0.027460112154048803\n", "2 b x 0.005457753705443728 y 0.03921965587769912\n", "3 c x 0.45944873370090106 y 0.034711398724083777\n", "4 c x 0.10502100613889181 y 0.04504004423820979\n", "5 c x 0.3479600358358678 y 0.9804449881028017" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# or you can use x.name, since x is a Series\n", "df >> mutate(across(\n", " [f.x, f.y], \n", " lambda x: [x.name + ' '] * x.shape[0] + (x**2).astype(str)\n", "))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/count.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "floral-roberts", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:21.123723Z", "iopub.status.busy": "2021-07-16T22:27:21.123037Z", "iopub.status.idle": "2021-07-16T22:27:22.446611Z", "shell.execute_reply": "2021-07-16T22:27:22.447112Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ count
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Count the number of rows in each group\n", "\n", "Original API: \n", "https://dplyr.tidyverse.org/reference/count.html \n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `*args`: Variables, or functions of variables. \n", "    Use desc() to sort a variable in descending order. \n", "\n", "  `wt`: A variable or function of variables to weight by. \n", "  `sort`: If TRUE, the result will be sorted by the count. \n", "  `name`: The name of the count column. \n", "  `_drop`: If `False`, keep grouping variables even if they are not used. \n", "    Original API does not support this. \n", "\n", "  `**kwargs`: Name-value pairs that apply with mutate \n", "\n", "##### Returns:\n", "  A data frame with the same number of rows as the number of groups. \n", "  The output has the following properties: \n", "    All rows appear in the output, but (usually) in a different place. \n", "    Columns are not modified. \n", "    Groups are not modified. \n", "    Data frame attributes are preserved. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ tally
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Count the number of rows in each group\n", "\n", "Original API: \n", "https://dplyr.tidyverse.org/reference/count.html \n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `wt`: A variable or function of variables to weight by. \n", "  `sort`: If TRUE, the result will be sorted by the count. \n", "  `name`: The name of the count column. \n", "\n", "##### Returns:\n", "  A data frame with the same number of rows as the number of groups. \n", "  The output has the following properties: \n", "    All rows appear in the output, but (usually) in a different place. \n", "    Columns are not modified. \n", "    Groups are not modified. \n", "    Data frame attributes are preserved. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ add_count
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Add a count column to a data frame\n", "\n", "Original API: \n", "https://dplyr.tidyverse.org/reference/count.html \n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `*args`: Variables, or functions of variables. \n", "    Use desc() to sort a variable in descending order. \n", "\n", "  `wt`: A variable or function of variables to weight by. \n", "  `sort`: If TRUE, the result will be sorted by the count. \n", "  `name`: The name of the count column. \n", "  `**kwargs`: Name-value pairs that apply with mutate \n", "\n", "##### Returns:\n", "  A data frame with the same number of rows as the number of groups. \n", "  The output has the following properties: \n", "    All rows appear in the output, but (usually) in a different place. \n", "    Columns are not modified. \n", "    Groups are not modified. \n", "    Data frame attributes are preserved. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ add_tally
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Add a count column to a data frame\n", "\n", "Original API: \n", "https://dplyr.tidyverse.org/reference/count.html \n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `wt`: A variable or function of variables to weight by. \n", "  `sort`: If TRUE, the result will be sorted by the count. \n", "  `name`: The name of the count column. \n", "\n", "##### Returns:\n", "  A data frame with the same number of rows as the number of groups. \n", "  The output has the following properties: \n", "    All rows appear in the output, but (usually) in a different place. \n", "    Columns are not modified. \n", "    Groups are not modified. \n", "    Data frame attributes are preserved. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/count.html\n", "%run nb_helpers.py\n", "\n", "from datar.data import starwars\n", "from datar.all import *\n", "\n", "nb_header(count, tally, add_count, add_tally)" ] }, { "cell_type": "code", "execution_count": 2, "id": "vietnamese-scheduling", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:22.499698Z", "iopub.status.busy": "2021-07-16T22:27:22.498972Z", "iopub.status.idle": "2021-07-16T22:27:22.761006Z", "shell.execute_reply": "2021-07-16T22:27:22.758057Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
speciesn
<object><int64>
0Human35
1Droid6
2Wookiee2
3Rodian1
4Hutt1
5Yoda's species1
6Trandoshan1
7Mon Calamari1
8Ewok1
9Sullustan1
10Neimodian1
11Gungan3
12NaN4
13Toydarian1
14Dug1
15Zabrak2
16Twi'lek2
17Vulptereen1
18Xexto1
19Toong1
20Cerean1
21Nautolan1
22Tholothian1
23Iktotchi1
24Quermian1
25Kel Dor1
26Chagrian1
27Geonosian1
28Mirialan2
29Clawdite1
30Besalisk1
31Kaminoan2
32Aleena1
33Skakoan1
34Muun1
35Togruta1
36Kaleesh1
37Pau'an1
\n", "
\n" ], "text/plain": [ " species n\n", " \n", "0 Human 35\n", "1 Droid 6\n", "2 Wookiee 2\n", "3 Rodian 1\n", "4 Hutt 1\n", "5 Yoda's species 1\n", "6 Trandoshan 1\n", "7 Mon Calamari 1\n", "8 Ewok 1\n", "9 Sullustan 1\n", "10 Neimodian 1\n", "11 Gungan 3\n", "12 NaN 4\n", "13 Toydarian 1\n", "14 Dug 1\n", "15 Zabrak 2\n", "16 Twi'lek 2\n", "17 Vulptereen 1\n", "18 Xexto 1\n", "19 Toong 1\n", "20 Cerean 1\n", "21 Nautolan 1\n", "22 Tholothian 1\n", "23 Iktotchi 1\n", "24 Quermian 1\n", "25 Kel Dor 1\n", "26 Chagrian 1\n", "27 Geonosian 1\n", "28 Mirialan 2\n", "29 Clawdite 1\n", "30 Besalisk 1\n", "31 Kaminoan 2\n", "32 Aleena 1\n", "33 Skakoan 1\n", "34 Muun 1\n", "35 Togruta 1\n", "36 Kaleesh 1\n", "37 Pau'an 1" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> count(f.species)" ] }, { "cell_type": "code", "execution_count": 3, "id": "upset-capture", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:22.933200Z", "iopub.status.busy": "2021-07-16T22:27:22.932569Z", "iopub.status.idle": "2021-07-16T22:27:23.167260Z", "shell.execute_reply": "2021-07-16T22:27:23.166667Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
speciesn
<object><int64>
0Human35
1Droid6
2NaN4
3Gungan3
4Twi'lek2
5Zabrak2
6Kaminoan2
7Mirialan2
8Wookiee2
9Besalisk1
10Clawdite1
11Iktotchi1
12Skakoan1
13Muun1
14Geonosian1
15Chagrian1
16Togruta1
17Kel Dor1
18Quermian1
19Aleena1
20Tholothian1
21Xexto1
22Cerean1
23Toong1
24Kaleesh1
25Vulptereen1
26Dug1
27Toydarian1
28Neimodian1
29Sullustan1
30Ewok1
31Mon Calamari1
32Trandoshan1
33Yoda's species1
34Hutt1
35Rodian1
36Nautolan1
37Pau'an1
\n", "
\n", "

TibbleGrouped: species (n=38)" ], "text/plain": [ " species n\n", " \n", "0 Human 35\n", "1 Droid 6\n", "2 NaN 4\n", "3 Gungan 3\n", "4 Twi'lek 2\n", "5 Zabrak 2\n", "6 Kaminoan 2\n", "7 Mirialan 2\n", "8 Wookiee 2\n", "9 Besalisk 1\n", "10 Clawdite 1\n", "11 Iktotchi 1\n", "12 Skakoan 1\n", "13 Muun 1\n", "14 Geonosian 1\n", "15 Chagrian 1\n", "16 Togruta 1\n", "17 Kel Dor 1\n", "18 Quermian 1\n", "19 Aleena 1\n", "20 Tholothian 1\n", "21 Xexto 1\n", "22 Cerean 1\n", "23 Toong 1\n", "24 Kaleesh 1\n", "25 Vulptereen 1\n", "26 Dug 1\n", "27 Toydarian 1\n", "28 Neimodian 1\n", "29 Sullustan 1\n", "30 Ewok 1\n", "31 Mon Calamari 1\n", "32 Trandoshan 1\n", "33 Yoda's species 1\n", "34 Hutt 1\n", "35 Rodian 1\n", "36 Nautolan 1\n", "37 Pau'an 1\n", "[TibbleGrouped: species (n=38)]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> count(f.species, sort=True)" ] }, { "cell_type": "code", "execution_count": 4, "id": "invisible-stage", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:23.200566Z", "iopub.status.busy": "2021-07-16T22:27:23.183269Z", "iopub.status.idle": "2021-07-16T22:27:23.216997Z", "shell.execute_reply": "2021-07-16T22:27:23.217355Z" } }, "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", "
sexgendern
<object><object><int64>
0malemasculine60
1femalefeminine16
2nonemasculine5
3NaNNaN4
4hermaphroditicmasculine1
5nonefeminine1
\n", "
\n", "

TibbleGrouped: sex, gender (n=6)" ], "text/plain": [ " sex gender n\n", " \n", "0 male masculine 60\n", "1 female feminine 16\n", "2 none masculine 5\n", "3 NaN NaN 4\n", "4 hermaphroditic masculine 1\n", "5 none feminine 1\n", "[TibbleGrouped: sex, gender (n=6)]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> count(f.sex, f.gender, sort=True)" ] }, { "cell_type": "code", "execution_count": 5, "id": "sought-republican", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:23.231211Z", "iopub.status.busy": "2021-07-16T22:27:23.230584Z", "iopub.status.idle": "2021-07-16T22:27:23.272491Z", "shell.execute_reply": "2021-07-16T22:27:23.273010Z" } }, "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", "
birth_decaden
<float64><int64>
020.06
1110.01
230.04
340.06
450.08
5NaN44
660.04
7200.01
8600.01
9900.01
1080.02
1110.01
1290.03
1370.04
14100.01
\n", "
\n" ], "text/plain": [ " birth_decade n\n", " \n", "0 20.0 6\n", "1 110.0 1\n", "2 30.0 4\n", "3 40.0 6\n", "4 50.0 8\n", "5 NaN 44\n", "6 60.0 4\n", "7 200.0 1\n", "8 600.0 1\n", "9 900.0 1\n", "10 80.0 2\n", "11 10.0 1\n", "12 90.0 3\n", "13 70.0 4\n", "14 100.0 1" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> count(birth_decade=round(f.birth_year, -1))" ] }, { "cell_type": "code", "execution_count": 6, "id": "extended-advantage", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:23.293306Z", "iopub.status.busy": "2021-07-16T22:27:23.279175Z", "iopub.status.idle": "2021-07-16T22:27:23.297207Z", "shell.execute_reply": "2021-07-16T22:27:23.297633Z" } }, "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", "
gendern
<object><int64>
0male1
1female2
\n", "
\n" ], "text/plain": [ " gender n\n", " \n", "0 male 1\n", "1 female 2" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tribble(\n", " f.name, f.gender, f.runs,\n", " \"Max\", \"male\", 10,\n", " \"Sandra\", \"female\", 1,\n", " \"Susan\", \"female\", 4\n", ")\n", "# counts rows:\n", "df >> count(f.gender)" ] }, { "cell_type": "code", "execution_count": 7, "id": "posted-group", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:23.333270Z", "iopub.status.busy": "2021-07-16T22:27:23.325562Z", "iopub.status.idle": "2021-07-16T22:27:23.336782Z", "shell.execute_reply": "2021-07-16T22:27:23.337132Z" } }, "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", "
gendern
<object><int64>
0male10
1female5
\n", "
\n" ], "text/plain": [ " gender n\n", " \n", "0 male 10\n", "1 female 5" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> count(f.gender, wt=f.runs)" ] }, { "cell_type": "code", "execution_count": 8, "id": "perceived-category", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:23.347891Z", "iopub.status.busy": "2021-07-16T22:27:23.347255Z", "iopub.status.idle": "2021-07-16T22:27:23.351736Z", "shell.execute_reply": "2021-07-16T22:27:23.351285Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
n
<int64>
087
\n", "
\n" ], "text/plain": [ " n\n", " \n", "0 87" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> tally()" ] }, { "cell_type": "code", "execution_count": 9, "id": "agricultural-spider", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:23.370009Z", "iopub.status.busy": "2021-07-16T22:27:23.359697Z", "iopub.status.idle": "2021-07-16T22:27:23.428354Z", "shell.execute_reply": "2021-07-16T22:27:23.425173Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
speciesn
<object><int64>
0Human35
1Droid6
2Wookiee2
3Rodian1
4Hutt1
5Yoda's species1
6Trandoshan1
7Mon Calamari1
8Ewok1
9Sullustan1
10Neimodian1
11Gungan3
12NaN4
13Toydarian1
14Dug1
15Zabrak2
16Twi'lek2
17Vulptereen1
18Xexto1
19Toong1
20Cerean1
21Nautolan1
22Tholothian1
23Iktotchi1
24Quermian1
25Kel Dor1
26Chagrian1
27Geonosian1
28Mirialan2
29Clawdite1
30Besalisk1
31Kaminoan2
32Aleena1
33Skakoan1
34Muun1
35Togruta1
36Kaleesh1
37Pau'an1
\n", "
\n" ], "text/plain": [ " species n\n", " \n", "0 Human 35\n", "1 Droid 6\n", "2 Wookiee 2\n", "3 Rodian 1\n", "4 Hutt 1\n", "5 Yoda's species 1\n", "6 Trandoshan 1\n", "7 Mon Calamari 1\n", "8 Ewok 1\n", "9 Sullustan 1\n", "10 Neimodian 1\n", "11 Gungan 3\n", "12 NaN 4\n", "13 Toydarian 1\n", "14 Dug 1\n", "15 Zabrak 2\n", "16 Twi'lek 2\n", "17 Vulptereen 1\n", "18 Xexto 1\n", "19 Toong 1\n", "20 Cerean 1\n", "21 Nautolan 1\n", "22 Tholothian 1\n", "23 Iktotchi 1\n", "24 Quermian 1\n", "25 Kel Dor 1\n", "26 Chagrian 1\n", "27 Geonosian 1\n", "28 Mirialan 2\n", "29 Clawdite 1\n", "30 Besalisk 1\n", "31 Kaminoan 2\n", "32 Aleena 1\n", "33 Skakoan 1\n", "34 Muun 1\n", "35 Togruta 1\n", "36 Kaleesh 1\n", "37 Pau'an 1" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> group_by(f.species) >> tally() " ] }, { "cell_type": "code", "execution_count": 10, "id": "outside-removal", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:23.463340Z", "iopub.status.busy": "2021-07-16T22:27:23.462638Z", "iopub.status.idle": "2021-07-16T22:27:23.531276Z", "shell.execute_reply": "2021-07-16T22:27:23.529823Z" } }, "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", "
namegenderrunsn
<object><object><int64><int64>
0Maxmale1010
1Sandrafemale15
2Susanfemale45
\n", "
\n", "

TibbleGrouped: gender (n=2)" ], "text/plain": [ " name gender runs n\n", " \n", "0 Max male 10 10\n", "1 Sandra female 1 5\n", "2 Susan female 4 5\n", "[TibbleGrouped: gender (n=2)]" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> add_count(f.gender, wt=f.runs)" ] }, { "cell_type": "code", "execution_count": 11, "id": "neutral-utility", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:23.540843Z", "iopub.status.busy": "2021-07-16T22:27:23.539733Z", "iopub.status.idle": "2021-07-16T22:27:23.554457Z", "shell.execute_reply": "2021-07-16T22:27:23.555011Z" } }, "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", "
namegenderruns
<object><object><int64>
0Maxmale10
1Sandrafemale1
2Susanfemale4
\n", "
\n" ], "text/plain": [ " name gender runs\n", " \n", "0 Max male 10\n", "1 Sandra female 1\n", "2 Susan female 4" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": 12, "id": "amber-chamber", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:23.588810Z", "iopub.status.busy": "2021-07-16T22:27:23.588218Z", "iopub.status.idle": "2021-07-16T22:27:23.594267Z", "shell.execute_reply": "2021-07-16T22:27:23.594900Z" } }, "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", "
namegenderrunsn
<object><object><int64><int64>
0Maxmale1015
1Sandrafemale115
2Susanfemale415
\n", "
\n" ], "text/plain": [ " name gender runs n\n", " \n", "0 Max male 10 15\n", "1 Sandra female 1 15\n", "2 Susan female 4 15" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> add_tally(wt=f.runs)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/cumall.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "minute-millennium", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:06.609806Z", "iopub.status.busy": "2021-07-16T22:28:06.608996Z", "iopub.status.idle": "2021-07-16T22:28:07.700823Z", "shell.execute_reply": "2021-07-16T22:28:07.701237Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ cummean
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Cumulative mean\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/cumall.html \n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "  `na_rm`: If `True`, remove missing values before computing. \n", "\n", "##### Returns:\n", "  An array of cumulative means \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ cumsum
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Cumulative sums\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "\n", "##### Returns:\n", "  The cumulative sums \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ cumall
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Get cumulative bool. All cases after first False\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/cumall.html \n", "\n", "##### Args:\n", "  `x`: A logical vector \n", "\n", "##### Returns:\n", "  An array of cumulative conjunctions \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ cumany
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Get cumulative bool. All cases after first True\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/cumany.html \n", "\n", "##### Args:\n", "  `x`: A logical vector \n", "\n", "##### Returns:\n", "  An array of cumulative disjunctions \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ cumany
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Get cumulative bool. All cases after first True\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/cumany.html \n", "\n", "##### Args:\n", "  `x`: A logical vector \n", "\n", "##### Returns:\n", "  An array of cumulative disjunctions \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/cumall.html\n", "%run nb_helpers.py\n", "\n", "import numpy\n", "\n", "from datar.all import *\n", "\n", "nb_header(cummean, cumsum, cumall, cumany, cumany, book='cumall')" ] }, { "cell_type": "code", "execution_count": 2, "id": "separate-coating", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:07.714938Z", "iopub.status.busy": "2021-07-16T22:28:07.714168Z", "iopub.status.idle": "2021-07-16T22:28:07.723294Z", "shell.execute_reply": "2021-07-16T22:28:07.724014Z" } }, "outputs": [ { "data": { "text/plain": [ "0 1.00\n", "1 2.00\n", "2 3.00\n", "3 2.75\n", "4 2.60\n", "dtype: float64" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = [1, 3, 5, 2, 2]\n", "cummean(x)" ] }, { "cell_type": "code", "execution_count": 3, "id": "religious-voltage", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:07.737874Z", "iopub.status.busy": "2021-07-16T22:28:07.737171Z", "iopub.status.idle": "2021-07-16T22:28:07.754908Z", "shell.execute_reply": "2021-07-16T22:28:07.755360Z" } }, "outputs": [ { "data": { "text/plain": [ "array([1. , 2. , 3. , 2.75, 2.6 ])" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cumsum(x) / seq_along(x) " ] }, { "cell_type": "code", "execution_count": 4, "id": "assigned-marks", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:07.768170Z", "iopub.status.busy": "2021-07-16T22:28:07.767400Z", "iopub.status.idle": "2021-07-16T22:28:07.777813Z", "shell.execute_reply": "2021-07-16T22:28:07.778359Z" } }, "outputs": [ { "data": { "text/plain": [ "0 True\n", "1 True\n", "2 False\n", "3 False\n", "4 False\n", "dtype: bool" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cumall(numpy.array(x) < 5)" ] }, { "cell_type": "code", "execution_count": 5, "id": "composed-midwest", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:07.788717Z", "iopub.status.busy": "2021-07-16T22:28:07.788024Z", "iopub.status.idle": "2021-07-16T22:28:07.797432Z", "shell.execute_reply": "2021-07-16T22:28:07.797881Z" } }, "outputs": [ { "data": { "text/plain": [ "0 False\n", "1 True\n", "2 True\n", "3 True\n", "4 True\n", "dtype: bool" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cumany(numpy.array(x) == 3)" ] }, { "cell_type": "code", "execution_count": 6, "id": "compliant-response", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:07.815885Z", "iopub.status.busy": "2021-07-16T22:28:07.814566Z", "iopub.status.idle": "2021-07-16T22:28:07.946033Z", "shell.execute_reply": "2021-07-16T22:28:07.945310Z" } }, "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", "
datebalance
<object><int64>
32020-01-04-25
42020-01-05-50
52020-01-0630
62020-01-07120
\n", "
\n" ], "text/plain": [ " date balance\n", " \n", "3 2020-01-04 -25\n", "4 2020-01-05 -50\n", "5 2020-01-06 30\n", "6 2020-01-07 120" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(\n", " date = as_date([f\"2020-01-0{i+1}\" for i in range(7)]),\n", " balance = c(100, 50, 25, -25, -50, 30, 120)\n", ")\n", "df >> filter(cumany(f.balance < 0))" ] }, { "cell_type": "code", "execution_count": 7, "id": "flying-senator", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:07.965583Z", "iopub.status.busy": "2021-07-16T22:28:07.964851Z", "iopub.status.idle": "2021-07-16T22:28:07.974194Z", "shell.execute_reply": "2021-07-16T22:28:07.974985Z" } }, "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", "
datebalance
<object><int64>
02020-01-01100
12020-01-0250
22020-01-0325
\n", "
\n" ], "text/plain": [ " date balance\n", " \n", "0 2020-01-01 100\n", "1 2020-01-02 50\n", "2 2020-01-03 25" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> filter(cumall(~(f.balance < 0)))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/desc.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "important-empty", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:38.744602Z", "iopub.status.busy": "2021-07-16T22:27:38.743026Z", "iopub.status.idle": "2021-07-16T22:27:39.602512Z", "shell.execute_reply": "2021-07-16T22:27:39.602933Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ desc
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Transform a vector into a format that will be sorted in descending order\n", "\n", "This is useful within arrange(). \n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/desc.html \n", "\n", "##### Args:\n", "  `x`: vector to transform \n", "\n", "##### Returns:\n", "  The descending order of x \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%run nb_helpers.py\n", "from datar.base import factor, letters\n", "from datar.dplyr import desc\n", "\n", "nb_header(desc)" ] }, { "cell_type": "code", "execution_count": 2, "id": "equal-software", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:39.613373Z", "iopub.status.busy": "2021-07-16T22:27:39.612755Z", "iopub.status.idle": "2021-07-16T22:27:39.620797Z", "shell.execute_reply": "2021-07-16T22:27:39.621622Z" } }, "outputs": [ { "data": { "text/plain": [ "array([ -1, -2, -3, -4, -5, -6, -7, -8, -9, -10])" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "desc(range(1,11))" ] }, { "cell_type": "code", "execution_count": 3, "id": "delayed-lincoln", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:39.642189Z", "iopub.status.busy": "2021-07-16T22:27:39.641582Z", "iopub.status.idle": "2021-07-16T22:27:39.651348Z", "shell.execute_reply": "2021-07-16T22:27:39.651772Z" } }, "outputs": [ { "data": { "text/plain": [ "array([ -0., -1., -2., -3., -4., -5., -6., -7., -8., -9., -10.,\n", " -11., -12., -13., -14., -15., -16., -17., -18., -19., -20., -21.,\n", " -22., -23., -24., -25.])" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "desc(factor(letters))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/distinct.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "incoming-criminal", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:01.856078Z", "iopub.status.busy": "2021-07-16T22:28:01.855450Z", "iopub.status.idle": "2021-07-16T22:28:02.766193Z", "shell.execute_reply": "2021-07-16T22:28:02.766583Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ distinct
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Filter a data frame based on conditions\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/distinct.html \n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `*args`: Variables to filter by. \n", "  `keep_all`: If `True`, keep all rows that match. \n", "  `_preserve`: If `True`, keep grouping variables even if they are not used. \n", "\n", "##### Returns:\n", "  The subset dataframe \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ n_distinct
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Count the number of distinct values\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/distinct.html \n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `na_rm`: If `True`, remove missing values before counting. \n", "\n", "##### Returns:\n", "  The number of distinct values \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/distinct.html\n", "%run nb_helpers.py\n", "from datar.data import starwars\n", "from datar.all import *\n", "\n", "nb_header(distinct, n_distinct, book='distinct')" ] }, { "cell_type": "code", "execution_count": 2, "id": "graduate-bonus", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:02.778943Z", "iopub.status.busy": "2021-07-16T22:28:02.778340Z", "iopub.status.idle": "2021-07-16T22:28:02.916126Z", "shell.execute_reply": "2021-07-16T22:28:02.916559Z" } }, "outputs": [ { "data": { "text/plain": [ "100" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(\n", " x=sample(range(10), 100, replace=True),\n", " y=sample(range(10), 100, replace=True)\n", ")\n", "nrow(df)" ] }, { "cell_type": "code", "execution_count": 3, "id": "liable-measure", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:02.965042Z", "iopub.status.busy": "2021-07-16T22:28:02.964300Z", "iopub.status.idle": "2021-07-16T22:28:02.972991Z", "shell.execute_reply": "2021-07-16T22:28:02.973410Z" } }, "outputs": [ { "data": { "text/plain": [ "59" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nrow(distinct(df))" ] }, { "cell_type": "code", "execution_count": 4, "id": "weird-insight", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:03.056160Z", "iopub.status.busy": "2021-07-16T22:28:03.052663Z", "iopub.status.idle": "2021-07-16T22:28:03.068917Z", "shell.execute_reply": "2021-07-16T22:28:03.069286Z" } }, "outputs": [ { "data": { "text/plain": [ "59" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> distinct(f.x, f.y) >> nrow()" ] }, { "cell_type": "code", "execution_count": 5, "id": "terminal-label", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:03.085467Z", "iopub.status.busy": "2021-07-16T22:28:03.084916Z", "iopub.status.idle": "2021-07-16T22:28:03.095546Z", "shell.execute_reply": "2021-07-16T22:28:03.095980Z" } }, "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", "
x
<int64>
04
16
21
38
45
69
142
197
220
383
\n", "
\n" ], "text/plain": [ " x\n", " \n", "0 4\n", "1 6\n", "2 1\n", "3 8\n", "4 5\n", "6 9\n", "14 2\n", "19 7\n", "22 0\n", "38 3" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> distinct(f.x)" ] }, { "cell_type": "code", "execution_count": 6, "id": "ignored-hearts", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:03.115485Z", "iopub.status.busy": "2021-07-16T22:28:03.114717Z", "iopub.status.idle": "2021-07-16T22:28:03.202525Z", "shell.execute_reply": "2021-07-16T22:28:03.204951Z" } }, "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", "
y
<int64>
04
13
21
37
48
66
109
130
165
182
\n", "
\n" ], "text/plain": [ " y\n", " \n", "0 4\n", "1 3\n", "2 1\n", "3 7\n", "4 8\n", "6 6\n", "10 9\n", "13 0\n", "16 5\n", "18 2" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> distinct(f.y)" ] }, { "cell_type": "code", "execution_count": 7, "id": "reasonable-envelope", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:03.244549Z", "iopub.status.busy": "2021-07-16T22:28:03.243874Z", "iopub.status.idle": "2021-07-16T22:28:03.262177Z", "shell.execute_reply": "2021-07-16T22:28:03.262613Z" } }, "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", "
xy
<int64><int64>
044
163
211
387
458
696
1420
1978
2206
3830
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 4 4\n", "1 6 3\n", "2 1 1\n", "3 8 7\n", "4 5 8\n", "6 9 6\n", "14 2 0\n", "19 7 8\n", "22 0 6\n", "38 3 0" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> distinct(f.x, _keep_all=True)" ] }, { "cell_type": "code", "execution_count": 8, "id": "historical-chapter", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:03.283879Z", "iopub.status.busy": "2021-07-16T22:28:03.283009Z", "iopub.status.idle": "2021-07-16T22:28:03.296509Z", "shell.execute_reply": "2021-07-16T22:28:03.297024Z" } }, "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", "
xy
<int64><int64>
044
163
211
387
458
696
1019
1360
1645
1862
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 4 4\n", "1 6 3\n", "2 1 1\n", "3 8 7\n", "4 5 8\n", "6 9 6\n", "10 1 9\n", "13 6 0\n", "16 4 5\n", "18 6 2" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> distinct(f.y, _keep_all=True)" ] }, { "cell_type": "code", "execution_count": 9, "id": "short-output", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:03.317929Z", "iopub.status.busy": "2021-07-16T22:28:03.317326Z", "iopub.status.idle": "2021-07-16T22:28:03.325870Z", "shell.execute_reply": "2021-07-16T22:28:03.326366Z" } }, "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", "
diff
<int64>
00
13
31
85
108
136
142
184
367
899
\n", "
\n" ], "text/plain": [ " diff\n", " \n", "0 0\n", "1 3\n", "3 1\n", "8 5\n", "10 8\n", "13 6\n", "14 2\n", "18 4\n", "36 7\n", "89 9" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> distinct(diff=abs(f.x-f.y))" ] }, { "cell_type": "code", "execution_count": 10, "id": "possible-tours", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:03.394487Z", "iopub.status.busy": "2021-07-16T22:28:03.393835Z", "iopub.status.idle": "2021-07-16T22:28:03.401685Z", "shell.execute_reply": "2021-07-16T22:28:03.402119Z" } }, "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", "
hair_colorskin_coloreye_color
<object><object><object>
0blondfairblue
1NaNgoldyellow
2NaNwhite, bluered
3nonewhiteyellow
............
4brownlightbrown
79nonepalewhite
81blackdarkdark
82brownlighthazel
84nonenoneblack
85unknownunknownunknown
\n", "

67 rows × 3 columns

\n", "
\n" ], "text/plain": [ " hair_color skin_color eye_color\n", " \n", "0 blond fair blue\n", "1 NaN gold yellow\n", "2 NaN white, blue red\n", "3 none white yellow\n", ".. ... ... ...\n", "4 brown light brown\n", "79 none pale white\n", "81 black dark dark\n", "82 brown light hazel\n", "84 none none black\n", "85 unknown unknown unknown\n", "\n", "[67 rows x 3 columns]" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> distinct(across(contains(\"color\")))" ] }, { "cell_type": "code", "execution_count": 11, "id": "radio-title", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:03.467684Z", "iopub.status.busy": "2021-07-16T22:28:03.467114Z", "iopub.status.idle": "2021-07-16T22:28:03.531743Z", "shell.execute_reply": "2021-07-16T22:28:03.532145Z" } }, "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", "
gx
<int64><int64>
011
222
\n", "
\n", "

TibbleGrouped: g (n=2)" ], "text/plain": [ " g x\n", " \n", "0 1 1\n", "2 2 2\n", "[TibbleGrouped: g (n=2)]" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(\n", " g=[1, 1, 2, 2],\n", " x=[1, 1, 2, 1]\n", ") >> group_by(f.g)\n", "\n", "df >> distinct(f.x) " ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/drop_na.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "ca9d87cf", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:02.908562Z", "iopub.status.busy": "2021-07-16T22:28:02.907945Z", "iopub.status.idle": "2021-07-16T22:28:03.847521Z", "shell.execute_reply": "2021-07-16T22:28:03.848746Z" } }, "outputs": [ { "data": { "text/html": [ "

Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ drop_na
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Drop rows containing missing values\n", "\n", "See https://tidyr.tidyverse.org/reference/drop_na.html \n", "\n", "##### Args:\n", "  `data`: A data frame. \n", "  `*columns`: Columns to inspect for missing values. \n", "  `_how`: How to select the rows to drop \n", "    - all: All columns of `columns` to be `NA`s\n", "\n", "    - any: Any columns of `columns` to be `NA`s\n", "\n", "    (tidyr doesn't support this argument) \n", "\n", "##### Returns:\n", "  Dataframe with rows with NAs dropped and indexes dropped \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://tidyr.tidyverse.org/reference/drop_na.html\n", "%run nb_helpers.py\n", "\n", "from datar.all import *\n", "\n", "nb_header(drop_na)" ] }, { "cell_type": "code", "execution_count": 2, "id": "495d9468", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:03.872775Z", "iopub.status.busy": "2021-07-16T22:28:03.869619Z", "iopub.status.idle": "2021-07-16T22:28:04.092841Z", "shell.execute_reply": "2021-07-16T22:28:04.093341Z" } }, "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", "
xy
<float64><object>
01.0a
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 1.0 a" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x = c(1, 2, NA), y = c(\"a\", NA, \"b\"))\n", "df >> drop_na()" ] }, { "cell_type": "code", "execution_count": 3, "id": "f04b6d40", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:04.122198Z", "iopub.status.busy": "2021-07-16T22:28:04.121085Z", "iopub.status.idle": "2021-07-16T22:28:04.130329Z", "shell.execute_reply": "2021-07-16T22:28:04.130799Z" } }, "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", "
xy
<float64><object>
01.0a
12.0NaN
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 1.0 a\n", "1 2.0 NaN" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> drop_na(f.x)" ] }, { "cell_type": "code", "execution_count": 4, "id": "38c638ec", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:04.160640Z", "iopub.status.busy": "2021-07-16T22:28:04.160021Z", "iopub.status.idle": "2021-07-16T22:28:04.166910Z", "shell.execute_reply": "2021-07-16T22:28:04.167297Z" } }, "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", "
xy
<float64><object>
01.0a
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 1.0 a" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "vars = [\"y\"]\n", "df >> drop_na(f.x, any_of(vars))" ] }, { "cell_type": "code", "execution_count": 5, "id": "e4b2c11a", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:04.180991Z", "iopub.status.busy": "2021-07-16T22:28:04.180288Z", "iopub.status.idle": "2021-07-16T22:28:04.188341Z", "shell.execute_reply": "2021-07-16T22:28:04.188774Z" } }, "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", "
xy
<float64><object>
01.0a
12.0NaN
2NaNb
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 1.0 a\n", "1 2.0 NaN\n", "2 NaN b" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# how_='any' or how_='all'\n", "# not supported by tidyr\n", "df >> drop_na(how_='all')" ] }, { "cell_type": "code", "execution_count": 6, "id": "446314c4", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:04.203254Z", "iopub.status.busy": "2021-07-16T22:28:04.202457Z", "iopub.status.idle": "2021-07-16T22:28:04.211838Z", "shell.execute_reply": "2021-07-16T22:28:04.212261Z" } }, "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", "
xy
<float64><object>
01.0a
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 1.0 a" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> drop_na(how_='any')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/enframe.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:30.178008Z", "iopub.status.busy": "2021-07-16T22:28:30.177298Z", "iopub.status.idle": "2021-07-16T22:28:31.066519Z", "shell.execute_reply": "2021-07-16T22:28:31.066940Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ enframe
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Converts mappings or lists to one- or two-column data frames.\n", "\n", "##### Args:\n", "  `x`: a list, a dictionary or a dataframe with one or two columns \n", "  `name`: and \n", "  `value`: value Names of the columns that store the names and values. \n", "    If `None`, a one-column dataframe is returned. \n", "    `value` cannot be `None` \n", "\n", "##### Returns:\n", "  A data frame with two columns if `name` is not None (default) or \n", "  one-column otherwise. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ deframe
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Converts two-column data frames to a dictionary\n", "using the first column as name and the second column as value. \n", "If the input has only one column, a list. \n", "\n", "##### Args:\n", "  `x`: A data frame. \n", "\n", "##### Returns:\n", "  A dictionary or a list if only one column in the data frame. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://tibble.tidyverse.org/reference/enframe.html\n", "%run nb_helpers.py\n", "\n", "from datar.tibble import *\n", "from datar.base import seq\n", "\n", "nb_header(enframe, deframe, book='enframe')" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:31.085129Z", "iopub.status.busy": "2021-07-16T22:28:31.084214Z", "iopub.status.idle": "2021-07-16T22:28:31.089910Z", "shell.execute_reply": "2021-07-16T22:28:31.090440Z" } }, "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", "
namevalue
<int64><int64>
001
112
223
\n", "
\n" ], "text/plain": [ " name value\n", " \n", "0 0 1\n", "1 1 2\n", "2 2 3" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "enframe(seq(1,3))" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:31.113080Z", "iopub.status.busy": "2021-07-16T22:28:31.112505Z", "iopub.status.idle": "2021-07-16T22:28:31.120948Z", "shell.execute_reply": "2021-07-16T22:28:31.121344Z" } }, "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", "
namevalue
<object><int64>
0a5
1b7
\n", "
\n" ], "text/plain": [ " name value\n", " \n", "0 a 5\n", "1 b 7" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "enframe(dict(a=5, b=7))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:31.132693Z", "iopub.status.busy": "2021-07-16T22:28:31.131955Z", "iopub.status.idle": "2021-07-16T22:28:31.139014Z", "shell.execute_reply": "2021-07-16T22:28:31.139426Z" } }, "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", "
namevalue
<object><object>
0one1
1two[2, 3]
2three[4, 5, 6]
\n", "
\n" ], "text/plain": [ " name value\n", " \n", "0 one 1\n", "1 two [2, 3]\n", "2 three [4, 5, 6]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "enframe(dict(one=1, two=[2,3], three=[4,5,6]))" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:31.151230Z", "iopub.status.busy": "2021-07-16T22:28:31.150441Z", "iopub.status.idle": "2021-07-16T22:28:31.156108Z", "shell.execute_reply": "2021-07-16T22:28:31.156544Z" } }, "outputs": [ { "data": { "text/plain": [ "{0: 3, 1: 2, 2: 1}" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "deframe(enframe(seq(3,1)))" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:31.175628Z", "iopub.status.busy": "2021-07-16T22:28:31.172529Z", "iopub.status.idle": "2021-07-16T22:28:31.301296Z", "shell.execute_reply": "2021-07-16T22:28:31.301845Z" } }, "outputs": [ { "data": { "text/plain": [ "array([1, 2, 3])" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "deframe(tibble(a=seq(1,3)))" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:31.309147Z", "iopub.status.busy": "2021-07-16T22:28:31.307277Z", "iopub.status.idle": "2021-07-16T22:28:31.322373Z", "shell.execute_reply": "2021-07-16T22:28:31.322957Z" } }, "outputs": [ { "data": { "text/plain": [ "array([array([1, 2, 3])], dtype=object)" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "deframe(tibble(a=[seq(1,3)]))" ] } ], "metadata": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" }, "kernelspec": { "display_name": "Python 3.7.8 64-bit ('base': conda)", "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.9.5" } }, "nbformat": 4, "nbformat_minor": 2 } ================================================ FILE: docs/notebooks/expand.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "imposed-davis", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:13.577475Z", "iopub.status.busy": "2021-07-16T22:27:13.576458Z", "iopub.status.idle": "2021-07-16T22:27:14.863613Z", "shell.execute_reply": "2021-07-16T22:27:14.864080Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ expand
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Generates all combination of variables found in a dataset.\n", "\n", "##### Args:\n", "  `data`: A data frame \n", "  `*args`: and, \n", "  `**kwargs`: columns to expand. Columns can be atomic lists. \n", "    - To find all unique combinations of x, y and z, including\n", "      those not present in the data, supply each variable as a \n", "      separate argument: `expand(df, x, y, z)`. \n", "\n", "    - To find only the combinations that occur in the data, use\n", "      `nesting`: `expand(df, nesting(x, y, z))`. \n", "\n", "    - You can combine the two forms. For example,\n", "      `expand(df, nesting(school_id, student_id), date)` would \n", "      produce a row for each present school-student combination \n", "      for all possible dates. \n", "\n", "  `_name_repair`: treatment of problematic column names: \n", "    - \"minimal\": No name repair or checks, beyond basic existence,\n", "\n", "    - \"unique\": Make sure names are unique and not empty,\n", "\n", "    - \"check_unique\": (default value), no name repair,\n", "      but check they are unique, \n", "\n", "    - \"universal\": Make the names unique and syntactic\n", "\n", "    - a function: apply custom name repair\n", "\n", "##### Returns:\n", "  A data frame with all combination of variables. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ nesting
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### A helper that only finds combinations already present in the data.\n", "\n", "##### Args:\n", "  `*args`: and, \n", "  `**kwargs`: columns to expand. Columns can be atomic lists. \n", "    - To find all unique combinations of x, y and z, including\n", "      those not present in the data, supply each variable as a \n", "      separate argument: `expand(df, x, y, z)`. \n", "\n", "    - To find only the combinations that occur in the data, use\n", "      `nesting`: `expand(df, nesting(x, y, z))`. \n", "\n", "    - You can combine the two forms. For example,\n", "      `expand(df, nesting(school_id, student_id), date)` would \n", "      produce a row for each present school-student combination \n", "      for all possible dates. \n", "\n", "  `_name_repair`: treatment of problematic column names: \n", "    - \"minimal\": No name repair or checks, beyond basic existence,\n", "\n", "    - \"unique\": Make sure names are unique and not empty,\n", "\n", "    - \"check_unique\": (default value), no name repair,\n", "      but check they are unique, \n", "\n", "    - \"universal\": Make the names unique and syntactic\n", "\n", "    - a function: apply custom name repair\n", "\n", "##### Returns:\n", "  A data frame with all combinations in data. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ crossing
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### A wrapper around `expand_grid()` that de-duplicates and sorts its inputs\n", "\n", "When values are not specified by literal `list`, they will be sorted. \n", "\n", "##### Args:\n", "  `*args`: and, \n", "  `**kwargs`: columns to expand. Columns can be atomic lists. \n", "    - To find all unique combinations of x, y and z, including\n", "      those not present in the data, supply each variable as a \n", "      separate argument: `expand(df, x, y, z)`. \n", "\n", "    - To find only the combinations that occur in the data, use\n", "      `nesting`: `expand(df, nesting(x, y, z))`. \n", "\n", "    - You can combine the two forms. For example,\n", "      `expand(df, nesting(school_id, student_id), date)` would \n", "      produce a row for each present school-student combination \n", "      for all possible dates. \n", "\n", "  `_name_repair`: treatment of problematic column names: \n", "    - \"minimal\": No name repair or checks, beyond basic existence,\n", "\n", "    - \"unique\": Make sure names are unique and not empty,\n", "\n", "    - \"check_unique\": (default value), no name repair,\n", "      but check they are unique, \n", "\n", "    - \"universal\": Make the names unique and syntactic\n", "\n", "    - a function: apply custom name repair\n", "\n", "##### Returns:\n", "  A data frame with values deduplicated and sorted. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://tidyr.tidyverse.org/reference/expand.html\n", "%run nb_helpers.py\n", "\n", "from datar.all import *\n", "\n", "nb_header(expand, nesting, crossing)" ] }, { "cell_type": "code", "execution_count": 2, "id": "persistent-amino", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:14.918494Z", "iopub.status.busy": "2021-07-16T22:27:14.917685Z", "iopub.status.idle": "2021-07-16T22:27:15.099993Z", "shell.execute_reply": "2021-07-16T22:27:15.100386Z" } }, "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", "
typeyearsizeweights
<object><int64><category><float64>
0apple2010XS2.522472
1orange2010S0.206341
2apple2012M-0.667409
3orange2010S0.887561
4orange2010S-1.317738
5orange2012M-0.228718
\n", "
\n" ], "text/plain": [ " type year size weights\n", " \n", "0 apple 2010 XS 2.522472\n", "1 orange 2010 S 0.206341\n", "2 apple 2012 M -0.667409\n", "3 orange 2010 S 0.887561\n", "4 orange 2010 S -1.317738\n", "5 orange 2012 M -0.228718" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "fruits = tibble(\n", " type = c(\"apple\", \"orange\", \"apple\", \"orange\", \"orange\", \"orange\"),\n", " year = c(2010, 2010, 2012, 2010, 2010, 2012),\n", " size = factor(\n", " c(\"XS\", \"S\", \"M\", \"S\", \"S\", \"M\"),\n", " levels = c(\"XS\", \"S\", \"M\", \"L\")\n", " ),\n", " weights = rnorm(6)\n", ")\n", "fruits " ] }, { "cell_type": "code", "execution_count": 3, "id": "backed-short", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.137962Z", "iopub.status.busy": "2021-07-16T22:27:15.135563Z", "iopub.status.idle": "2021-07-16T22:27:15.304537Z", "shell.execute_reply": "2021-07-16T22:27:15.307272Z" } }, "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", "
type
<object>
0apple
1orange
\n", "
\n" ], "text/plain": [ " type\n", " \n", "0 apple\n", "1 orange" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fruits >> expand(f.type)" ] }, { "cell_type": "code", "execution_count": 4, "id": "asian-texture", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.389332Z", "iopub.status.busy": "2021-07-16T22:27:15.388776Z", "iopub.status.idle": "2021-07-16T22:27:15.495831Z", "shell.execute_reply": "2021-07-16T22:27:15.496225Z" } }, "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", "
typesize
<object><category>
0appleXS
1appleS
2appleM
3appleL
4orangeXS
5orangeS
6orangeM
7orangeL
\n", "
\n" ], "text/plain": [ " type size\n", " \n", "0 apple XS\n", "1 apple S\n", "2 apple M\n", "3 apple L\n", "4 orange XS\n", "5 orange S\n", "6 orange M\n", "7 orange L" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fruits >> expand(f.type, f.size) " ] }, { "cell_type": "code", "execution_count": 5, "id": "realistic-addiction", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.532936Z", "iopub.status.busy": "2021-07-16T22:27:15.532104Z", "iopub.status.idle": "2021-07-16T22:27:15.613973Z", "shell.execute_reply": "2021-07-16T22:27:15.614538Z" } }, "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", "
typesizeyear
<object><category><int64>
0appleXS2010
1appleXS2012
2appleS2010
3appleS2012
4appleM2010
5appleM2012
6appleL2010
7appleL2012
8orangeXS2010
9orangeXS2012
10orangeS2010
11orangeS2012
12orangeM2010
13orangeM2012
14orangeL2010
15orangeL2012
\n", "
\n" ], "text/plain": [ " type size year\n", " \n", "0 apple XS 2010\n", "1 apple XS 2012\n", "2 apple S 2010\n", "3 apple S 2012\n", "4 apple M 2010\n", "5 apple M 2012\n", "6 apple L 2010\n", "7 apple L 2012\n", "8 orange XS 2010\n", "9 orange XS 2012\n", "10 orange S 2010\n", "11 orange S 2012\n", "12 orange M 2010\n", "13 orange M 2012\n", "14 orange L 2010\n", "15 orange L 2012" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fruits >> expand(f.type, f.size, f.year)" ] }, { "cell_type": "code", "execution_count": 6, "id": "packed-edinburgh", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.640595Z", "iopub.status.busy": "2021-07-16T22:27:15.640010Z", "iopub.status.idle": "2021-07-16T22:27:15.766353Z", "shell.execute_reply": "2021-07-16T22:27:15.766709Z" } }, "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", "
type
<object>
0apple
1orange
\n", "
\n" ], "text/plain": [ " type\n", " \n", "0 apple\n", "1 orange" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fruits >> expand(nesting(f.type))" ] }, { "cell_type": "code", "execution_count": 7, "id": "opposed-installation", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.782939Z", "iopub.status.busy": "2021-07-16T22:27:15.782375Z", "iopub.status.idle": "2021-07-16T22:27:15.843231Z", "shell.execute_reply": "2021-07-16T22:27:15.843693Z" } }, "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", "
typesize
<object><category>
0appleXS
1orangeS
2appleM
3orangeM
\n", "
\n" ], "text/plain": [ " type size\n", " \n", "0 apple XS\n", "1 orange S\n", "2 apple M\n", "3 orange M" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fruits >> expand(nesting(f.type, f.size))" ] }, { "cell_type": "code", "execution_count": 8, "id": "difficult-norfolk", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.880587Z", "iopub.status.busy": "2021-07-16T22:27:15.880004Z", "iopub.status.idle": "2021-07-16T22:27:15.913491Z", "shell.execute_reply": "2021-07-16T22:27:15.914138Z" } }, "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", "
typesizeyear
<object><category><int64>
0appleXS2010
1orangeS2010
2appleM2012
3orangeM2012
\n", "
\n" ], "text/plain": [ " type size year\n", " \n", "0 apple XS 2010\n", "1 orange S 2010\n", "2 apple M 2012\n", "3 orange M 2012" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fruits >> expand(nesting(f.type, f.size, f.year))" ] }, { "cell_type": "code", "execution_count": 9, "id": "corporate-maple", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.923115Z", "iopub.status.busy": "2021-07-16T22:27:15.922506Z", "iopub.status.idle": "2021-07-16T22:27:15.957822Z", "shell.execute_reply": "2021-07-16T22:27:15.957294Z" } }, "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", "
typesize_VAR_2
<object><category><int64>
0appleXS2010
1appleXS2011
2appleXS2012
3appleS2010
4appleS2011
5appleS2012
6appleM2010
7appleM2011
8appleM2012
9appleL2010
10appleL2011
11appleL2012
12orangeXS2010
13orangeXS2011
14orangeXS2012
15orangeS2010
16orangeS2011
17orangeS2012
18orangeM2010
19orangeM2011
20orangeM2012
21orangeL2010
22orangeL2011
23orangeL2012
\n", "
\n" ], "text/plain": [ " type size _VAR_2\n", " \n", "0 apple XS 2010\n", "1 apple XS 2011\n", "2 apple XS 2012\n", "3 apple S 2010\n", "4 apple S 2011\n", "5 apple S 2012\n", "6 apple M 2010\n", "7 apple M 2011\n", "8 apple M 2012\n", "9 apple L 2010\n", "10 apple L 2011\n", "11 apple L 2012\n", "12 orange XS 2010\n", "13 orange XS 2011\n", "14 orange XS 2012\n", "15 orange S 2010\n", "16 orange S 2011\n", "17 orange S 2012\n", "18 orange M 2010\n", "19 orange M 2011\n", "20 orange M 2012\n", "21 orange L 2010\n", "22 orange L 2011\n", "23 orange L 2012" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fruits >> expand(f.type, f.size, full_seq(f.year, 1))" ] }, { "cell_type": "code", "execution_count": 10, "id": "developed-floor", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.969739Z", "iopub.status.busy": "2021-07-16T22:27:15.968313Z", "iopub.status.idle": "2021-07-16T22:27:15.998503Z", "shell.execute_reply": "2021-07-16T22:27:15.998872Z" } }, "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", "
typesize_VAR_2
<object><category><int64>
0appleXS2010
1appleXS2011
2appleXS2012
3appleS2010
4appleS2011
5appleS2012
6appleM2010
7appleM2011
8appleM2012
9appleL2010
10appleL2011
11appleL2012
12orangeXS2010
13orangeXS2011
14orangeXS2012
15orangeS2010
16orangeS2011
17orangeS2012
18orangeM2010
19orangeM2011
20orangeM2012
21orangeL2010
22orangeL2011
23orangeL2012
\n", "
\n" ], "text/plain": [ " type size _VAR_2\n", " \n", "0 apple XS 2010\n", "1 apple XS 2011\n", "2 apple XS 2012\n", "3 apple S 2010\n", "4 apple S 2011\n", "5 apple S 2012\n", "6 apple M 2010\n", "7 apple M 2011\n", "8 apple M 2012\n", "9 apple L 2010\n", "10 apple L 2011\n", "11 apple L 2012\n", "12 orange XS 2010\n", "13 orange XS 2011\n", "14 orange XS 2012\n", "15 orange S 2010\n", "16 orange S 2011\n", "17 orange S 2012\n", "18 orange M 2010\n", "19 orange M 2011\n", "20 orange M 2012\n", "21 orange L 2010\n", "22 orange L 2011\n", "23 orange L 2012" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fruits >> expand(f.type, f.size, seq(2010, 2012))" ] }, { "cell_type": "code", "execution_count": 11, "id": "alternate-addiction", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:16.051676Z", "iopub.status.busy": "2021-07-16T22:27:16.050970Z", "iopub.status.idle": "2021-07-16T22:27:16.065169Z", "shell.execute_reply": "2021-07-16T22:27:16.065694Z" } }, "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", "
typesizeyear
<object><category><int64>
0appleXS2010
1appleXS2011
2appleXS2012
3appleS2010
4appleS2011
5appleS2012
6appleM2010
7appleM2011
8appleM2012
9appleL2010
10appleL2011
11appleL2012
12orangeXS2010
13orangeXS2011
14orangeXS2012
15orangeS2010
16orangeS2011
17orangeS2012
18orangeM2010
19orangeM2011
20orangeM2012
21orangeL2010
22orangeL2011
23orangeL2012
\n", "
\n" ], "text/plain": [ " type size year\n", " \n", "0 apple XS 2010\n", "1 apple XS 2011\n", "2 apple XS 2012\n", "3 apple S 2010\n", "4 apple S 2011\n", "5 apple S 2012\n", "6 apple M 2010\n", "7 apple M 2011\n", "8 apple M 2012\n", "9 apple L 2010\n", "10 apple L 2011\n", "11 apple L 2012\n", "12 orange XS 2010\n", "13 orange XS 2011\n", "14 orange XS 2012\n", "15 orange S 2010\n", "16 orange S 2011\n", "17 orange S 2012\n", "18 orange M 2010\n", "19 orange M 2011\n", "20 orange M 2012\n", "21 orange L 2010\n", "22 orange L 2011\n", "23 orange L 2012" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fruits >> expand(f.type, f.size, year=seq(2010, 2012))" ] }, { "cell_type": "code", "execution_count": 12, "id": "regular-employment", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:16.100570Z", "iopub.status.busy": "2021-07-16T22:27:16.099899Z", "iopub.status.idle": "2021-07-16T22:27:16.137413Z", "shell.execute_reply": "2021-07-16T22:27:16.138469Z" } }, "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", "
typesizeyear
<object><category><int64>
0appleXS2010
1appleXS2012
2appleS2010
3appleS2012
4appleM2010
5appleM2012
6appleL2010
7appleL2012
8orangeXS2010
9orangeXS2012
10orangeS2010
11orangeS2012
12orangeM2010
13orangeM2012
14orangeL2010
15orangeL2012
\n", "
\n" ], "text/plain": [ " type size year\n", " \n", "0 apple XS 2010\n", "1 apple XS 2012\n", "2 apple S 2010\n", "3 apple S 2012\n", "4 apple M 2010\n", "5 apple M 2012\n", "6 apple L 2010\n", "7 apple L 2012\n", "8 orange XS 2010\n", "9 orange XS 2012\n", "10 orange S 2010\n", "11 orange S 2012\n", "12 orange M 2010\n", "13 orange M 2012\n", "14 orange L 2010\n", "15 orange L 2012" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "all = fruits >> expand(f.type, f.size, f.year)\n", "all" ] }, { "cell_type": "code", "execution_count": 13, "id": "olive-tucson", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:16.236056Z", "iopub.status.busy": "2021-07-16T22:27:16.235177Z", "iopub.status.idle": "2021-07-16T22:27:16.353065Z", "shell.execute_reply": "2021-07-16T22:27:16.354380Z" } }, "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", "
typesizeyear
<object><category><int64>
1appleXS2012
2appleS2010
3appleS2012
4appleM2010
6appleL2010
7appleL2012
8orangeXS2010
9orangeXS2012
13orangeS2012
14orangeM2010
16orangeL2010
17orangeL2012
\n", "
\n" ], "text/plain": [ " type size year\n", " \n", "1 apple XS 2012\n", "2 apple S 2010\n", "3 apple S 2012\n", "4 apple M 2010\n", "6 apple L 2010\n", "7 apple L 2012\n", "8 orange XS 2010\n", "9 orange XS 2012\n", "13 orange S 2012\n", "14 orange M 2010\n", "16 orange L 2010\n", "17 orange L 2012" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "all >> anti_join(fruits)" ] }, { "cell_type": "code", "execution_count": 14, "id": "random-bowling", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:16.366841Z", "iopub.status.busy": "2021-07-16T22:27:16.365974Z", "iopub.status.idle": "2021-07-16T22:27:16.427464Z", "shell.execute_reply": "2021-07-16T22:27:16.428041Z" } }, "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", "
typeyearsizeweights
<object><int64><category><float64>
0apple2010XS2.522472
1apple2012XSNaN
2apple2010SNaN
3apple2012SNaN
4apple2010MNaN
5apple2012M-0.667409
6apple2010LNaN
7apple2012LNaN
8orange2010XSNaN
9orange2012XSNaN
10orange2010S0.206341
11orange2010S0.887561
12orange2010S-1.317738
13orange2012SNaN
14orange2010MNaN
15orange2012M-0.228718
16orange2010LNaN
17orange2012LNaN
\n", "
\n" ], "text/plain": [ " type year size weights\n", " \n", "0 apple 2010 XS 2.522472\n", "1 apple 2012 XS NaN\n", "2 apple 2010 S NaN\n", "3 apple 2012 S NaN\n", "4 apple 2010 M NaN\n", "5 apple 2012 M -0.667409\n", "6 apple 2010 L NaN\n", "7 apple 2012 L NaN\n", "8 orange 2010 XS NaN\n", "9 orange 2012 XS NaN\n", "10 orange 2010 S 0.206341\n", "11 orange 2010 S 0.887561\n", "12 orange 2010 S -1.317738\n", "13 orange 2012 S NaN\n", "14 orange 2010 M NaN\n", "15 orange 2012 M -0.228718\n", "16 orange 2010 L NaN\n", "17 orange 2012 L NaN" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fruits >> right_join(all)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/expand_grid.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "respiratory-oriental", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:02.594424Z", "iopub.status.busy": "2021-07-16T22:28:02.593842Z", "iopub.status.idle": "2021-07-16T22:28:03.465029Z", "shell.execute_reply": "2021-07-16T22:28:03.465435Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ expand_grid
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Expand a grid\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "  `*args`: Additional numeric vectors \n", "  `**kwargs`: Additional keyword arguments \n", "\n", "##### Returns:\n", "  The expanded grid \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://tidyr.tidyverse.org/reference/expand_grid.html\n", "%run nb_helpers.py\n", "\n", "from datar.all import *\n", "\n", "nb_header(expand_grid)" ] }, { "cell_type": "code", "execution_count": 2, "id": "driven-cornwall", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:03.507985Z", "iopub.status.busy": "2021-07-16T22:28:03.507421Z", "iopub.status.idle": "2021-07-16T22:28:03.690295Z", "shell.execute_reply": "2021-07-16T22:28:03.690760Z" } }, "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", "
xy
<int64><int64>
011
112
221
322
431
532
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 1 1\n", "1 1 2\n", "2 2 1\n", "3 2 2\n", "4 3 1\n", "5 3 2" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "expand_grid(x=seq(1,3), y=seq(1,2))" ] }, { "cell_type": "code", "execution_count": 3, "id": "structural-assembly", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:03.723628Z", "iopub.status.busy": "2021-07-16T22:28:03.722356Z", "iopub.status.idle": "2021-07-16T22:28:03.731096Z", "shell.execute_reply": "2021-07-16T22:28:03.731540Z" } }, "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", "
l1l2
<object><object>
0aA
1aB
2aC
3aD
.........
4aE
671zV
672zW
673zX
674zY
675zZ
\n", "

676 rows × 2 columns

\n", "
\n" ], "text/plain": [ " l1 l2\n", " \n", "0 a A\n", "1 a B\n", "2 a C\n", "3 a D\n", ".. ... ...\n", "4 a E\n", "671 z V\n", "672 z W\n", "673 z X\n", "674 z Y\n", "675 z Z\n", "\n", "[676 rows x 2 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "expand_grid(l1=letters, l2=LETTERS)" ] }, { "cell_type": "code", "execution_count": 4, "id": "nervous-sterling", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:03.760022Z", "iopub.status.busy": "2021-07-16T22:28:03.759343Z", "iopub.status.idle": "2021-07-16T22:28:03.798135Z", "shell.execute_reply": "2021-07-16T22:28:03.798629Z" } }, "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", "
df$xdf$yz
<int64><int64><int64>
0121
1122
2123
3211
4212
5213
\n", "
\n" ], "text/plain": [ " df$x df$y z\n", " \n", "0 1 2 1\n", "1 1 2 2\n", "2 1 2 3\n", "3 2 1 1\n", "4 2 1 2\n", "5 2 1 3" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "expand_grid(df=tibble(x=[1,2], y=c(2, 1)), z=[1,2,3])" ] }, { "cell_type": "code", "execution_count": 5, "id": "super-champagne", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:03.824682Z", "iopub.status.busy": "2021-07-16T22:28:03.823796Z", "iopub.status.idle": "2021-07-16T22:28:03.888499Z", "shell.execute_reply": "2021-07-16T22:28:03.889119Z" } }, "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", "
x1$ax1$bx2$ax2$b
<int64><int64><int64><int64>
01357
11368
22457
32468
\n", "
\n" ], "text/plain": [ " x1$a x1$b x2$a x2$b\n", " \n", "0 1 3 5 7\n", "1 1 3 6 8\n", "2 2 4 5 7\n", "3 2 4 6 8" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "expand_grid(x1=tibble(a=[1,2], b=[3,4]), x2=tibble(a=[5,6], b=[7,8]))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/extract.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "processed-allah", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:56.819249Z", "iopub.status.busy": "2021-07-16T22:27:56.813812Z", "iopub.status.idle": "2021-07-16T22:27:57.713922Z", "shell.execute_reply": "2021-07-16T22:27:57.714378Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ extract
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Given a regular expression with capturing groups, extract() turns each\n", "group into a new column. If the groups don't match, or the input is NA, \n", "the output will be NA. \n", "\n", "See https://tidyr.tidyverse.org/reference/extract.html \n", "\n", "##### Args:\n", "  `data`: The dataframe \n", "  `col`: Column name or position. \n", "  `into`: Names of new variables to create as character vector. \n", "    Use None to omit the variable in the output. \n", "\n", "  `regex`: a regular expression used to extract the desired values. \n", "    There should be one group (defined by ()) for each element of into. \n", "\n", "  `remove`: If TRUE, remove input column from output data frame. \n", "  `convert`: The universal type for the extracted columns or a dict for \n", "    individual ones \n", "\n", "##### Returns:\n", "  Dataframe with extracted columns. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://tidyr.tidyverse.org/reference/extract.html\n", "%run nb_helpers.py\n", "\n", "from datar.all import *\n", "\n", "nb_header(extract)" ] }, { "cell_type": "code", "execution_count": 2, "id": "caring-munich", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:57.721455Z", "iopub.status.busy": "2021-07-16T22:27:57.720888Z", "iopub.status.idle": "2021-07-16T22:27:57.915716Z", "shell.execute_reply": "2021-07-16T22:27:57.916273Z" } }, "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", "
A
<object>
0NaN
1a
2a
3b
4d
\n", "
\n" ], "text/plain": [ " A\n", " \n", "0 NaN\n", "1 a\n", "2 a\n", "3 b\n", "4 d" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x = c(NA, \"a-b\", \"a-d\", \"b-c\", \"d-e\"))\n", "df >> extract(f.x, \"A\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "registered-investment", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:57.929149Z", "iopub.status.busy": "2021-07-16T22:27:57.928412Z", "iopub.status.idle": "2021-07-16T22:27:57.931807Z", "shell.execute_reply": "2021-07-16T22:27:57.932199Z" } }, "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", "
AB
<object><object>
0NaNNaN
1ab
2ad
3bc
4de
\n", "
\n" ], "text/plain": [ " A B\n", " \n", "0 NaN NaN\n", "1 a b\n", "2 a d\n", "3 b c\n", "4 d e" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> extract(f.x, c(\"A\", \"B\"), r\"(\\w+)-(\\w+)\")" ] }, { "cell_type": "code", "execution_count": 4, "id": "celtic-mortality", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:57.944560Z", "iopub.status.busy": "2021-07-16T22:27:57.943905Z", "iopub.status.idle": "2021-07-16T22:27:57.946848Z", "shell.execute_reply": "2021-07-16T22:27:57.947195Z" } }, "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", "
AB
<object><object>
0NaNNaN
1ab
2ad
3bc
4NaNNaN
\n", "
\n" ], "text/plain": [ " A B\n", " \n", "0 NaN NaN\n", "1 a b\n", "2 a d\n", "3 b c\n", "4 NaN NaN" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> extract(f.x, c(\"A\", \"B\"), r\"([a-d]+)-([a-d]+)\")" ] }, { "cell_type": "code", "execution_count": 5, "id": "8deb631b", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:57.958227Z", "iopub.status.busy": "2021-07-16T22:27:57.956839Z", "iopub.status.idle": "2021-07-16T22:27:57.981449Z", "shell.execute_reply": "2021-07-16T22:27:57.981988Z" } }, "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", "
ab
<object><object>
0acbd
\n", "
\n" ], "text/plain": [ " a b\n", " \n", "0 ac bd" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# combine multiple columns\n", "df = tibble(x='abcd')\n", "df >> extract(f.x, ['a', 'b', 'a', 'b'], r'(.)(.)(.)(.)')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/fill.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "armed-shield", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:31.394446Z", "iopub.status.busy": "2021-07-16T22:28:31.393014Z", "iopub.status.idle": "2021-07-16T22:28:32.393689Z", "shell.execute_reply": "2021-07-16T22:28:32.394219Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fill
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Fills missing values in selected columns using the next or\n", "previous entry. \n", "\n", "See https://tidyr.tidyverse.org/reference/fill.html \n", "\n", "##### Args:\n", "  `_data`: A dataframe \n", "  `*columns`: Columns to fill \n", "  `_direction`: Direction in which to fill missing values. \n", "    Currently either \"down\" (the default), \"up\", \n", "    \"downup\" (i.e. first down and then up) or \n", "    \"updown\" (first up and then down). \n", "\n", "##### Returns:\n", "  The dataframe with NAs being replaced. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://tidyr.tidyverse.org/reference/fill.html\n", "%run nb_helpers.py\n", "\n", "from datar.all import *\n", "\n", "nb_header(fill)" ] }, { "cell_type": "code", "execution_count": 2, "id": "coral-musician", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:32.409593Z", "iopub.status.busy": "2021-07-16T22:28:32.408665Z", "iopub.status.idle": "2021-07-16T22:28:32.412799Z", "shell.execute_reply": "2021-07-16T22:28:32.413197Z" } }, "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", "
quarteryearsales
<object><float64><int64>
0Q12000.066013
1Q2NaN69182
2Q3NaN53175
3Q4NaN21001
4Q12001.046036
5Q2NaN58842
6Q3NaN44568
7Q4NaN50197
8Q12002.039113
9Q2NaN41668
10Q3NaN30144
11Q4NaN52897
12Q12004.032129
13Q2NaN67686
14Q3NaN31768
15Q4NaN49094
\n", "
\n" ], "text/plain": [ " quarter year sales\n", " \n", "0 Q1 2000.0 66013\n", "1 Q2 NaN 69182\n", "2 Q3 NaN 53175\n", "3 Q4 NaN 21001\n", "4 Q1 2001.0 46036\n", "5 Q2 NaN 58842\n", "6 Q3 NaN 44568\n", "7 Q4 NaN 50197\n", "8 Q1 2002.0 39113\n", "9 Q2 NaN 41668\n", "10 Q3 NaN 30144\n", "11 Q4 NaN 52897\n", "12 Q1 2004.0 32129\n", "13 Q2 NaN 67686\n", "14 Q3 NaN 31768\n", "15 Q4 NaN 49094" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sales = tribble(\n", " f.quarter, f.year, f.sales,\n", " \"Q1\", 2000, 66013,\n", " \"Q2\", NA, 69182,\n", " \"Q3\", NA, 53175,\n", " \"Q4\", NA, 21001,\n", " \"Q1\", 2001, 46036,\n", " \"Q2\", NA, 58842,\n", " \"Q3\", NA, 44568,\n", " \"Q4\", NA, 50197,\n", " \"Q1\", 2002, 39113,\n", " \"Q2\", NA, 41668,\n", " \"Q3\", NA, 30144,\n", " \"Q4\", NA, 52897,\n", " \"Q1\", 2004, 32129,\n", " \"Q2\", NA, 67686,\n", " \"Q3\", NA, 31768,\n", " \"Q4\", NA, 49094\n", ")\n", "sales" ] }, { "cell_type": "code", "execution_count": 3, "id": "dramatic-break", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:32.436403Z", "iopub.status.busy": "2021-07-16T22:28:32.435653Z", "iopub.status.idle": "2021-07-16T22:28:32.478246Z", "shell.execute_reply": "2021-07-16T22:28:32.478714Z" } }, "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", "
quarteryearsales
<object><float64><int64>
0Q12000.066013
1Q22000.069182
2Q32000.053175
3Q42000.021001
4Q12001.046036
5Q22001.058842
6Q32001.044568
7Q42001.050197
8Q12002.039113
9Q22002.041668
10Q32002.030144
11Q42002.052897
12Q12004.032129
13Q22004.067686
14Q32004.031768
15Q42004.049094
\n", "
\n" ], "text/plain": [ " quarter year sales\n", " \n", "0 Q1 2000.0 66013\n", "1 Q2 2000.0 69182\n", "2 Q3 2000.0 53175\n", "3 Q4 2000.0 21001\n", "4 Q1 2001.0 46036\n", "5 Q2 2001.0 58842\n", "6 Q3 2001.0 44568\n", "7 Q4 2001.0 50197\n", "8 Q1 2002.0 39113\n", "9 Q2 2002.0 41668\n", "10 Q3 2002.0 30144\n", "11 Q4 2002.0 52897\n", "12 Q1 2004.0 32129\n", "13 Q2 2004.0 67686\n", "14 Q3 2004.0 31768\n", "15 Q4 2004.0 49094" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sales >> fill(f.year)" ] }, { "cell_type": "code", "execution_count": 4, "id": "intelligent-scanner", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:32.495256Z", "iopub.status.busy": "2021-07-16T22:28:32.485963Z", "iopub.status.idle": "2021-07-16T22:28:32.498776Z", "shell.execute_reply": "2021-07-16T22:28:32.499177Z" } }, "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", "
rankpet_typebreed
<int64><object><object>
01DogBoston Terrier
12DogRetrievers (Labrador)
23DogRetrievers (Golden)
34DogFrench Bulldogs
45DogBulldogs
56DogBeagles
61CatPersian
72CatMaine Coon
83CatRagdoll
94CatExotic
105CatSiamese
116CatAmerican Short
\n", "
\n" ], "text/plain": [ " rank pet_type breed\n", " \n", "0 1 Dog Boston Terrier\n", "1 2 Dog Retrievers (Labrador)\n", "2 3 Dog Retrievers (Golden)\n", "3 4 Dog French Bulldogs\n", "4 5 Dog Bulldogs\n", "5 6 Dog Beagles\n", "6 1 Cat Persian\n", "7 2 Cat Maine Coon\n", "8 3 Cat Ragdoll\n", "9 4 Cat Exotic\n", "10 5 Cat Siamese\n", "11 6 Cat American Short" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tidy_pets = tribble(\n", " f.rank, f.pet_type, f.breed,\n", " 1, NA, \"Boston Terrier\",\n", " 2, NA, \"Retrievers (Labrador)\",\n", " 3, NA, \"Retrievers (Golden)\",\n", " 4, NA, \"French Bulldogs\",\n", " 5, NA, \"Bulldogs\",\n", " 6, \"Dog\", \"Beagles\",\n", " 1, NA, \"Persian\",\n", " 2, NA, \"Maine Coon\",\n", " 3, NA, \"Ragdoll\",\n", " 4, NA, \"Exotic\",\n", " 5, NA, \"Siamese\",\n", " 6, \"Cat\", \"American Short\"\n", ")\n", "tidy_pets >> fill(f.pet_type, _direction = \"up\")" ] }, { "cell_type": "code", "execution_count": 5, "id": "level-assistant", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:32.509886Z", "iopub.status.busy": "2021-07-16T22:28:32.507992Z", "iopub.status.idle": "2021-07-16T22:28:32.598870Z", "shell.execute_reply": "2021-07-16T22:28:32.598415Z" } }, "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", "
groupnamerolen_squirrels
<int64><object><object><float64>
01SamObserver8.0
11MaraScorekeeper8.0
21JesseObserver8.0
31TomObserver8.0
42MikeObserver14.0
52RachaelObserver14.0
62SydekeaScorekeeper14.0
72GabrielaObserver14.0
83DerrickObserver9.0
93KaraScorekeeper9.0
103EmilyObserver9.0
113DanielleObserver9.0
\n", "
\n", "

TibbleGrouped: group (n=3)" ], "text/plain": [ " group name role n_squirrels\n", " \n", "0 1 Sam Observer 8.0\n", "1 1 Mara Scorekeeper 8.0\n", "2 1 Jesse Observer 8.0\n", "3 1 Tom Observer 8.0\n", "4 2 Mike Observer 14.0\n", "5 2 Rachael Observer 14.0\n", "6 2 Sydekea Scorekeeper 14.0\n", "7 2 Gabriela Observer 14.0\n", "8 3 Derrick Observer 9.0\n", "9 3 Kara Scorekeeper 9.0\n", "10 3 Emily Observer 9.0\n", "11 3 Danielle Observer 9.0\n", "[TibbleGrouped: group (n=3)]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "squirrels = tribble(\n", " f.group, f.name, f.role, f.n_squirrels,\n", " 1, \"Sam\", \"Observer\", NA,\n", " 1, \"Mara\", \"Scorekeeper\", 8,\n", " 1, \"Jesse\", \"Observer\", NA,\n", " 1, \"Tom\", \"Observer\", NA,\n", " 2, \"Mike\", \"Observer\", NA,\n", " 2, \"Rachael\", \"Observer\", NA,\n", " 2, \"Sydekea\", \"Scorekeeper\", 14,\n", " 2, \"Gabriela\", \"Observer\", NA,\n", " 3, \"Derrick\", \"Observer\", NA,\n", " 3, \"Kara\", \"Scorekeeper\", 9,\n", " 3, \"Emily\", \"Observer\", NA,\n", " 3, \"Danielle\", \"Observer\", NA\n", ")\n", " \n", "squirrels >> \\\n", " group_by(f.group) >> \\\n", " fill(f.n_squirrels, _direction = \"downup\") " ] }, { "cell_type": "code", "execution_count": null, "id": "little-practice", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/filter-joins.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:41.370298Z", "iopub.status.busy": "2021-07-16T22:27:41.368998Z", "iopub.status.idle": "2021-07-16T22:27:42.302245Z", "shell.execute_reply": "2021-07-16T22:27:42.302701Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ semi_join
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Semi join two data frames by matching rows.\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/join.html \n", "\n", "##### Args:\n", "  `x`: A data frame \n", "  `y`: A data frame \n", "  `by`: A list of column names to join by. \n", "    If None, use the intersection of the columns of x and y. \n", "\n", "  `copy`: If True, always copy the data. \n", "\n", "##### Returns:\n", "  A data frame \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ anti_join
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Anti join two data frames by matching rows.\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/join.html \n", "\n", "##### Args:\n", "  `x`: A data frame \n", "  `y`: A data frame \n", "  `by`: A list of column names to join by. \n", "    If None, use the intersection of the columns of x and y. \n", "\n", "  `copy`: If True, always copy the data. \n", "\n", "##### Returns:\n", "  A data frame \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/filter-joins.html\n", "%run nb_helpers.py\n", "\n", "from datar.data import band_members, band_instruments\n", "from datar.all import *\n", "\n", "nb_header(semi_join, anti_join, book='filter-joins')" ] }, { "cell_type": "code", "execution_count": 2, "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", "
nameband
<object><object>
0MickStones
1JohnBeatles
2PaulBeatles
\n", "
\n" ], "text/plain": [ " name band\n", " \n", "0 Mick Stones\n", "1 John Beatles\n", "2 Paul Beatles" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "band_members" ] }, { "cell_type": "code", "execution_count": 3, "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", "
nameplays
<object><object>
0Johnguitar
1Paulbass
2Keithguitar
\n", "
\n" ], "text/plain": [ " name plays\n", " \n", "0 John guitar\n", "1 Paul bass\n", "2 Keith guitar" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "band_instruments" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:42.371916Z", "iopub.status.busy": "2021-07-16T22:27:42.370067Z", "iopub.status.idle": "2021-07-16T22:27:42.398547Z", "shell.execute_reply": "2021-07-16T22:27:42.399395Z" } }, "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", "
nameband
<object><object>
1JohnBeatles
2PaulBeatles
\n", "
\n" ], "text/plain": [ " name band\n", " \n", "1 John Beatles\n", "2 Paul Beatles" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "band_members >> semi_join(band_instruments)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:42.426844Z", "iopub.status.busy": "2021-07-16T22:27:42.426222Z", "iopub.status.idle": "2021-07-16T22:27:42.437212Z", "shell.execute_reply": "2021-07-16T22:27:42.436497Z" } }, "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", "
nameband
<object><object>
0MickStones
\n", "
\n" ], "text/plain": [ " name band\n", " \n", "0 Mick Stones" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "band_members >> anti_join(band_instruments, by={'name': 'name'})" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/filter.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:19.245063Z", "iopub.status.busy": "2021-07-16T22:27:19.244401Z", "iopub.status.idle": "2021-07-16T22:27:20.145099Z", "shell.execute_reply": "2021-07-16T22:27:20.144206Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ filter_
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Filter a data frame based on conditions\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/filter.html \n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `*conditions`: Conditions to filter by. \n", "  `_preserve`: If `True`, keep grouping variables even if they are not used. \n", "\n", "##### Returns:\n", "  The subset dataframe \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/filter.html\n", "%run nb_helpers.py\n", "from datar.data import starwars\n", "from datar.all import *\n", "\n", "nb_header(filter)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:20.178910Z", "iopub.status.busy": "2021-07-16T22:27:20.178291Z", "iopub.status.idle": "2021-07-16T22:27:20.185838Z", "shell.execute_reply": "2021-07-16T22:27:20.186271Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
nameheightmasshair_colorskin_coloreye_colorbirth_yearsexgenderhomeworldspecies
<object><float64><float64><object><object><object><float64><object><object><object><object>
0Luke Skywalker172.077.0blondfairblue19.0malemasculineTatooineHuman
3Darth Vader202.0136.0nonewhiteyellow41.9malemasculineTatooineHuman
4Leia Organa150.049.0brownlightbrown19.0femalefeminineAlderaanHuman
5Owen Lars178.0120.0brown, greylightblue52.0malemasculineTatooineHuman
6Beru Whitesun lars165.075.0brownlightblue47.0femalefeminineTatooineHuman
8Biggs Darklighter183.084.0blacklightbrown24.0malemasculineTatooineHuman
9Obi-Wan Kenobi182.077.0auburn, whitefairblue-gray57.0malemasculineStewjonHuman
10Anakin Skywalker188.084.0blondfairblue41.9malemasculineTatooineHuman
11Wilhuff Tarkin180.0NaNauburn, greyfairblue64.0malemasculineEriaduHuman
13Han Solo180.080.0brownfairbrown29.0malemasculineCorelliaHuman
16Wedge Antilles170.077.0brownfairhazel21.0malemasculineCorelliaHuman
17Jek Tono Porkins180.0110.0brownfairblueNaNmalemasculineBestine IVHuman
19Palpatine170.075.0greypaleyellow82.0malemasculineNabooHuman
20Boba Fett183.078.2blackfairbrown31.5malemasculineKaminoHuman
23Lando Calrissian177.079.0blackdarkbrown31.0malemasculineSocorroHuman
24Lobot175.079.0nonelightblue37.0malemasculineBespinHuman
26Mon Mothma150.0NaNauburnfairblue48.0femalefeminineChandrilaHuman
27Arvel CrynydNaNNaNbrownfairbrownNaNmalemasculineNaNHuman
30Qui-Gon Jinn193.089.0brownfairblue92.0malemasculineNaNHuman
32Finis Valorum170.0NaNblondfairblue91.0malemasculineCoruscantHuman
40Shmi Skywalker163.0NaNblackfairbrown72.0femalefeminineTatooineHuman
47Mace Windu188.084.0nonedarkbrown72.0malemasculineHaruun KalHuman
56Gregar Typho185.085.0blackdarkbrownNaNmalemasculineNabooHuman
57Cordé157.0NaNbrownlightbrownNaNfemalefeminineNabooHuman
58Cliegg Lars183.0NaNbrownfairblue82.0malemasculineTatooineHuman
62Dormé165.0NaNbrownlightbrownNaNfemalefeminineNabooHuman
63Dooku193.080.0whitefairbrown102.0malemasculineSerennoHuman
64Bail Prestor Organa191.0NaNblacktanbrown67.0malemasculineAlderaanHuman
65Jango Fett183.079.0blacktanbrown66.0malemasculineConcord DawnHuman
70Jocasta Nu167.0NaNwhitefairblueNaNfemalefeminineCoruscantHuman
78Raymus Antilles188.079.0brownlightbrownNaNmalemasculineAlderaanHuman
81FinnNaNNaNblackdarkdarkNaNmalemasculineNaNHuman
82ReyNaNNaNbrownlighthazelNaNfemalefeminineNaNHuman
83Poe DameronNaNNaNbrownlightbrownNaNmalemasculineNaNHuman
86Padmé Amidala165.045.0brownlightbrown46.0femalefeminineNabooHuman
\n", "
\n" ], "text/plain": [ " name height mass hair_color skin_color \\\n", " \n", "0 Luke Skywalker 172.0 77.0 blond fair \n", "3 Darth Vader 202.0 136.0 none white \n", "4 Leia Organa 150.0 49.0 brown light \n", "5 Owen Lars 178.0 120.0 brown, grey light \n", "6 Beru Whitesun lars 165.0 75.0 brown light \n", "8 Biggs Darklighter 183.0 84.0 black light \n", "9 Obi-Wan Kenobi 182.0 77.0 auburn, white fair \n", "10 Anakin Skywalker 188.0 84.0 blond fair \n", "11 Wilhuff Tarkin 180.0 NaN auburn, grey fair \n", "13 Han Solo 180.0 80.0 brown fair \n", "16 Wedge Antilles 170.0 77.0 brown fair \n", "17 Jek Tono Porkins 180.0 110.0 brown fair \n", "19 Palpatine 170.0 75.0 grey pale \n", "20 Boba Fett 183.0 78.2 black fair \n", "23 Lando Calrissian 177.0 79.0 black dark \n", "24 Lobot 175.0 79.0 none light \n", "26 Mon Mothma 150.0 NaN auburn fair \n", "27 Arvel Crynyd NaN NaN brown fair \n", "30 Qui-Gon Jinn 193.0 89.0 brown fair \n", "32 Finis Valorum 170.0 NaN blond fair \n", "40 Shmi Skywalker 163.0 NaN black fair \n", "47 Mace Windu 188.0 84.0 none dark \n", "56 Gregar Typho 185.0 85.0 black dark \n", "57 Cordé 157.0 NaN brown light \n", "58 Cliegg Lars 183.0 NaN brown fair \n", "62 Dormé 165.0 NaN brown light \n", "63 Dooku 193.0 80.0 white fair \n", "64 Bail Prestor Organa 191.0 NaN black tan \n", "65 Jango Fett 183.0 79.0 black tan \n", "70 Jocasta Nu 167.0 NaN white fair \n", "78 Raymus Antilles 188.0 79.0 brown light \n", "81 Finn NaN NaN black dark \n", "82 Rey NaN NaN brown light \n", "83 Poe Dameron NaN NaN brown light \n", "86 Padmé Amidala 165.0 45.0 brown light \n", "\n", " eye_color birth_year sex gender homeworld species \n", " \n", "0 blue 19.0 male masculine Tatooine Human \n", "3 yellow 41.9 male masculine Tatooine Human \n", "4 brown 19.0 female feminine Alderaan Human \n", "5 blue 52.0 male masculine Tatooine Human \n", "6 blue 47.0 female feminine Tatooine Human \n", "8 brown 24.0 male masculine Tatooine Human \n", "9 blue-gray 57.0 male masculine Stewjon Human \n", "10 blue 41.9 male masculine Tatooine Human \n", "11 blue 64.0 male masculine Eriadu Human \n", "13 brown 29.0 male masculine Corellia Human \n", "16 hazel 21.0 male masculine Corellia Human \n", "17 blue NaN male masculine Bestine IV Human \n", "19 yellow 82.0 male masculine Naboo Human \n", "20 brown 31.5 male masculine Kamino Human \n", "23 brown 31.0 male masculine Socorro Human \n", "24 blue 37.0 male masculine Bespin Human \n", "26 blue 48.0 female feminine Chandrila Human \n", "27 brown NaN male masculine NaN Human \n", "30 blue 92.0 male masculine NaN Human \n", "32 blue 91.0 male masculine Coruscant Human \n", "40 brown 72.0 female feminine Tatooine Human \n", "47 brown 72.0 male masculine Haruun Kal Human \n", "56 brown NaN male masculine Naboo Human \n", "57 brown NaN female feminine Naboo Human \n", "58 blue 82.0 male masculine Tatooine Human \n", "62 brown NaN female feminine Naboo Human \n", "63 brown 102.0 male masculine Serenno Human \n", "64 brown 67.0 male masculine Alderaan Human \n", "65 brown 66.0 male masculine Concord Dawn Human \n", "70 blue NaN female feminine Coruscant Human \n", "78 brown NaN male masculine Alderaan Human \n", "81 dark NaN male masculine NaN Human \n", "82 hazel NaN female feminine NaN Human \n", "83 brown NaN male masculine NaN Human \n", "86 brown 46.0 female feminine Naboo Human " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "filter(starwars, f.species == \"Human\")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:20.221069Z", "iopub.status.busy": "2021-07-16T22:27:20.220335Z", "iopub.status.idle": "2021-07-16T22:27:20.231762Z", "shell.execute_reply": "2021-07-16T22:27:20.232200Z" } }, "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", "
nameheightmasshair_colorskin_coloreye_colorbirth_yearsexgenderhomeworldspecies
<object><float64><float64><object><object><object><float64><object><object><object><object>
15Jabba Desilijic Tiure175.01358.0NaNgreen-tan, brownorange600.0hermaphroditicmasculineNal HuttaHutt
\n", "
\n" ], "text/plain": [ " name height mass hair_color skin_color \\\n", " \n", "15 Jabba Desilijic Tiure 175.0 1358.0 NaN green-tan, brown \n", "\n", " eye_color birth_year sex gender homeworld species \n", " \n", "15 orange 600.0 hermaphroditic masculine Nal Hutta Hutt " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "filter(starwars, f.mass > 1000)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:20.260375Z", "iopub.status.busy": "2021-07-16T22:27:20.259506Z", "iopub.status.idle": "2021-07-16T22:27:20.273843Z", "shell.execute_reply": "2021-07-16T22:27:20.273081Z" } }, "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", "
nameheightmasshair_colorskin_coloreye_colorbirth_yearsexgenderhomeworldspecies
<object><float64><float64><object><object><object><float64><object><object><object><object>
29Nien Nunb160.068.0nonegreyblackNaNmalemasculineSullustSullustan
45Gasgano122.0NaNnonewhite, blueblackNaNmalemasculineTroikenXexto
49Kit Fisto196.087.0nonegreenblackNaNmalemasculineGlee AnselmNautolan
54Plo Koon188.080.0noneorangeblack22.0malemasculineDorinKel Dor
68Lama Su229.088.0nonegreyblackNaNmalemasculineKaminoKaminoan
69Taun We213.0NaNnonegreyblackNaNfemalefeminineKaminoKaminoan
75Shaak Ti178.057.0nonered, blue, whiteblackNaNfemalefeminineShiliTogruta
80Tion Medon206.080.0nonegreyblackNaNmalemasculineUtapauPau'an
84BB8NaNNaNnonenoneblackNaNnonemasculineNaNDroid
\n", "
\n" ], "text/plain": [ " name height mass hair_color skin_color eye_color \\\n", " \n", "29 Nien Nunb 160.0 68.0 none grey black \n", "45 Gasgano 122.0 NaN none white, blue black \n", "49 Kit Fisto 196.0 87.0 none green black \n", "54 Plo Koon 188.0 80.0 none orange black \n", "68 Lama Su 229.0 88.0 none grey black \n", "69 Taun We 213.0 NaN none grey black \n", "75 Shaak Ti 178.0 57.0 none red, blue, white black \n", "80 Tion Medon 206.0 80.0 none grey black \n", "84 BB8 NaN NaN none none black \n", "\n", " birth_year sex gender homeworld species \n", " \n", "29 NaN male masculine Sullust Sullustan \n", "45 NaN male masculine Troiken Xexto \n", "49 NaN male masculine Glee Anselm Nautolan \n", "54 22.0 male masculine Dorin Kel Dor \n", "68 NaN male masculine Kamino Kaminoan \n", "69 NaN female feminine Kamino Kaminoan \n", "75 NaN female feminine Shili Togruta \n", "80 NaN male masculine Utapau Pau'an \n", "84 NaN none masculine NaN Droid " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Conditions connected by & or | have to wrapped, since == has lower priority than & does\n", "filter(starwars, (f.hair_color == \"none\") & (f.eye_color == \"black\"))" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:20.313774Z", "iopub.status.busy": "2021-07-16T22:27:20.312830Z", "iopub.status.idle": "2021-07-16T22:27:20.325457Z", "shell.execute_reply": "2021-07-16T22:27:20.325892Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
nameheightmasshair_colorskin_coloreye_colorbirth_yearsexgenderhomeworldspecies
<object><float64><float64><object><object><object><float64><object><object><object><object>
3Darth Vader202.0136.0nonewhiteyellow41.9malemasculineTatooineHuman
14Greedo173.074.0NaNgreenblack44.0malemasculineRodiaRodian
21IG-88200.0140.0nonemetalred15.0nonemasculineNaNDroid
22Bossk190.0113.0nonegreenred53.0malemasculineTrandoshaTrandoshan
24Lobot175.079.0nonelightblue37.0malemasculineBespinHuman
25Ackbar180.083.0nonebrown mottleorange41.0malemasculineMon CalaMon Calamari
29Nien Nunb160.068.0nonegreyblackNaNmalemasculineSullustSullustan
31Nute Gunray191.090.0nonemottled greenredNaNmalemasculineCato NeimoidiaNeimodian
33Jar Jar Binks196.066.0noneorangeorange52.0malemasculineNabooGungan
34Roos Tarpals224.082.0nonegreyorangeNaNmalemasculineNabooGungan
35Rugor Nass206.0NaNnonegreenorangeNaNmalemasculineNabooGungan
38Sebulba112.040.0nonegrey, redorangeNaNmalemasculineMalastareDug
41Darth Maul175.080.0noneredyellow54.0malemasculineDathomirZabrak
42Bib Fortuna180.0NaNnonepalepinkNaNmalemasculineRylothTwi'lek
43Ayla Secura178.055.0nonebluehazel48.0femalefeminineRylothTwi'lek
44Dud Bolt94.045.0noneblue, greyyellowNaNmalemasculineVulpterVulptereen
45Gasgano122.0NaNnonewhite, blueblackNaNmalemasculineTroikenXexto
46Ben Quadinaros163.065.0nonegrey, green, yelloworangeNaNmalemasculineTundToong
47Mace Windu188.084.0nonedarkbrown72.0malemasculineHaruun KalHuman
49Kit Fisto196.087.0nonegreenblackNaNmalemasculineGlee AnselmNautolan
51Adi Gallia184.050.0nonedarkblueNaNfemalefeminineCoruscantTholothian
52Saesee Tiin188.0NaNnonepaleorangeNaNmalemasculineIktotchIktotchi
53Yarael Poof264.0NaNnonewhiteyellowNaNmalemasculineQuermiaQuermian
54Plo Koon188.080.0noneorangeblack22.0malemasculineDorinKel Dor
55Mas Amedda196.0NaNnoneblueblueNaNmalemasculineChampalaChagrian
59Poggle the Lesser183.080.0nonegreenyellowNaNmalemasculineGeonosisGeonosian
67Dexter Jettster198.0102.0nonebrownyellowNaNmalemasculineOjomBesalisk
68Lama Su229.088.0nonegreyblackNaNmalemasculineKaminoKaminoan
69Taun We213.0NaNnonegreyblackNaNfemalefeminineKaminoKaminoan
71Ratts Tyerell79.015.0nonegrey, blueunknownNaNmalemasculineAleen MinorAleena
72R4-P1796.0NaNnonesilver, redred, blueNaNnonefeminineNaNDroid
73Wat Tambor193.048.0nonegreen, greyunknownNaNmalemasculineSkakoSkakoan
74San Hill191.0NaNnonegreygoldNaNmalemasculineMuunilinstMuun
75Shaak Ti178.057.0nonered, blue, whiteblackNaNfemalefeminineShiliTogruta
76Grievous216.0159.0nonebrown, whitegreen, yellowNaNmalemasculineKaleeKaleesh
79Sly Moore178.048.0nonepalewhiteNaNNaNNaNUmbaraNaN
80Tion Medon206.080.0nonegreyblackNaNmalemasculineUtapauPau'an
84BB8NaNNaNnonenoneblackNaNnonemasculineNaNDroid
\n", "
\n" ], "text/plain": [ " name height mass hair_color skin_color \\\n", " \n", "3 Darth Vader 202.0 136.0 none white \n", "14 Greedo 173.0 74.0 NaN green \n", "21 IG-88 200.0 140.0 none metal \n", "22 Bossk 190.0 113.0 none green \n", "24 Lobot 175.0 79.0 none light \n", "25 Ackbar 180.0 83.0 none brown mottle \n", "29 Nien Nunb 160.0 68.0 none grey \n", "31 Nute Gunray 191.0 90.0 none mottled green \n", "33 Jar Jar Binks 196.0 66.0 none orange \n", "34 Roos Tarpals 224.0 82.0 none grey \n", "35 Rugor Nass 206.0 NaN none green \n", "38 Sebulba 112.0 40.0 none grey, red \n", "41 Darth Maul 175.0 80.0 none red \n", "42 Bib Fortuna 180.0 NaN none pale \n", "43 Ayla Secura 178.0 55.0 none blue \n", "44 Dud Bolt 94.0 45.0 none blue, grey \n", "45 Gasgano 122.0 NaN none white, blue \n", "46 Ben Quadinaros 163.0 65.0 none grey, green, yellow \n", "47 Mace Windu 188.0 84.0 none dark \n", "49 Kit Fisto 196.0 87.0 none green \n", "51 Adi Gallia 184.0 50.0 none dark \n", "52 Saesee Tiin 188.0 NaN none pale \n", "53 Yarael Poof 264.0 NaN none white \n", "54 Plo Koon 188.0 80.0 none orange \n", "55 Mas Amedda 196.0 NaN none blue \n", "59 Poggle the Lesser 183.0 80.0 none green \n", "67 Dexter Jettster 198.0 102.0 none brown \n", "68 Lama Su 229.0 88.0 none grey \n", "69 Taun We 213.0 NaN none grey \n", "71 Ratts Tyerell 79.0 15.0 none grey, blue \n", "72 R4-P17 96.0 NaN none silver, red \n", "73 Wat Tambor 193.0 48.0 none green, grey \n", "74 San Hill 191.0 NaN none grey \n", "75 Shaak Ti 178.0 57.0 none red, blue, white \n", "76 Grievous 216.0 159.0 none brown, white \n", "79 Sly Moore 178.0 48.0 none pale \n", "80 Tion Medon 206.0 80.0 none grey \n", "84 BB8 NaN NaN none none \n", "\n", " eye_color birth_year sex gender homeworld \\\n", " \n", "3 yellow 41.9 male masculine Tatooine \n", "14 black 44.0 male masculine Rodia \n", "21 red 15.0 none masculine NaN \n", "22 red 53.0 male masculine Trandosha \n", "24 blue 37.0 male masculine Bespin \n", "25 orange 41.0 male masculine Mon Cala \n", "29 black NaN male masculine Sullust \n", "31 red NaN male masculine Cato Neimoidia \n", "33 orange 52.0 male masculine Naboo \n", "34 orange NaN male masculine Naboo \n", "35 orange NaN male masculine Naboo \n", "38 orange NaN male masculine Malastare \n", "41 yellow 54.0 male masculine Dathomir \n", "42 pink NaN male masculine Ryloth \n", "43 hazel 48.0 female feminine Ryloth \n", "44 yellow NaN male masculine Vulpter \n", "45 black NaN male masculine Troiken \n", "46 orange NaN male masculine Tund \n", "47 brown 72.0 male masculine Haruun Kal \n", "49 black NaN male masculine Glee Anselm \n", "51 blue NaN female feminine Coruscant \n", "52 orange NaN male masculine Iktotch \n", "53 yellow NaN male masculine Quermia \n", "54 black 22.0 male masculine Dorin \n", "55 blue NaN male masculine Champala \n", "59 yellow NaN male masculine Geonosis \n", "67 yellow NaN male masculine Ojom \n", "68 black NaN male masculine Kamino \n", "69 black NaN female feminine Kamino \n", "71 unknown NaN male masculine Aleen Minor \n", "72 red, blue NaN none feminine NaN \n", "73 unknown NaN male masculine Skako \n", "74 gold NaN male masculine Muunilinst \n", "75 black NaN female feminine Shili \n", "76 green, yellow NaN male masculine Kalee \n", "79 white NaN NaN NaN Umbara \n", "80 black NaN male masculine Utapau \n", "84 black NaN none masculine NaN \n", "\n", " species \n", " \n", "3 Human \n", "14 Rodian \n", "21 Droid \n", "22 Trandoshan \n", "24 Human \n", "25 Mon Calamari \n", "29 Sullustan \n", "31 Neimodian \n", "33 Gungan \n", "34 Gungan \n", "35 Gungan \n", "38 Dug \n", "41 Zabrak \n", "42 Twi'lek \n", "43 Twi'lek \n", "44 Vulptereen \n", "45 Xexto \n", "46 Toong \n", "47 Human \n", "49 Nautolan \n", "51 Tholothian \n", "52 Iktotchi \n", "53 Quermian \n", "54 Kel Dor \n", "55 Chagrian \n", "59 Geonosian \n", "67 Besalisk \n", "68 Kaminoan \n", "69 Kaminoan \n", "71 Aleena \n", "72 Droid \n", "73 Skakoan \n", "74 Muun \n", "75 Togruta \n", "76 Kaleesh \n", "79 NaN \n", "80 Pau'an \n", "84 Droid " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "filter(starwars, (f.hair_color == \"none\") | (f.eye_color == \"black\"))" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:20.363097Z", "iopub.status.busy": "2021-07-16T22:27:20.361695Z", "iopub.status.idle": "2021-07-16T22:27:20.394981Z", "shell.execute_reply": "2021-07-16T22:27:20.395470Z" } }, "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", "
nameheightmasshair_colorskin_coloreye_colorbirth_yearsexgenderhomeworldspecies
<object><float64><float64><object><object><object><float64><object><object><object><object>
29Nien Nunb160.068.0nonegreyblackNaNmalemasculineSullustSullustan
45Gasgano122.0NaNnonewhite, blueblackNaNmalemasculineTroikenXexto
49Kit Fisto196.087.0nonegreenblackNaNmalemasculineGlee AnselmNautolan
54Plo Koon188.080.0noneorangeblack22.0malemasculineDorinKel Dor
68Lama Su229.088.0nonegreyblackNaNmalemasculineKaminoKaminoan
69Taun We213.0NaNnonegreyblackNaNfemalefeminineKaminoKaminoan
75Shaak Ti178.057.0nonered, blue, whiteblackNaNfemalefeminineShiliTogruta
80Tion Medon206.080.0nonegreyblackNaNmalemasculineUtapauPau'an
84BB8NaNNaNnonenoneblackNaNnonemasculineNaNDroid
\n", "
\n" ], "text/plain": [ " name height mass hair_color skin_color eye_color \\\n", " \n", "29 Nien Nunb 160.0 68.0 none grey black \n", "45 Gasgano 122.0 NaN none white, blue black \n", "49 Kit Fisto 196.0 87.0 none green black \n", "54 Plo Koon 188.0 80.0 none orange black \n", "68 Lama Su 229.0 88.0 none grey black \n", "69 Taun We 213.0 NaN none grey black \n", "75 Shaak Ti 178.0 57.0 none red, blue, white black \n", "80 Tion Medon 206.0 80.0 none grey black \n", "84 BB8 NaN NaN none none black \n", "\n", " birth_year sex gender homeworld species \n", " \n", "29 NaN male masculine Sullust Sullustan \n", "45 NaN male masculine Troiken Xexto \n", "49 NaN male masculine Glee Anselm Nautolan \n", "54 22.0 male masculine Dorin Kel Dor \n", "68 NaN male masculine Kamino Kaminoan \n", "69 NaN female feminine Kamino Kaminoan \n", "75 NaN female feminine Shili Togruta \n", "80 NaN male masculine Utapau Pau'an \n", "84 NaN none masculine NaN Droid " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "filter(starwars, f.hair_color == \"none\", f.eye_color == \"black\")" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:20.432901Z", "iopub.status.busy": "2021-07-16T22:27:20.432240Z", "iopub.status.idle": "2021-07-16T22:27:20.444105Z", "shell.execute_reply": "2021-07-16T22:27:20.443126Z" } }, "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", "
nameheightmasshair_colorskin_coloreye_colorbirth_yearsexgenderhomeworldspecies
<object><float64><float64><object><object><object><float64><object><object><object><object>
3Darth Vader202.0136.0nonewhiteyellow41.9malemasculineTatooineHuman
5Owen Lars178.0120.0brown, greylightblue52.0malemasculineTatooineHuman
12Chewbacca228.0112.0brownunknownblue200.0malemasculineKashyyykWookiee
15Jabba Desilijic Tiure175.01358.0NaNgreen-tan, brownorange600.0hermaphroditicmasculineNal HuttaHutt
17Jek Tono Porkins180.0110.0brownfairblueNaNmalemasculineBestine IVHuman
21IG-88200.0140.0nonemetalred15.0nonemasculineNaNDroid
22Bossk190.0113.0nonegreenred53.0malemasculineTrandoshaTrandoshan
67Dexter Jettster198.0102.0nonebrownyellowNaNmalemasculineOjomBesalisk
76Grievous216.0159.0nonebrown, whitegreen, yellowNaNmalemasculineKaleeKaleesh
77Tarfful234.0136.0brownbrownblueNaNmalemasculineKashyyykWookiee
\n", "
\n" ], "text/plain": [ " name height mass hair_color skin_color \\\n", " \n", "3 Darth Vader 202.0 136.0 none white \n", "5 Owen Lars 178.0 120.0 brown, grey light \n", "12 Chewbacca 228.0 112.0 brown unknown \n", "15 Jabba Desilijic Tiure 175.0 1358.0 NaN green-tan, brown \n", "17 Jek Tono Porkins 180.0 110.0 brown fair \n", "21 IG-88 200.0 140.0 none metal \n", "22 Bossk 190.0 113.0 none green \n", "67 Dexter Jettster 198.0 102.0 none brown \n", "76 Grievous 216.0 159.0 none brown, white \n", "77 Tarfful 234.0 136.0 brown brown \n", "\n", " eye_color birth_year sex gender homeworld \\\n", " \n", "3 yellow 41.9 male masculine Tatooine \n", "5 blue 52.0 male masculine Tatooine \n", "12 blue 200.0 male masculine Kashyyyk \n", "15 orange 600.0 hermaphroditic masculine Nal Hutta \n", "17 blue NaN male masculine Bestine IV \n", "21 red 15.0 none masculine NaN \n", "22 red 53.0 male masculine Trandosha \n", "67 yellow NaN male masculine Ojom \n", "76 green, yellow NaN male masculine Kalee \n", "77 blue NaN male masculine Kashyyyk \n", "\n", " species \n", " \n", "3 Human \n", "5 Human \n", "12 Wookiee \n", "15 Hutt \n", "17 Human \n", "21 Droid \n", "22 Trandoshan \n", "67 Besalisk \n", "76 Kaleesh \n", "77 Wookiee " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> filter(f.mass > mean(f.mass))" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:20.551519Z", "iopub.status.busy": "2021-07-16T22:27:20.550906Z", "iopub.status.idle": "2021-07-16T22:27:20.612485Z", "shell.execute_reply": "2021-07-16T22:27:20.613028Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
nameheightmasshair_colorskin_coloreye_colorbirth_yearsexgenderhomeworldspecies
<object><float64><float64><object><object><object><float64><object><object><object><object>
0Darth Vader202.0136.0nonewhiteyellow41.9malemasculineTatooineHuman
1Owen Lars178.0120.0brown, greylightblue52.0malemasculineTatooineHuman
2Beru Whitesun lars165.075.0brownlightblue47.0femalefeminineTatooineHuman
3Chewbacca228.0112.0brownunknownblue200.0malemasculineKashyyykWookiee
4Jabba Desilijic Tiure175.01358.0NaNgreen-tan, brownorange600.0hermaphroditicmasculineNal HuttaHutt
5Jek Tono Porkins180.0110.0brownfairblueNaNmalemasculineBestine IVHuman
6IG-88200.0140.0nonemetalred15.0nonemasculineNaNDroid
7Bossk190.0113.0nonegreenred53.0malemasculineTrandoshaTrandoshan
8Ayla Secura178.055.0nonebluehazel48.0femalefeminineRylothTwi'lek
9Luminara Unduli170.056.2blackyellowblue58.0femalefeminineMirialMirialan
10Zam Wesell168.055.0blondefair, green, yellowyellowNaNfemalefeminineZolanClawdite
11Shaak Ti178.057.0nonered, blue, whiteblackNaNfemalefeminineShiliTogruta
12Grievous216.0159.0nonebrown, whitegreen, yellowNaNmalemasculineKaleeKaleesh
13Tarfful234.0136.0brownbrownblueNaNmalemasculineKashyyykWookiee
\n", "
\n", "

TibbleGrouped: gender (n=2)" ], "text/plain": [ " name height mass hair_color \\\n", " \n", "0 Darth Vader 202.0 136.0 none \n", "1 Owen Lars 178.0 120.0 brown, grey \n", "2 Beru Whitesun lars 165.0 75.0 brown \n", "3 Chewbacca 228.0 112.0 brown \n", "4 Jabba Desilijic Tiure 175.0 1358.0 NaN \n", "5 Jek Tono Porkins 180.0 110.0 brown \n", "6 IG-88 200.0 140.0 none \n", "7 Bossk 190.0 113.0 none \n", "8 Ayla Secura 178.0 55.0 none \n", "9 Luminara Unduli 170.0 56.2 black \n", "10 Zam Wesell 168.0 55.0 blonde \n", "11 Shaak Ti 178.0 57.0 none \n", "12 Grievous 216.0 159.0 none \n", "13 Tarfful 234.0 136.0 brown \n", "\n", " skin_color eye_color birth_year sex gender \\\n", " \n", "0 white yellow 41.9 male masculine \n", "1 light blue 52.0 male masculine \n", "2 light blue 47.0 female feminine \n", "3 unknown blue 200.0 male masculine \n", "4 green-tan, brown orange 600.0 hermaphroditic masculine \n", "5 fair blue NaN male masculine \n", "6 metal red 15.0 none masculine \n", "7 green red 53.0 male masculine \n", "8 blue hazel 48.0 female feminine \n", "9 yellow blue 58.0 female feminine \n", "10 fair, green, yellow yellow NaN female feminine \n", "11 red, blue, white black NaN female feminine \n", "12 brown, white green, yellow NaN male masculine \n", "13 brown blue NaN male masculine \n", "\n", " homeworld species \n", " \n", "0 Tatooine Human \n", "1 Tatooine Human \n", "2 Tatooine Human \n", "3 Kashyyyk Wookiee \n", "4 Nal Hutta Hutt \n", "5 Bestine IV Human \n", "6 NaN Droid \n", "7 Trandosha Trandoshan \n", "8 Ryloth Twi'lek \n", "9 Mirial Mirialan \n", "10 Zolan Clawdite \n", "11 Shili Togruta \n", "12 Kalee Kaleesh \n", "13 Kashyyyk Wookiee \n", "[TibbleGrouped: gender (n=2)]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> group_by(f.gender) >> filter(f.mass > mean(f.mass))" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:20.638518Z", "iopub.status.busy": "2021-07-16T22:27:20.622898Z", "iopub.status.idle": "2021-07-16T22:27:20.644143Z", "shell.execute_reply": "2021-07-16T22:27:20.643500Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
nameheightmasshair_colorskin_coloreye_colorbirth_yearsexgenderhomeworldspecies
<object><float64><float64><object><object><object><float64><object><object><object><object>
3Darth Vader202.0136.0nonewhiteyellow41.9malemasculineTatooineHuman
5Owen Lars178.0120.0brown, greylightblue52.0malemasculineTatooineHuman
8Biggs Darklighter183.084.0blacklightbrown24.0malemasculineTatooineHuman
10Anakin Skywalker188.084.0blondfairblue41.9malemasculineTatooineHuman
12Chewbacca228.0112.0brownunknownblue200.0malemasculineKashyyykWookiee
15Jabba Desilijic Tiure175.01358.0NaNgreen-tan, brownorange600.0hermaphroditicmasculineNal HuttaHutt
17Jek Tono Porkins180.0110.0brownfairblueNaNmalemasculineBestine IVHuman
21IG-88200.0140.0nonemetalred15.0nonemasculineNaNDroid
22Bossk190.0113.0nonegreenred53.0malemasculineTrandoshaTrandoshan
25Ackbar180.083.0nonebrown mottleorange41.0malemasculineMon CalaMon Calamari
30Qui-Gon Jinn193.089.0brownfairblue92.0malemasculineNaNHuman
31Nute Gunray191.090.0nonemottled greenredNaNmalemasculineCato NeimoidiaNeimodian
34Roos Tarpals224.082.0nonegreyorangeNaNmalemasculineNabooGungan
47Mace Windu188.084.0nonedarkbrown72.0malemasculineHaruun KalHuman
48Ki-Adi-Mundi198.082.0whitepaleyellow92.0malemasculineCereaCerean
49Kit Fisto196.087.0nonegreenblackNaNmalemasculineGlee AnselmNautolan
56Gregar Typho185.085.0blackdarkbrownNaNmalemasculineNabooHuman
67Dexter Jettster198.0102.0nonebrownyellowNaNmalemasculineOjomBesalisk
68Lama Su229.088.0nonegreyblackNaNmalemasculineKaminoKaminoan
76Grievous216.0159.0nonebrown, whitegreen, yellowNaNmalemasculineKaleeKaleesh
77Tarfful234.0136.0brownbrownblueNaNmalemasculineKashyyykWookiee
\n", "
\n" ], "text/plain": [ " name height mass hair_color skin_color \\\n", " \n", "3 Darth Vader 202.0 136.0 none white \n", "5 Owen Lars 178.0 120.0 brown, grey light \n", "8 Biggs Darklighter 183.0 84.0 black light \n", "10 Anakin Skywalker 188.0 84.0 blond fair \n", "12 Chewbacca 228.0 112.0 brown unknown \n", "15 Jabba Desilijic Tiure 175.0 1358.0 NaN green-tan, brown \n", "17 Jek Tono Porkins 180.0 110.0 brown fair \n", "21 IG-88 200.0 140.0 none metal \n", "22 Bossk 190.0 113.0 none green \n", "25 Ackbar 180.0 83.0 none brown mottle \n", "30 Qui-Gon Jinn 193.0 89.0 brown fair \n", "31 Nute Gunray 191.0 90.0 none mottled green \n", "34 Roos Tarpals 224.0 82.0 none grey \n", "47 Mace Windu 188.0 84.0 none dark \n", "48 Ki-Adi-Mundi 198.0 82.0 white pale \n", "49 Kit Fisto 196.0 87.0 none green \n", "56 Gregar Typho 185.0 85.0 black dark \n", "67 Dexter Jettster 198.0 102.0 none brown \n", "68 Lama Su 229.0 88.0 none grey \n", "76 Grievous 216.0 159.0 none brown, white \n", "77 Tarfful 234.0 136.0 brown brown \n", "\n", " eye_color birth_year sex gender homeworld \\\n", " \n", "3 yellow 41.9 male masculine Tatooine \n", "5 blue 52.0 male masculine Tatooine \n", "8 brown 24.0 male masculine Tatooine \n", "10 blue 41.9 male masculine Tatooine \n", "12 blue 200.0 male masculine Kashyyyk \n", "15 orange 600.0 hermaphroditic masculine Nal Hutta \n", "17 blue NaN male masculine Bestine IV \n", "21 red 15.0 none masculine NaN \n", "22 red 53.0 male masculine Trandosha \n", "25 orange 41.0 male masculine Mon Cala \n", "30 blue 92.0 male masculine NaN \n", "31 red NaN male masculine Cato Neimoidia \n", "34 orange NaN male masculine Naboo \n", "47 brown 72.0 male masculine Haruun Kal \n", "48 yellow 92.0 male masculine Cerea \n", "49 black NaN male masculine Glee Anselm \n", "56 brown NaN male masculine Naboo \n", "67 yellow NaN male masculine Ojom \n", "68 black NaN male masculine Kamino \n", "76 green, yellow NaN male masculine Kalee \n", "77 blue NaN male masculine Kashyyyk \n", "\n", " species \n", " \n", "3 Human \n", "5 Human \n", "8 Human \n", "10 Human \n", "12 Wookiee \n", "15 Hutt \n", "17 Human \n", "21 Droid \n", "22 Trandoshan \n", "25 Mon Calamari \n", "30 Human \n", "31 Neimodian \n", "34 Gungan \n", "47 Human \n", "48 Cerean \n", "49 Nautolan \n", "56 Human \n", "67 Besalisk \n", "68 Kaminoan \n", "76 Kaleesh \n", "77 Wookiee " ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# To refer to column names that are stored as strings, use `f[...]`:\n", "vars = c(\"mass\", \"height\")\n", "cond = c(80, 150)\n", "starwars >> \\\n", " filter(\n", " f[vars[0]] > cond[0],\n", " f[vars[1]] > cond[1]\n", " )" ] } ], "metadata": { "kernelspec": { "display_name": "datar-TA_GutPO-py3.12", "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.12.2" } }, "nbformat": 4, "nbformat_minor": 2 } ================================================ FILE: docs/notebooks/forcats_fct_multi.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_c
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Concatenate factors, combining levels\n", "\n", "This is a useful ways of patching together factors from multiple sources \n", "that really should have the same levels but don't. \n", "\n", "##### Args:\n", "  `*fs`: factors to concatenate \n", "\n", "##### Returns:\n", "  The concatenated factor \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_cross
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Combine levels from two or more factors to create a new factor\n", "\n", "Computes a factor whose levels are all the combinations of \n", "the levels of the input factors. \n", "\n", "##### Args:\n", "  `*fs`: factors to cross \n", "  `sep`: A string to separate levels \n", "  `keep_empty`: If True, keep combinations with no observations as levels \n", "\n", "##### Returns:\n", "  The new factor \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%run nb_helpers.py\n", "from datar.all import *\n", "\n", "nb_header(\n", " fct_c,\n", " fct_cross,\n", " book=\"forcat_fct_multi\",\n", ")\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## fct_c" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "fa = factor(\"a\")\n", "fb = factor(\"b\")\n", "fab = factor(c(\"a\", \"b\"))\n", "\n", "# c(fa, fb, fab)\n", "# convert factor to integer for `c`?" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a', 'b', 'a', 'b']\n", "Categories (2, object): ['a', 'b']" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_c(fa, fb, fab)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a', 'b', 'a', 'b']\n", "Categories (2, object): ['a', 'b']" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fs = [fa, fb, fab]\n", "fct_c(*fs)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## fct_cross" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['apple:green', 'kiwi:green', 'apple:red', 'apple:green']\n", "Categories (3, object): ['apple:green', 'apple:red', 'kiwi:green']" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fruit = factor(c(\"apple\", \"kiwi\", \"apple\", \"apple\"))\n", "colour = factor(c(\"green\", \"green\", \"red\", \"green\"))\n", "eaten = c(\"yes\", \"no\", \"yes\", \"no\")\n", "fct_cross(fruit, colour)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['apple:green:yes', 'kiwi:green:no', 'apple:red:yes', 'apple:green:no']\n", "Categories (4, object): ['apple:green:no', 'apple:green:yes', 'apple:red:yes', 'kiwi:green:no']" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_cross(fruit, colour, eaten)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['apple:green', 'kiwi:green', 'apple:red', 'apple:green']\n", "Categories (4, object): ['apple:green', 'apple:red', 'kiwi:green', 'kiwi:red']" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_cross(fruit, colour, keep_empty = TRUE)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 2 } ================================================ FILE: docs/notebooks/forcats_lvl_addrm.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_expand
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Add additional levels to a factor\n", "\n", "##### Args:\n", "  `_f`: A factor \n", "  `*additional_levels`: Additional levels to add to the factor. \n", "    Levels that already exist will be silently ignored. \n", "\n", "##### Returns:\n", "  The factor with levels expanded \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_explicit_na
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Make missing values explicit\n", "\n", "This gives missing values an explicit factor level, ensuring that they \n", "appear in summaries and on plots. \n", "\n", "##### Args:\n", "  `_f`: A factor \n", "  `na_level`: Level to use for missing values. \n", "    This is what NAs will be changed to. \n", "\n", "##### Returns:\n", "  The factor with explict na_levels \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_drop
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Drop unused levels\n", "\n", "##### Args:\n", "  `_f`: A factor \n", "  `only`: A character vector restricting the set of levels to be dropped. \n", "    If supplied, only levels that have no entries and appear in \n", "    this vector will be removed. \n", "\n", "##### Returns:\n", "  The factor with unused levels dropped \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_unify
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Unify the levels in a list of factors\n", "\n", "##### Args:\n", "  `fs`: A list of factors \n", "  `levels`: Set of levels to apply to every factor. Default to union \n", "    of all factor levels \n", "\n", "##### Returns:\n", "  A list of factors with the levels expanded \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%run nb_helpers.py\n", "from datar.all import *\n", "\n", "nb_header(\n", " fct_expand,\n", " fct_explicit_na,\n", " fct_drop,\n", " fct_unify,\n", " book=\"forcat_lvl_addrm\",\n", ")\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## fct_expand" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['c', 'c', 'b', 'c', 'a', ..., 'b', 'c', 'b', 'b', 'c']\n", "Length: 20\n", "Categories (3, object): ['a', 'b', 'c']" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct = factor(sample(letters[:3], 20, replace = TRUE))\n", "fct" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['c', 'c', 'b', 'c', 'a', ..., 'b', 'c', 'b', 'b', 'c']\n", "Length: 20\n", "Categories (6, object): ['a', 'b', 'c', 'd', 'e', 'f']" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_expand(fct, \"d\", \"e\", \"f\")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['c', 'c', 'b', 'c', 'a', ..., 'b', 'c', 'b', 'b', 'c']\n", "Length: 20\n", "Categories (6, object): ['a', 'b', 'c', 'd', 'e', 'f']" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_expand(fct, letters[:6])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## fct_explicit_na" ] }, { "cell_type": "code", "execution_count": 5, "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", "
fn
<category><float64>
0a4.0
1b2.0
2c2.0
3NaN3.0
\n", "
\n" ], "text/plain": [ " f n\n", " \n", "0 a 4.0\n", "1 b 2.0\n", "2 c 2.0\n", "3 NaN 3.0" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f1 = factor(c(\"a\", \"a\", NA, NA, \"a\", \"b\", NA, \"c\", \"a\", \"c\", \"b\"))\n", "fct_count(f1)" ] }, { "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", "
fn
<category><int64>
0a4
1b2
2c2
3(Missing)3
\n", "
\n" ], "text/plain": [ " f n\n", " \n", "0 a 4\n", "1 b 2\n", "2 c 2\n", "3 (Missing) 3" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f2 = fct_explicit_na(f1)\n", "fct_count(f2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## fct_drop" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a', 'b']\n", "Categories (3, object): ['a', 'b', 'c']" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct = factor(c(\"a\", \"b\"), levels = c(\"a\", \"b\", \"c\"))\n", "fct" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a', 'b']\n", "Categories (2, object): ['a', 'b']" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_drop(fct)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a', 'b']\n", "Categories (3, object): ['a', 'b', 'c']" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_drop(fct, only = \"a\")" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a', 'b']\n", "Categories (2, object): ['a', 'b']" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_drop(fct, only = \"c\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## fct_unify" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[['a']\n", " Categories (2, object): ['a', 'b'],\n", " ['b']\n", " Categories (2, object): ['a', 'b'],\n", " ['a', 'b']\n", " Categories (2, object): ['a', 'b']]" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fs = [factor(\"a\"), factor(\"b\"), factor(c(\"a\", \"b\"))]\n", "fct_unify(fs)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 2 } ================================================ FILE: docs/notebooks/forcats_lvl_order.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_relevel
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Reorder factor levels by hand\n", "\n", "##### Args:\n", "  `_f`: A factor (categoriccal), or a string vector \n", "  `*lvls`: Either a function (then `len(lvls)` should equal to `1`) or \n", "    the new levels. \n", "    A function will be called with the current levels as input, and the \n", "    return value (which must be a character vector) will be used to \n", "    relevel the factor. \n", "    Any levels not mentioned will be left in their existing order, \n", "    by default after the explicitly mentioned levels. \n", "\n", "  `after`: Where should the new values be placed? \n", "\n", "##### Returns:\n", "  The factor with levels replaced \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_inorder
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Reorder factor levels by first appearance\n", "\n", "##### Args:\n", "  `_f`: A factor \n", "  `ordered`: A logical which determines the \"ordered\" status of the \n", "    output factor. \n", "\n", "##### Returns:\n", "  The factor with levels reordered \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_infreq
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Reorder factor levels by frequency\n", "\n", "##### Args:\n", "  `_f`: A factor \n", "  `ordered`: A logical which determines the \"ordered\" status of the \n", "    output factor. \n", "\n", "##### Returns:\n", "  The factor with levels reordered \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_inseq
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Reorder factor levels by sequence\n", "\n", "##### Args:\n", "  `_f`: A factor \n", "  `ordered`: A logical which determines the \"ordered\" status of the \n", "    output factor. \n", "\n", "##### Returns:\n", "  The factor with levels reordered \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_reorder
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Reorder factor levels by a function (default: median)\n", "\n", "##### Args:\n", "  `_f`: A factor \n", "  `_x`: The data to be used to reorder the factor \n", "  `_fun`: A function to be used to reorder the factor \n", "  `_desc`: If `True`, the factor will be reordered in descending order \n", "  `*args`: Extra arguments to be passed to `_fun` \n", "  `**kwargs`: Extra keyword arguments to be passed to `_fun` \n", "\n", "##### Returns:\n", "  The factor with levels reordered \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_reorder2
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Reorder factor levels by a function (default: `last2`)\n", "\n", "##### Args:\n", "  `_f`: A factor \n", "  `_x`: The data to be used to reorder the factor \n", "  `_fun`: A function to be used to reorder the factor \n", "  `_desc`: If `True`, the factor will be reordered in descending order \n", "  `*args`: Extra arguments to be passed to `_fun` \n", "  `**kwargs`: Extra keyword arguments to be passed to `_fun` \n", "\n", "##### Returns:\n", "  The factor with levels reordered \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_rev
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Reverse the order of the levels of a factor\n", "\n", "##### Args:\n", "  `_f`: A factor \n", "\n", "##### Returns:\n", "  The factor with levels reversed \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_shift
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Shift the levels of a factor\n", "\n", "##### Args:\n", "  `_f`: A factor \n", "  `n`: The number of levels to shift \n", "\n", "##### Returns:\n", "  The factor with levels shifted \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_shuffle
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Shuffle the levels of a factor\n", "\n", "##### Args:\n", "  `_f`: A factor \n", "\n", "##### Returns:\n", "  The factor with levels shuffled \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ first2
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Find the first element of `_y` ordered by `_x`\n", "\n", "##### Args:\n", "  `_x`: The vector used to order `_y` \n", "  `_y`: The vector to get the first element of \n", "\n", "##### Returns:\n", "  First element of `_y` ordered by `_x` \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ last2
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Find the last element of `_y` ordered by `_x`\n", "\n", "##### Args:\n", "  `_x`: The vector used to order `_y` \n", "  `_y`: The vector to get the last element of \n", "\n", "##### Returns:\n", "  Last element of `_y` ordered by `_x` \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%run nb_helpers.py\n", "\n", "import plotnine as p9\n", "from datar.all import *\n", "from datar.data import gss_cat, iris, ChickWeight\n", "\n", "nb_header(\n", " fct_relevel,\n", " fct_inorder,\n", " fct_infreq,\n", " fct_inseq,\n", " fct_reorder,\n", " fct_reorder2,\n", " fct_rev,\n", " fct_shift,\n", " fct_shuffle,\n", " first2,\n", " last2, \n", " book=\"forcat_lvl_order\",\n", ")\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## fct_relevel" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a', 'b', 'c', 'd']\n", "Categories (4, object): ['b', 'c', 'd', 'a']" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct = factor(c(\"a\", \"b\", \"c\", \"d\"), levels = c(\"b\", \"c\", \"d\", \"a\"))\n", "fct_relevel(fct)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a', 'b', 'c', 'd']\n", "Categories (4, object): ['a', 'b', 'c', 'd']" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_relevel(fct, \"a\")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a', 'b', 'c', 'd']\n", "Categories (4, object): ['b', 'a', 'c', 'd']" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_relevel(fct, \"b\", \"a\")" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a', 'b', 'c', 'd']\n", "Categories (4, object): ['b', 'c', 'a', 'd']" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_relevel(fct, \"a\", after=1)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a', 'b', 'c', 'd']\n", "Categories (4, object): ['a', 'b', 'c', 'd']" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# use -1 instead of Inf\n", "fct_relevel(fct, \"a\", after = None)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a', 'b', 'c', 'd']\n", "Categories (4, object): ['b', 'c', 'd', 'a']" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_relevel(fct, \"a\", after = 2)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a', 'b', 'c', 'd']\n", "Categories (4, object): ['a', 'b', 'c', 'd']" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_relevel(fct, sort)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a', 'b', 'c', 'd']\n", "Categories (4, object): ['b', 'd', 'a', 'c']" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_relevel(fct, sample)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a', 'b', 'c', 'd']\n", "Categories (4, object): ['a', 'd', 'c', 'b']" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_relevel(fct, rev)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'rincome': ['$1000 to 2999',\n", " '$10000 - 14999',\n", " '$15000 - 19999',\n", " '$20000 - 24999',\n", " '$25000 or more',\n", " '$3000 to 3999',\n", " '$4000 to 4999',\n", " '$5000 to 5999',\n", " '$6000 to 6999',\n", " '$7000 to 7999',\n", " '$8000 to 9999',\n", " \"Don't know\",\n", " 'Lt $1000',\n", " 'No answer',\n", " 'Not applicable',\n", " 'Refused'],\n", " 'denom': ['Afr meth ep zion',\n", " 'Afr meth episcopal',\n", " 'Am bapt ch in usa',\n", " 'Am baptist asso',\n", " 'Am lutheran',\n", " 'Baptist-dk which',\n", " \"Don't know\",\n", " 'Episcopal',\n", " 'Evangelical luth',\n", " 'Luth ch in america',\n", " 'Lutheran-dk which',\n", " 'Lutheran-mo synod',\n", " 'Methodist-dk which',\n", " 'Nat bapt conv of am',\n", " 'Nat bapt conv usa',\n", " 'No answer',\n", " 'No denomination',\n", " 'Not applicable',\n", " 'Other',\n", " 'Other baptists',\n", " 'Other lutheran',\n", " 'Other methodist',\n", " 'Other presbyterian',\n", " 'Presbyterian c in us',\n", " 'Presbyterian, merged',\n", " 'Presbyterian-dk wh',\n", " 'Southern baptist',\n", " 'United methodist',\n", " 'United pres ch in us',\n", " 'Wi evan luth synod']}" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = gss_cat[[\"rincome\", \"denom\"]] >> mutate(across(everything(), as_factor)) \n", "\n", "(\n", " df \n", " >> summarize(across(everything(), lambda col: [levels(col).tolist()]))\n", " >> t()\n", " >> rename_with(str)\n", " >> pull(to=\"dict\", name=rownames(f))\n", ") " ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'rincome': ['$1000 to 2999',\n", " '$10000 - 14999',\n", " '$15000 - 19999',\n", " '$20000 - 24999',\n", " '$25000 or more',\n", " '$3000 to 3999',\n", " '$4000 to 4999',\n", " '$5000 to 5999',\n", " '$6000 to 6999',\n", " '$7000 to 7999',\n", " '$8000 to 9999',\n", " 'Lt $1000',\n", " 'No answer',\n", " 'Not applicable',\n", " 'Refused',\n", " \"Don't know\"],\n", " 'denom': ['Afr meth ep zion',\n", " 'Afr meth episcopal',\n", " 'Am bapt ch in usa',\n", " 'Am baptist asso',\n", " 'Am lutheran',\n", " 'Baptist-dk which',\n", " 'Episcopal',\n", " 'Evangelical luth',\n", " 'Luth ch in america',\n", " 'Lutheran-dk which',\n", " 'Lutheran-mo synod',\n", " 'Methodist-dk which',\n", " 'Nat bapt conv of am',\n", " 'Nat bapt conv usa',\n", " 'No answer',\n", " 'No denomination',\n", " 'Not applicable',\n", " 'Other',\n", " 'Other baptists',\n", " 'Other lutheran',\n", " 'Other methodist',\n", " 'Other presbyterian',\n", " 'Presbyterian c in us',\n", " 'Presbyterian, merged',\n", " 'Presbyterian-dk wh',\n", " 'Southern baptist',\n", " 'United methodist',\n", " 'United pres ch in us',\n", " 'Wi evan luth synod',\n", " \"Don't know\"]}" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df2 = df >> mutate(across(everything(), fct_relevel, \"Don't know\", after=-1))\n", "(\n", " df2 \n", " >> summarize(across(everything(), lambda col: [levels(col).tolist()]))\n", " >> t()\n", " >> rename_with(str)\n", " >> pull(to=\"dict\", name=rownames(f))\n", ") " ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 14:00:07][datar][WARNING] [fct_relevel] Unknown levels in `_f`: ['e']\n" ] }, { "data": { "text/plain": [ "['a', 'b', 'c', 'd']\n", "Categories (4, object): ['b', 'c', 'd', 'a']" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_relevel(fct, \"e\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## fct_inorder, fct_infreq, and fct_inseq" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['b', 'b', 'a', 'c', 'c', 'c']\n", "Categories (3, object): ['a', 'b', 'c']" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct = factor(c(\"b\", \"b\", \"a\", \"c\", \"c\", \"c\"))\n", "fct" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['b', 'b', 'a', 'c', 'c', 'c']\n", "Categories (3, object): ['b', 'a', 'c']" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_inorder(fct)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['b', 'b', 'a', 'c', 'c', 'c']\n", "Categories (3, object): ['c', 'b', 'a']" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_infreq(fct)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 2, 3]\n", "Categories (3, int64): [1, 2, 3]" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct = factor([1,2,3], levels = [3,2,1])\n", "fct_inseq(fct)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## fct_reorder, fct_reorder2, last2, and first2" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['blue', 'green', 'purple', 'red', 'yellow']\n", "Categories (5, object): ['blue', 'red', 'purple', 'yellow', 'green']" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tribble(\n", " f.color, f.a, f.b,\n", " \"blue\", 1, 2,\n", " \"green\", 6, 2,\n", " \"purple\", 3, 3,\n", " \"red\", 2, 3,\n", " \"yellow\", 5, 1\n", ") >> mutate(color=as_factor(f.color))\n", "\n", "fct_reorder(df.color, df.a, _fun=min)" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['blue', 'green', 'purple', 'red', 'yellow']\n", "Categories (5, object): ['red', 'purple', 'green', 'blue', 'yellow']" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_reorder2(df.color, df.a, df.b)" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjQAAAGyCAYAAADzil5bAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaH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XVVVVioqK0vTp09WrVy+9+OKLOnz4sGbNmiVJ+ve//601a9bowIEDCgwM1Lhx43THHXfIMAy98sor2rp1q8rKypSUlKSpU6eqQ4cOdbJXV1fr97//vd5//33V1NRowIABysjIUEhIiCQpNTVVU6dO1ZYtW3TixAlt3LixZT5UNMi55l5ERIQiIyN1zz336F//+pcef/xx3XbbbXr11VfVpUsXzZ8/Xy+88ILeeustOZ1OjR8/Xk8//bRWr16tjh07atmyZXWen5aWppdfflkej0e33HKLbr31Vklq8Nw8evSoVqxYof3790uS+vbtq2nTpik0NLTlP7zWwADOkJOTY9x2221GTk6OYRiGceLECePAgQPG3//+d+O+++4z9u/fb9TU1Bivv/66cf/99xtVVVWGYRjGfffdZ3z22Wfe1ykpKTHGjx9vbN261aipqTF27Nhh3H777cbBgwcNwzCMBx980HjppZcMt9ttVFZWGrt37/Y+d9u2bUZRUZFRU1Nj/PGPfzQmTJhgVFRUtOCngKY4fvy4ccsttxgnT5703veTn/zEeO+994xnn33WmDdvnlFYWGhUVFQYS5cuNZ544gnDMAzj6NGjxrhx44zHHnvMKC0tNSoqKozPP//cuPfee40TJ04YhmEYubm5Rm5urmEYhvGHP/zBeOyxx7zveeeddxpvv/22UVVVZZSWlhp79+41DMMw3n77beO+++4zcnJyjIqKCuN3v/udMXv2bG+2M+fuH/7wB2PGjBlGfn6+cerUKeORRx7x5jMMwxg3bpwxZ84cb374l3PNvaVLlxrr1q0zDMMwvvzyS+Omm24ynnnmGaOystKoqKgwtm7davzoRz8yjh49apSVlRm//vWvjXHjxhlHjx41DMOo9/lr1qwxqqqqjK+//tq45ZZbjMOHDxuG0fC5mZuba+zYscOoqqoyioqKjDlz5hhZWVkt9nm1NmxyQi0Oh0OSdPDgQVVWVioqKkoXX3yxXn/9dd16663q2rWrHA6Hrr32WtlsNn399df1vs6nn36qmJgYXXPNNXI4HOrXr58GDhyov/3tb5KkgIAA5eXlqaCgQE6nU0lJSd7njhgxQuHh4XI4HLrppptUU1OjnJyc5v/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ZPdbtd1112nTZs2af/+/TIMQ+Xl5frHP/6hsrIySVL79u119OhR7+tcccUVysvL01tvvSW3262dO3fqH//4h4YPHy5Jevfdd3Xy5EnZbDbvDpd2u13l5eWy2+0KDw+X2+3Wxo0bVV5e3vIfBJokODhYV155pVatWiW3263evXvLbrfr2muv1XPPPaeCggJJ0smTJ/XJJ5+c9XX27dunvXv3qrq6Wi6XSy6XS3Z73a+t4cOHa/fu3dq2bZtqampUVlbm3Rw6fPhw/fnPf9bhw4dVVVWl9evXq3v37vX+r3nEiBHauHGjCgoKVFZWpvXr1yslJaXW/8Th3+qbew0xbNgw/fWvf1VeXp7Ky8v10ksv+STPueZmeXm52rVrp5CQEJ04cUJ//OMfffKebRVraFDL6aM8cnJyZLfbdckll2j69Onq1KmTKisrtWzZMh07dkwul0tJSUneo49uv/12rV69Wr///e91ww03aMKECZo/f76effZZPffcc4qOjtYDDzygzp07S5J27typtWvXqrKyUpGRkZo6dari4uIUExOjK664QtOnT1e7du2Umpp63lW/8E8jRozQ4sWLddNNN3n3zbrnnnv08ssv65e//KWKiooUERGhYcOGnXUfh7KyMj333HM6duyYAgIC1KNHD/3v//5vnXExMTFasGCB1q5dq2eeeUZOp1OpqalKTEzUqFGjVFhYqPnz53uPcvr+Zq/T7rjjDpWXl2vmzJlyu93q37+/MjIyfPehoEXUN/fOZ8yYMcrNzdXMmTPldDqVlpamDz/8sMll9lxzc/z48Vq6dKnGjx+v+Ph4jRgxQq+++mqT3q8t48R6AAB8z7fffqtZs2Zp06ZN9a4VhP/hpwQAaPOqq6v1j3/8Q263W0VFRXr++ec1aNAgyoyFsIYGANDmVVdXa86cOcrJyVFAQIB69eqlqVOn1tohHP6NQgMAACyPdWkAAMDyKDQAAMDyKDQAAMDyKDQAAMDyKDQAAMDyKDQAGuUPf/iDBg4cqIiICIWHh6tHjx66//77a103qSV99913stls2rRpkynvD8BcFBoAF+yxxx7TxIkTNWzYML300kt66aWXlJ6ers8++0xHjhwxJVN8fLw+/vhjjR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7j3bp1kyRFRERo2bJlWrZsmf71r39p+fLlmj59upKTkzVs2LAGvx8Ac7HJCcAFO3bsWJ37ysvLlZOTU2cH4W3btqmoqMi7/O6776qgoECDBg2SJF199dU6fvy4nE6nrrjiijq/nE6nQkJCNHjwYD3//PO1jlA6l8GDBys4OFiHDh2q93U7dOhQ5zm9evXS0qVLJalOMQPg31hDA+CC9erVS+PGjdM111yj+Ph4HT58WCtWrFB+fr5mzJhRa2xYWJiuu+46/fKXv9TJkyf1i1/8QgMHDtQ111wjSRozZozGjRuna6+9VrNnz1bv3r1VWlqq3bt365tvvtGzzz4rSVqyZIlGjRqlq6++WtOnT1dkZKR27Nih6Ohopaen18nYvn17LVy4ULNnz9ahQ4c0YsQIORwO/ec//9Gf/vQnbd68WcHBwRo6dKhuueUWJScny+Fw6Pnnn5fT6WTtDGAxFBoAF2zBggXasmWLZs6cqePHjys6Olq9e/fWO++8o5EjR9Yae8stt6hTp06aOnWqCgsLNWbMGK1atarWmE2bNmnJkiVauXKlDhw4oIiICCUnJ+vee+/1jklJSdF7772nhx56SJMnT5bD4VDPnj21aNGis+Z84IEHdNFFF+m3v/2tnn76aQUGBurSSy/VjTfeKKfTKUkaOnSonn/+ee3fv192u129evXSli1b1KNHDx9+YgCaG2cKBtBsunbtqhtvvFErVqwwOwqAVo59aAAAgOVRaAAAgOWxyQkAAFgea2gAAIDlUWgAAIDlUWgAAIDlUWgAAIDlUWgAAIDlUWgAAIDlUWgAAIDlUWgAAIDlUWgAAIDl/T+4izyGILPpsAAAAABJRU5ErkJggg==", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p9.ggplot(iris) + p9.geom_boxplot(\n", " p9.aes(x=\"Species\", y=\"Sepal_Width\")\n", ")" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjQ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BwOh7+RZWZmas6cOerVq5eOHj2q3NxcFRYWyul06sILL1ROTo4iIyPNig8AAExmM9rQcWcctt2yTpTS4uJi/ieDZsVcQ0thrpmjIYdtc+kDAABgeRQaAABgeRQaAABgeRQaAABgeRQaAABgeRQaAABgeUFxHhoAAIJZSUmJcnNz9c033yg+Pl533XWX+vbta3YsnIQ1NAAAnEFVVZUeeOABffTRRzp48KB27NihmTNnavv27WZHw0koNAAAnMG2bdu0f/9+1dTUSJIMw5BhGFq/fr3JyXAyCg0AAGdQUVEhh8NR6z7DMHTs2DGTEqE+FBoAAM4gJSVFPp+v1n0hISG65JJLzAmEelFoAAA4g+TkZD344IMKCQmRzWaTJF1++eW64447TE6Gk3GUEwAAZzF8+HD16dNH+/btU5cuXdShQ4c6a21gLgoNAAANEBcXp44dO/qvto3gwiYnAABgeRQaAABgeRQaAABgeRQaAABgeRQaAABgeRQaAABgeRQaAABgeRQaAABgeRQaAABgeRQaAABgeRQaAABgeRQaAABgeRQaAABgeRQaAABgeRQaAABgeRQaAABgeSFmB2hJTqdTLpfL7Bhths1mkyRFRETIMAyT06A1Y66hpTDXglebKjQej0cej8fsGG2Gw+GQ0+lUeXm5vF6v2XHQijHX0FKYa+ZoyMoINjkBAADLo9AAAADLo9AAAADLo9AAAADLo9AAAADLo9AAANBA5eXlysvLU3l5udlRcAoKDQAADVReXq4VK1ZQaIIQhQYAAFgehQYAAFgehQYAAFgehQYAAFgehQYAAFgehQYAAFgehQYAAFgehQYAAFgehQYAAFgehQYAAFgehQYAAFgehQYAAFgehQYAAFgehQYAAFgehQYAAFgehQYAAFgehQYAAFgehQYAAFgehQYAAFgehQYAAFgehQYAAFie5QtNaWmp7rzzTj3wwANmRwEAACaxfKFZtWqVunTpYnYMAABgIksXmu3bt+vAgQO68sorzY4CAABMZNlCU11drby8PE2ePFk2m83sOAAAwEQhZgdorA0bNqhv377q3r27/vvf/9Y7xu12y+12+5ddLpeSk5NbKmKb53A4at0CzYW5hpZit9v9t8y34GLJQ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oYqOztbSUlJioyMNDsO2oDo6GizI6CNYK4FH5thGIbZIRrDMAwtX75c3333nR555BGFh4fXGcMaGnM5HA5FR0ertLRUXq/X7DhoxZhraCnMNXPExsaedYxl19Dk5eXp22+/1fz58+stM5KUlJSkpKQk/3JhYSET0ARer5fPHS2CuYaWwlwLPpYsNAUFBXr99dcVGhqqrKws//233nqrMjMzTUwGAADMYMlCk5CQoL/85S9mxwAAAEGiVRy2DQAA2jYKDQAAsDwKDQAAsDwKDQAAsDwKDQAAsDwKDQAAsDwKDQAAsDwKDQAAsDwKDQAAsDwKDQAAsDwKDQAAsDwKDQAAsDybYRiG2SHQOrndbuXl5WnSpElKSkoyOw5aMeYaWgpzLXixhgbNxu12KycnR2632+woaOWYa2gpzLXgRaEBAACWR6EBAACWR6FBs0lKStKcOXPYzoxmx1xDS2GuBS92CgYAAJbHGhoAAGB5FBoE1Lp167R48eImv859992nL774oumBENSWLVuml156qUWeH6i5CSA4sckJQem+++7TlClTNGDAALOjAGij+DlkLayhwTnxer1mRzijYM+HhuO7BHAuQswOgJaxYcMG7dixQ7Nnz6513/bt2zVr1iytXbtWH3zwgSorK9WvXz9NnjxZkZGROnTokLKzszVt2jStXbtWLpdLS5cu1erVq/Xee+/J4/EoLi5OU6dOVe/evfXSSy9p//79evDBByVJ//nPf7Ry5Urt2bNHoaGhGjt2rG677TYZhqFXX31VmzZtUkVFhVJTUzV58mR16NChTvbq6mq9+OKL+uCDD1RTU6MBAwYoOztbERERkqSMjAxNnjxZGzdu1JEjR7Ru3bqW+VDRIGeaezExMYqNjdXdd9+tf//733r88cd1yy236LXXXlPXrl01Z84cvfDCC3r77bfldDo1btw4Pf3001qxYoU6deqkxYsX13l+ZmamXnnlFfl8Pt100026+eabJanBc/PgwYNaunSpdu/eLUm65JJLNGXKFEVGRrb8h4eAee2117Rx40aVl5crOjpad911l/7f//t/2rx5szZs2KAjR46oa9eumjp1qs4//3w9/vjjOnz4sH7729/Kbrdr7Nixuuuuu/Sf//xHK1asUH5+vjp27KgJEybosssukyTt2rVLeXl5ys/PV2hoqPr166f7779fkvTcc89py5YtKi8vV1JSku677z6lpaWZ+ZG0PgbahMOHDxs33XSTcfToUf99P/vZz4z333/fePbZZ43Zs2cbxcXFxvHjx41FixYZTzzxhGEYhnHw4EFj7NixxmOPPWaUl5cbx48fN7744gvjnnvuMY4cOWIYhmG43W7D7XYbhmEYf/zjH43HHnvM/56333678c477xgej8coLy83vvnmG8MwDOOdd94x7r33XiM/P984fvy48Yc//MGYMWOGP9u9995rfP755/7XnDZtmlFYWGgcO3bMeOSRR/z5DMMwxo4da8ycOdOfH8HlTHNv0aJFxurVqw3DMIyvvvrKuOGGG4xnnnnGqKqqMo4fP25s2rTJ+MlPfmIcPHjQqKioMH77298aY8eONQ4ePGgYhlHv81euXGl4PB7j22+/NW666SZj//79hmE0fG663W5j69athsfjMUpKSoyZM2caubm5LfZ5IfDy8/ONW265xcjPzzcMwzCOHDli7Nmzx/jHP/5h3Hvvvcbu3buNmpoa44033jDuu+8+w+PxGIZR++eQYRhGWVmZMW7cOGPTpk1GTU2NsXXrVuPWW2819u7daxiGYTzwwAPGyy+/bHi9XqOqqsrYsWOH/7mbN282SkpKjJqaGuNPf/qTMX78eH5eBRibnNqI+Ph49ezZUx999JEkac+ePTp06JAGDhyoTZs26b777lP79u3lcrl05513asuWLbVW+Y8bN07h4eFyuVwKCQmRx+PR3r17VVNTo8TERCUmJtZ5z/fff1+pqakaNWqUQkNDFR4erpSUFP9jGRkZ6ty5s1wul+655x795z//qfd04u+//77uuOMOdejQQREREZo4caI+/PBDVVdX+8fccsst/vwILqebe1dccUW94ydMmCCn0ymXy6UPPvhAY8eOVadOnRQWFqZx48ad8b3sdrvGjx+v0NBQXXTRRTrvvPP8a1pOdqa5mZiYqH79+ik0NFTR0dHKyMjQjh07mvgpwEwOh0OStHfvXlVVVSkuLk7nn3++3njjDd18883q1q2bHA6Hrr76atlsNn377bf1vs5nn32mjh076qqrrpLD4VC/fv10+eWX6+9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9Otf/1pHjx7Vr371K11++eW66qqrJEmjR4/W2LFjdfXVV2vGjBnq06ePysvLtWPHDn333Xd69tlnJUkLFy7UyJEjdeWVV2rq1KmKjY3V1q1bFR8fr6ysrDoZ27dvr3nz5mnGjBnat2+fhg8fLofDof/+97/685//rA0bNig8PFxDhgzRTTfdpLS0NDkcDj3//PNyOp2snQEshkID4JzNnTtXGzdu1PTp03X48GHFx8erT58+evfddzVixIhaY2+66SZ17txZkydPVnFxsUaPHq3ly5fXGrN+/XotXLhQy5Yt0549exQTE6O0tDTdc889/jHp6el6//339dBDD2nixIlyOBzq1auX5s+ff9qc999/v8477zz9/ve/19NPP63Q0FD96Ec/0vXXXy+n0ylJGjJkiJ5//nnt3r1bdrtdvXv31saNG9WzZ88AfmIAmhtnCgbQbLp166brr79eS5cuNTsKgFaOfWgAAIDlUWgAAIDlsckJAABYHmtoAACA5VFoAACA5VFoAACA5VFoAACA5VFoAACA5VFoAACA5VFoAACA5VFoAACA5VFoAACA5f1/r708hsGS9A4AAAAASUVORK5CYII=", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p9.ggplot(\n", " iris >> mutate(Species=fct_reorder(f.Species, f.Sepal_Width))\n", ") + p9.geom_boxplot(\n", " p9.aes(x=\"Species\", y=\"Sepal_Width\")\n", ")" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjQAAAGyCAYAAADzil5bAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAA9hAAAPYQGoP6dpAAA1aklEQVR4nO3deXhU5cH+8XtmkhmykxBCJoKAiikhgICKQHjZBFfiHqUiYjRledvSotJCFQiCpS4FlBIiyqKtXCJoW1rFFaqit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AAlkehAQAAlhfS3Cd6PB79/e9/1/79+1VVVdXg8QkTJpzV6y1dulSffvqpKisrFRUVpTFjxigjI6PRsenp6XK5XLLZbJKklJQUzZ0796z/DQAAoHVoVqHZtm2bbr75ZuXl5ckwjAaP22y2sy406enpysrKksvl0pEjRzR37lwlJSUpLS2t0fGLFi1S586dmxMfAAC0Ms0qNFOmTFFMTIzWrFmjlJQUOZ3Ocw5y/vnn11u22Ww6ePDgOb8uAABo/ZpVaHbu3KmXX35Zw4YN82uYNWvW6C9/+Yuqq6uVkJCgESNGnHLsQw89JI/Hox49emjixIkNChEAAGg7mlVoLr74YpWWlvo7i+6++25NmDBB33zzjT7++GNFREQ0Ou7RRx9VcnKyamtr9corr2j27NlatmyZwsPD643Lz89Xfn6+b9nlcikpKcnvuc+Ww+EwOwICwOFw8LU1id1u993yNUAgnZhfzLPg06xCs2jRIk2bNk19+/bVD37wA78Gstls6tGjhz777DOtXbtW9957b4MxqampkqTQ0FCNHz9emzdv1q5duzRgwIB643Jzc5Wdne1bnjVrlhYsWODXvM1RXV1tdgQEQExMjGJjY82O0Sad+J6Kioria4AWER0dbXYEfE+TC03v3r19RxVJ/137kZqaqqSkJLVv377eWJvNps8///ycgnm93nprV07n5FwnmzRpktLT033LLpdLxcXF55TLH0pKSsyOgAAoKSmRy+UyO0abVFZW5rvla4BAcjgcio6OVmlpqTwej9lx2oym/KLS5EIzYMCAUxaHc3X8+HF98sknGjhwoNq1a6evvvpKr7/+um6//fYGY/ft26fa2lp169ZNdXV12rBhg2pqapScnNxgrNvtltvt9i0XFhYGxQQMhgzwP4/Hw9fWJF6v13fL1wAtge/34NPkQrN69eoAxpDefvttPfPMM/J6vYqLi9ONN96o6667TpKUkZGhOXPmqFevXjp27JhycnJUWFgop9Opiy66SNnZ2YqMjAxoPgAAELyatQ9NZmamHn74YXXv3r3BY3v37lV2drZWrlzZ5NeLjIw87b4t69at8/29T58+ysnJObvAAACgVWvWpQ9Wr16tI0eONPpYYWGh1qxZc06hAAAAzkazr+V0qv1pdu/erQ4dOjQ7EAAAwNlq8iannJwc36Yem82mH/7whwoLC6s3pqqqSt99951uu+02/6YEAAA4jSYXmqSkJN95Xnbs2KHk5GR17Nix3hin06mePXs2eu4YAACAQGlyobnhhht0ww03+JYffvhhXXDBBQEJBQAAcDaadZTTqlWr/J0DAACg2ZpcaDIzM8/qhc/msG0AAIBz0eRC889//rPe8oEDB1RYWKi4uDglJCSooKBARUVFio+PV+fOnf0etDX68ssvdejQIbNj4BwVFRWZHQEA2rxmFZpNmzZpypQpeumllzRixAjf/e+++67uvffeoLgApBXMmDHD7AgAALQKzToPzYwZMzRv3rx6ZUaSRo4cqblz5+rBBx/0SzgAAIJJeXm5cnNzVV5ebnYUfE+zdgrevXu34uLiGn0sLi5O33777TmFaisee+yxU36OsI6ioiLWtgFtRHl5uVasWKHhw4erXbt2ZsfBSZpVaFJSUrRw4UINGzas3kUhy8rKtHDhQqWkpPgtYGuWkpKixMREs2PgHLEfFACYr1mF5umnn9bVV1+tzp07a8SIEb6dgjdv3iyPx6NNmzb5OycAAMApNWsfmsGDB2v37t2aPHmySkpK9N5776mkpESTJ0/W7t27NWTIEH/nBAAAOKVmraGRpE6dOmnhwoX+zAIAANAszb7aNgAAQLBo8hqaPn366MUXX1Rqaqp69+4tm812yrE2m02ff/65XwICAACcSZMLzYABAxQREeH7++kKDQAAQEtqcqE5+YKUq1evDkQWAACAZmlyobn++us1dOhQDRkyRJdddplcLlcgcwEAADRZkwtNXl6efvWrX8kwDDmdTvXv319paWkaMmSI0tLSOOMtAAAwTZMLzeeff66ysjJ99NFH2rp1q7Zu3aqcnBw9/vjjstlsSk5O9pWbtLQ0XXjhhYHMDQAA4HNW56GJiorSmDFjNGbMGEmS1+vV559/7is4b775plauXCmbzaa6urqABAYAAPi+czoPjd1uV1xcnOLi4hQbG6vY2FhJUlhYmF/CAQAANMVZraHxeDz65z//6Vsj8+GHHyo/P19du3bVoEGDlJWVpUGDBqlv376BygsAANBAkwvNiBE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xs3/KsWbO0YMGCFskF+X6wRUVFKTY21uQ0bVNr/8+lrYqJiQm676ljx44pIyNDXq/X7Cgt4ic/+YnZEQLObrfrzTffVPv27c2O0iTNKjRer1cPPfSQnnrqKVVUVMhms+mTTz5RbGysbr75Zg0cOFBz5szxd9YzZjp5bYwkTZo0Senp6b5ll8ul4uLiFs3VlpWVlfluXS6XyWnappKSEknSY489FpCd89GyioqKNGPGDJWUlATd91RBQYG8Xq9WrlyphIQEs+PgHBUUFCgzM1OHDx/27R9rpqYU+GYVmtmzZ2vp0qV68sknNWrUKF188cW+x9LT0/Xss88GtNAcP35cn3zyiQYOHKh27drpq6++0uuvv67bb7+93ji32y232+1bLiwsDMgOymjcid/UvF4vn7tJTnzuKSkpSkxMNDkNztWJ/aA8Hk/QfU+dyJOQkMBca0WCca6dSrMKzerVq/Xoo49q0qRJDf6hF154ob799lu/hDudt99+W88884y8Xq/i4uJ044036rrrrgv4+wIAgODTrEJz9OhR9ezZs9HHPB6PamtrzynUmURGRrIvDAAA8GnWnrsXX3yx3nrrrUYf27Jli1JTU88pFAAAwNlo1hqan//858rKylJoaKhuvfVWSdL+/fv10Ucf6amnntLq1av9mREAAOC0mn0emqKiIs2dO1ePPvqoJOnGG29URESE5s+fzzWVAABAi2r2eWimT5+uH/3oR/rwww9VWFiouLg4DRo0yFIn4QEAAK3DOZ1YLzIyUmPGjPFXFgAAgGZp8k7BhYWF+uKLLxrc/8UXX+jWW29Vr169NGrUKG3cuNGvAQEAAM6kyYVm5syZDa7htHfvXg0dOlR/+tOfFBYWph07duimm27Se++95++cAAAAp9TkQrN161bdeeed9e5btGiRjh8/rr/+9a/69NNP9d133+mKK67Qb37zG78HBQAAOJUmF5oDBw40OL/Mxo0bdckll/j2owkLC9OPf/zjRjdNAQAABEqTC43NZpPNZvMtHz58WHv27NGwYcPqjevcubMKCwv9lxCWFRERoaysLEVERJgdBQDQyjW50CQnJ+vtt9/2Lf/lL3+RzWZrcJRTfn6+Onbs6L+EsKyIiA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AEiVZx2DYAAGjbKDQAAMDyKDQAAMDyKDQAAMDyKDQAAMDyKDQAAMDyKDQAAMDyKDQAAMDyKDQAAMDyKDQAAMDyKDQAAMDyKDQAAMDybIZhGGaHQOuUn5+v3NxcTZo0SW632+w4aMWYa2gpzLXgxRoaBEx+fr6ys7OVn59vdhS0csw1tBTmWvCi0AAAAMuj0AAAAMuj0CBg3G635syZw3ZmBBxzDS2FuRa82CkYAABYHmtoAACA5VFoAJhm2bJlevHFF1vk+evWrdPixYub/V5ou/w1d+677z599tln5x4IjWKTE/zivvvu05QpUzRgwACzowBAUOLnZGCxhgZAUPJ4PGZHQBsR7HMt2PMFixCzAyD4vPrqq9q4caPKy8sVHR2tu+66S//zP/+jzZs3a8OGDTp69Ki6du2qqVOn6vzzz9fjjz+uI0eO6Ne//rXsdrvGjh2ru+66S//+97+1YsUK5eXlqWPHjpowYYIuu+wySdLu3buVm5urvLw8hYaGql+/frr//vslSc8995y2bt2q8vJyud1u3XfffUpNTTXzI8E52LBhg3bu3KnZs2fXu2/Hjh2KiYlRbGys7r77bv3rX//S448/rltuuUWvvvqqunbtqjlz5uiFF17QW2+9JafTqXHjxunpp5/WihUr1KlTJy1evLjB8zMyMvTyyy/L6/Xqpptu0s033yxJevHFF3XgwAE9+OCDkqR///vfWrlypfbu3avQ0FCNHTtWt912mw4dOqSlS5dqz549kqRLLrlEU6ZMUWRkZMt/eDit082tWbNmae3atXrvvfdUWVmpfv36afLkyYqMjNThw4eVlZWladOmae3atXK5XFq6dKlWr16td999VzU1NYqLi9PUqVPVu3fvJs8dwzD0yiuvaNOmTaqoqFBKSoomT56sDh06NMheW1ur3//+93rvvfdUV1enAQMGKCsrSxEREZKk9PR0TZ48WRs3btTRo0e1bt26lvlQrcwATpKXl2fccsstRl5enmEYhnH06FFj7969xt///nfj3nvvNfbs2WPU1dUZr7/+unHfffcZNTU1hmEYxr333mt8+umnvtcpKyszxo0bZ2zatMmoq6sztm3bZtx6663Gvn37DMMwjAceeMB46aW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rx4sQ4fPiyXy6WUlBTf0Ue33nqrVqxYod///ve67rrrNH78eM2ZM0fPPvusnnvuOcXHx+v+++9Xly5dJEnbt2/XqlWrVF1drdjYWE2ePFmJiYnq2LGjLr30Uk2dOlXt2rVTenr6GTczwBqGDx+uBQsW6IYbbvDtq3Umo0ePVn5+vqZPny6n06mMjAx98MEH5/xDv2PHjpo7d65WrVqlZ555Rk6nU+np6UpOTta4ceO0aNEijRs3Tm63W8OHD9err756Tu+HwGpsbt199916+eWX9ctf/lIlJSWKiYnR0KFDT7nvVkVFhZ577jkdPnxYISEh6tmzp/73f/+3wbjTzZ2RI0equLhYc+bM8R3l9P3NXifcdtttqqys1PTp0+XxeNS/f39lZWX570NpgzixHgDL+Pbbb/Xggw9q/fr1jf72DKDt4icCgKBVW1urf/zjH/J4PCopKdHzzz+vgQMHUmYANMAaGgBBq7a2VjNnzlReXp5CQkLUu3dvTZ48ud6OkwAgUWgAAEArwHpbAABgeRQaAABgeRQaAABgeRQaAABgeRQaAABgeRQaAM3yhz/8QZdffrliYmIUHR2tnj176r777qt3LZuW9N1338lms2n9+vWmvD8Ac1FoAJy1xx57THfddZeGDh2ql156SS+99JIyMzP16aef6uDBg6Zkcrvd+uijjzRy5EhT3h+AuTgPDYCz1rlzZ40ZM0YrV65s8JjX6+VMvgBaHD91AJy14uLiRq8gLKlemenWrZt+/OMf6/HHH9d5552n8PBw3XDDDcrPz6/3nOrqas2aNUtdu3aVy+VSz5499eKLLzZ47Y8++khjxoxRdHS0oqKiNHDgQL311luSTr3JafXq1erTp4/atWun8847T7/61a/k8Xh8jx87dkxZWVk677zz1K5dO3Xp0kV33HFHsz8bAObgatsAztqAAQO0fPlyde/eXddff70SExNPOfbVV19V165dlZOTo+LiYv3iF7/QzTffrI8++sg35sRVtOfMmaOePXvqtdde0/jx4xUbG6trrrlGkrR161aNHDlSV1xxhZ599lm1b99en376qfbt23fK9/7tb3+rGTNm6Oc//7mefPJJ7dq1y1doFi5cKEmaPn26Xn/9dS1cuFDdunVTfn6+Xn/9dT99UgBajAEAZ+lf//qXcdFFFxmSDElG9+7djZ/+9KfGnj176o3r2rWrERUVZRw7dsx33zvvvGNIMjZt2mQYhmG8++67hiTjjTfeqPfc22+/3bjssst8y4MHDzZSUlKMurq6RjPt2bPHkGS8/PLLhmEYRmlpqREZGWnMnDmz3ricnBwjLCzMKCwsNAzDMHr16mVMnz69eR8EgKDBJicAZy01NVU7d+7UX//6V02bNk0xMTF66qmn1KdPH23fvr3e2BEjRigmJsa3PHLkSMXFxenvf/+7JOnNN99UXFycRo4cqbq6Ot+f0aNH65///Kc8Ho8qKir08ccf6+6775bD4WhSxg8//FDHjx/XbbfdVu91r7zySlVWVmrHjh2SpP79+2v16tV64oknfPcBsB42OQFoFqfTqWuvvVbXXnutJOmNN97Qddddp3nz5umVV17xjUtISGjw3ISEBN9+NIWFhSoqKlJoaGij75Ofny+bzSav16ukpKQm5yssLJT038LSmLy8PEnS008/rbi4OD355JN68MEH1aVLF82cOVNTpkxp8nsBMB+FBoBfXHXVVerbt6927dpV7/7GzktTUFDg26k4Li5OHTt21Guvvdbo6yYkJKi2tlZ2u/2sDgmPi4uTJL3yyivq0qVLg8e7d+8uSYqJidHixYu1ePFi/etf/9KSJUs0depUpaamaujQoU1+PwDmYpMTgLN2+PDhBvdVVlYqLy+vwQ7CmzdvVklJiW/53XffVVFRkQYOHChJuvLKK3XkyBE5nU5deumlDf44nU5FRERo0KBBev755+sdoXQ6gwYNUnh4uPbv39/o63bo0KHBc3r37q1FixZJUoNiBiC4sYYGwFnr3bu3xo4dq6uuukput1sHDhzQ0qVLVVhYqGnTptUbGxUVpWuuuUa//OUvdezYMf3iF7/Q5ZdfrquuukqSNHr0aI0dO1ZXX321ZsyYoT59+qi8vFw7d+7UN998o2effVaStHDhQo0cOVJXXnmlpk6dqtjYWG3btk3x8fHKzMxskLF9+/aaN2+eZsyYof3792v48OFyOBz6z3/+oz/96U/asGGDwsPDNWTIEN10001KTU2Vw+HQ888/L6fTydoZwGIoNADO2ty5c7Vx40ZNnz5dR44cUXx8vPr06aN33nlHI0aMqDf2pptuUufOnTV58mQVFxdr9OjRWr58eb0x69ev18KFC7Vs2TLt3btXMTExSk1N1T333OMbk5aWpi1btuihhx7SxIkT5XA41KtXL82fP/+UOe+//36dd955+u1vf6unn35aoaGhuvDCC3X99dfL6XRKkoYMGaLnn39ee/bskd1uV+/evbVx40b17NnTj58YgEDjTMEAAqZbt266/vrrtXTpUrOjAGjl2IcGAABYHoUGAABYHpucAACA5bGGBgAAWB6FBgAAWB6FBgAAWB6FBgAAWB6FBgAAWB6FBgAAWB6FBgAAWB6FBgAAWB6FBgAAWN7/A0udPIZ5X7oGAAAAAElFTkSuQmCC", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p9.ggplot(\n", " iris >> mutate(Species=fct_reorder(f.Species, f.Sepal_Width, _desc=True))\n", ") + p9.geom_boxplot(\n", " p9.aes(x=\"Species\", y=\"Sepal_Width\")\n", ")" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAo0AAAGuCAYAAAD1fTxIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAA9hAAAPYQGoP6dpAAC3AUlEQVR4nOzdd3yV5f3/8dd932ePLLJDEvYUEJwIijhw4KijVm2to446qnZoq93rZ7/W77darXXUVSturXtbRRGtCxc7JCGBEBIyzz73fV+/PwIRSAgZJ2TweT4eeUDOObnv6+ROznnnGp9LU0ophBBCCCGE6II+0A0QQgghhBCDn4RGIYQQQgixWxIahRBCCCHEbkloFEIIIYQQuyWhUQghhBBC7JaERiGEEEIIsVsSGoUQQgghxG5JaBRCCCGEELvlGOgGDIT6+vp+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HA0pZQa6UYIIYQQQojRTXoahRBCCCHEsCQ0CiGEEEKIYUloFEIIIYQQw5LQKIQQQgghhiWhUQghhBBCDEtCoxBCCCGEGJaERiGEEEIIMSwJjUIIIYQQYlgSGoUQQgghxLAkNAohhBBCiGFJaBRCCCGEEMP6/wE/x6xD2zUWkwAAAABJRU5ErkJggg==", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "chks = (\n", " ChickWeight \n", " >> filter(as_integer(f.Chick) < 10)\n", " >> mutate(Chick=fct_shuffle(f.Chick))\n", ")\n", "\n", "(\n", " p9.ggplot(chks, p9.aes(\"Time\", \"weight\", colour=\"Chick\")) \n", " + p9.geom_point() \n", " + p9.geom_line()\n", ")" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAo0AAAGuCAYAAAD1fTxIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAA9hAAAPYQGoP6dpAAC3RElEQVR4nOzdd3xW9d3/8dc559oji4SQQBL2HoKCoijiwIGjjlpHraOOOupqtdWO295tb3tb719tHXW0jrpw4d6KiCIOVEDZkEGAJBASklz7Oud8f38EIiOEjCtk8Hn68AG5xjnfi5Mr1zvf8flqSimFEEIIIYQQLdC7ugFCCCGEEKL7k9AohBBCCCH2SUKjEEIIIYTYJwmNQgghhBBinyQ0CiGEEEKIfZLQKIQQQggh9klCoxBCCCGE2CcJjUIIIYQQYp8cXd2ArlBdXd0px9U0Da/XSzQapTfVTHe5XCQSia5uRkr11msFcr16ErlWPUtvu1498VplZ2d3dRMOaNLTmEK6ruPz+dD13vXP6na7u7oJKddbrxXI9epJ5Fr1LL3tevXmayU6h3ynCCGEEEKIfZLQKIQ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jml6e+2bXP77beTm5tLdnY2l1xyCeFwuOn+5oan4/E4v/3tbxk8eDBut5sBAwZw8cUX77U9tm1z2WWXkZ2dzaJFizr+AttAehqFEEKILpSos1l9f5jAUAeFP/RK8e5uxDRNFixYwFlnnYXTue/pAvfeey9HHnkkjz/+OKtXr+bmm28mNzeXv/zlL3t9zllnncXcuXO57bbbOOyww9iyZQtz5szZa3suvPBC5s2bx7x58/b7XEcJjUIIIUQXsaKKNf8M48rQGHyRD02XwNidbN26lXg8TmFhYasen5eXx1NPPQXAiSeeyNdff80LL7yw19D43nvv8cYbb/D0009z3nnnNd2+8993iMfjnHPOOSxevJj58+czbNiwdryijpHhaSGEEKIL2KZi7b/CKFMx9Eo/uksCY3fV2t7f448/fpevR48ezYYNG/b6+A8++ACfz8e5557b4nGj0SinnHIKK1as4OOPP+6SwAgSGoUQQoj9TtmK0icjxKoshl8TwOGTj+PuqE+fPng8HtavX9+qx+++KtrlchGPx/f6+K1bt5KXl7fPULplyxY++ugjZs2a1epez84g36VCCCHEfrbhlRh1y5IMvzqAK1M+irsrh8PBEUccwQcffIBpmik/fp8+faioqEAp1eLjCgsLefrpp7nnnnv485//nPJ2tJZ8pwohhBD7UdWHMTZ/FGfoFQG8+bLbS3d30003UVlZudew9uabb7b72McddxyRSITnnntun489++yzefzxx/n973/P3Xff3e5zdoQshBFCCCH2k5qvEpS/FGPwJT6Cw+QjuCc4+eSTueWWW7j99ttZvnw55557LtnZ2ZSUlPDII49QV1fHySef3K5jH3fccZx88slceumlrFu3jkMPPZSamhpeeOEFnn322T0ef8EFFxCNRrnyyivxer1ceeWVHX15bSLfsUIIIcR+UL86SckTEQrO9JI10dXVzRFt8L//+78cfvjh3HvvvVx66aWEw2H69+/PCSecwC9/+csOHfvFF1/kD3/4Aw8++GBTjceZM2fu9fGXXXYZsViMq6++Gq/Xy09+8pMOnb8tNLWvgfReqC17PraFYRhkZmZSW1uLZVmdco6uEAwGaWho6OpmpFRvvVYg16snkWvVs3TkekU2WK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x3NKWUGu9GCCGEEEKIiU16GoUQQgghxJgkNAohhBBCiDFJaBRCCCGEEGOS0CiEEEIIIcYkoVEIIYQQQoxJQqMQQgghhBiThEYhhBBCCDEmCY1CCCGEEGJMEhqFEEIIIcSYJDQKIYQQQogxSWgUQgghhBBj+v8BJfa+1tXR+qsAAAAASUVORK5CYII=", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(\n", " p9.ggplot(\n", " chks >> mutate(Chick=fct_reorder2(f.Chick, f.Time, f.weight)),\n", " p9.aes(\"Time\", \"weight\", colour=\"Chick\"),\n", " )\n", " + p9.geom_point()\n", " + p9.geom_line()\n", " + p9.labs(colour=\"Chick\")\n", ")\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## fct_shuffle" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a', 'b', 'c']\n", "Categories (3, object): ['b', 'c', 'a']" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct = factor(c(\"a\", \"b\", \"c\"))\n", "fct_shuffle(fct)" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a', 'b', 'c']\n", "Categories (3, object): ['c', 'b', 'a']" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_shuffle(fct)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## fct_rev" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a', 'b', 'c']\n", "Categories (3, object): ['c', 'b', 'a']" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_rev(fct)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## fct_shift" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Mon', 'Tue', 'Wed']\n", "Categories (7, object): ['Sun' < 'Mon' < 'Tue' < 'Wed' < 'Thu' < 'Fri' < 'Sat']" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = factor(\n", " c(\"Mon\", \"Tue\", \"Wed\"),\n", " levels = c(\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"),\n", " ordered = TRUE\n", ")\n", "x" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Mon', 'Tue', 'Wed']\n", "Categories (7, object): ['Mon' < 'Tue' < 'Wed' < 'Thu' < 'Fri' < 'Sat' < 'Sun']" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_shift(x)" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Mon', 'Tue', 'Wed']\n", "Categories (7, object): ['Tue' < 'Wed' < 'Thu' < 'Fri' < 'Sat' < 'Sun' < 'Mon']" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_shift(x, 2)" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Mon', 'Tue', 'Wed']\n", "Categories (7, object): ['Sat' < 'Sun' < 'Mon' < 'Tue' < 'Wed' < 'Thu' < 'Fri']" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_shift(x, -1)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 2 } ================================================ FILE: docs/notebooks/forcats_lvl_value.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_anon
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Anonymise factor levels\n", "\n", "##### Args:\n", "  `f`: A factor. \n", "  `prefix`: A character prefix to insert in front of the random labels. \n", "\n", "##### Returns:\n", "  The factor with levels anonymised \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_collapse
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Collapse factor levels into manually defined groups\n", "\n", "##### Args:\n", "  `_f`: A factor \n", "  `**kwargs`: The levels to collapse. \n", "    Like `name=[old_level, old_level1, ...]`. The old levels will \n", "    be replaced with `name` \n", "\n", "  `other_level`: Replace all levels not named in `kwargs`. \n", "    If not, don't collapse them. \n", "\n", "##### Returns:\n", "  The factor with levels collapsed. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_lump
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Lump together factor levels into \"other\"\n", "\n", "##### Args:\n", "  `f`: A factor \n", "  `n`: Positive `n` preserves the most common `n` values. \n", "    Negative `n` preserves the least common `-n` values. \n", "    It there are ties, you will get at least `abs(n)` values. \n", "\n", "  `prop`: Positive `prop` lumps values which do not appear at least \n", "    `prop` of the time. Negative `prop` lumps values that \n", "    do not appear at most `-prop` of the time. \n", "\n", "  `w`: An optional numeric vector giving weights for frequency of \n", "    each value (not level) in f. \n", "\n", "  `other_level`: Value of level used for \"other\" values. Always \n", "    placed at end of levels. \n", "\n", "  ties_method A character string specifying how ties are treated. \n", "    One of: `average`, `first`, `dense`, `max`, and `min`. \n", "\n", "##### Returns:\n", "  The factor with levels lumped. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_lump_min
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### lumps levels that appear fewer than `min_` times.\n", "\n", "##### Args:\n", "  `_f`: A factor \n", "  `min_`: Preserve levels that appear at least `min_` number of times. \n", "  `w`: An optional numeric vector giving weights for frequency of \n", "    each value (not level) in f. \n", "\n", "  `other_level`: Value of level used for \"other\" values. Always \n", "    placed at end of levels. \n", "\n", "##### Returns:\n", "  The factor with levels lumped. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_lump_prop
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Lumps levels that appear in fewer `prop * n` times.\n", "\n", "##### Args:\n", "  `_f`: A factor \n", "  `prop`: Positive `prop` lumps values which do not appear at least \n", "    `prop` of the time. Negative `prop` lumps values that \n", "    do not appear at most `-prop` of the time. \n", "\n", "  `w`: An optional numeric vector giving weights for frequency of \n", "    each value (not level) in f. \n", "\n", "  `other_level`: Value of level used for \"other\" values. Always \n", "    placed at end of levels. \n", "\n", "##### Returns:\n", "  The factor with levels lumped. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_lump_n
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Lumps all levels except for the `n` most frequent.\n", "\n", "##### Args:\n", "  `f`: A factor \n", "  `n`: Positive `n` preserves the most common `n` values. \n", "    Negative `n` preserves the least common `-n` values. \n", "    It there are ties, you will get at least `abs(n)` values. \n", "\n", "  `w`: An optional numeric vector giving weights for frequency of \n", "    each value (not level) in f. \n", "\n", "  `other_level`: Value of level used for \"other\" values. Always \n", "    placed at end of levels. \n", "\n", "  ties_method A character string specifying how ties are treated. \n", "    One of: `average`, `first`, `dense`, `max`, and `min`. \n", "\n", "##### Returns:\n", "  The factor with levels lumped. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_lump_lowfreq
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### lumps together the least frequent levels, ensuring\n", "that \"other\" is still the smallest level. \n", "\n", "##### Args:\n", "  `f`: A factor \n", "  `other_level`: Value of level used for \"other\" values. Always \n", "    placed at end of levels. \n", "\n", "##### Returns:\n", "  The factor with levels lumped. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_other
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Replace levels with \"other\"\n", "\n", "##### Args:\n", "  `_f`: A factor \n", "  `keep`: and \n", "  `drop`: Pick one of `keep` and `drop`: \n", "    - `keep` will preserve listed levels, replacing all others with\n", "      `other_level`. \n", "\n", "    - `drop` will replace listed levels with `other_level`, keeping all\n", "      as is. \n", "\n", "  `other_level`: Value of level used for \"other\" values. Always \n", "    placed at end of levels. \n", "\n", "##### Returns:\n", "  The factor with levels replaced. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_recode
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Change factor levels by hand\n", "\n", "##### Args:\n", "  `_f`: A factor \n", "  `*args`: and \n", "  `**kwargs`: A sequence of named character vectors where the name \n", "    gives the new level, and the value gives the old level. \n", "    Levels not otherwise mentioned will be left as is. Levels can \n", "    be removed by naming them `NULL`. \n", "    As `NULL/None` cannot be a name of keyword arguments, replacement \n", "    has to be specified as a dict \n", "    (i.e. `fct_recode(x, {NULL: \"apple\"})`) \n", "    If you want to replace multiple values with the same old value, \n", "    use a `set`/`list`/`numpy.ndarray` \n", "    (i.e. `fct_recode(x, fruit=[\"apple\", \"banana\"])`). \n", "    This is a safe way, since `set`/`list`/`numpy.ndarray` is \n", "    not hashable to be a level of a factor. \n", "    Do NOT use a `tuple`, as it's hashable! \n", "\n", "    Note that the order of the name-value is in the reverse way as \n", "    `dplyr.recode()` and `dplyr.recode_factor()` \n", "\n", "##### Returns:\n", "  The factor recoded with given recodings \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_relabel
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Automatically relabel factor levels, collapse as necessary\n", "\n", "##### Args:\n", "  `_f`: A factor \n", "  `_fun`: A function to be applied to each level. Must accept the old \n", "    levels and return a character vector of the same length \n", "    as its input. \n", "\n", "  `*args`: and \n", "  `**kwargs`: Addtional arguments to `_fun` \n", "\n", "##### Returns:\n", "  The factor with levels relabeled \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%run nb_helpers.py\n", "\n", "from datar.all import *\n", "from datar.data import gss_cat\n", "\n", "gss_cat >>= mutate(rincome=as_factor(f.rincome))\n", "\n", "nb_header(\n", " fct_anon,\n", " fct_collapse,\n", " fct_lump,\n", " fct_lump_min,\n", " fct_lump_prop,\n", " fct_lump_n,\n", " fct_lump_lowfreq,\n", " fct_other,\n", " fct_recode,\n", " fct_relabel,\n", " book=\"forcat_lvl_value\",\n", ")\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## fct_anon" ] }, { "cell_type": "code", "execution_count": 2, "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", "
fn
<category><int64>
0Buddhism147
1Catholic5124
2Christian689
3Don't know15
4Hinduism71
5Inter-nondenominational109
6Jewish388
7Moslem/islam104
8Native american23
9No answer93
10None3523
11Orthodox-christian95
12Other224
13Other eastern32
14Protestant10846
\n", "
\n" ], "text/plain": [ " f n\n", " \n", "0 Buddhism 147\n", "1 Catholic 5124\n", "2 Christian 689\n", "3 Don't know 15\n", "4 Hinduism 71\n", "5 Inter-nondenominational 109\n", "6 Jewish 388\n", "7 Moslem/islam 104\n", "8 Native american 23\n", "9 No answer 93\n", "10 None 3523\n", "11 Orthodox-christian 95\n", "12 Other 224\n", "13 Other eastern 32\n", "14 Protestant 10846" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gss_cat.relig >> fct_count()" ] }, { "cell_type": "code", "execution_count": 3, "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", "
fn
<category><int64>
000147
101104
20293
303109
4045124
505689
60632
70715
808224
90971
10103523
111110846
121223
1313388
141495
\n", "
\n" ], "text/plain": [ " f n\n", " \n", "0 00 147\n", "1 01 104\n", "2 02 93\n", "3 03 109\n", "4 04 5124\n", "5 05 689\n", "6 06 32\n", "7 07 15\n", "8 08 224\n", "9 09 71\n", "10 10 3523\n", "11 11 10846\n", "12 12 23\n", "13 13 388\n", "14 14 95" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gss_cat.relig >> fct_anon() >> fct_count()" ] }, { "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fn
<category><int64>
0X00388
1X01689
2X02224
3X033523
4X045124
5X05147
6X0610846
7X07109
8X0895
9X0923
10X1015
11X1171
12X12104
13X1332
14X1493
\n", "
\n" ], "text/plain": [ " f n\n", " \n", "0 X00 388\n", "1 X01 689\n", "2 X02 224\n", "3 X03 3523\n", "4 X04 5124\n", "5 X05 147\n", "6 X06 10846\n", "7 X07 109\n", "8 X08 95\n", "9 X09 23\n", "10 X10 15\n", "11 X11 71\n", "12 X12 104\n", "13 X13 32\n", "14 X14 93" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gss_cat.relig >> fct_anon(\"X\") >> fct_count()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## fct_collapse" ] }, { "cell_type": "code", "execution_count": 5, "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", "
fn
<category><int64>
0Don't know1
1Ind,near dem2499
2Ind,near rep1791
3Independent4119
4No answer154
5Not str democrat3690
6Not str republican3032
7Other party393
8Strong democrat3490
9Strong republican2314
\n", "
\n" ], "text/plain": [ " f n\n", " \n", "0 Don't know 1\n", "1 Ind,near dem 2499\n", "2 Ind,near rep 1791\n", "3 Independent 4119\n", "4 No answer 154\n", "5 Not str democrat 3690\n", "6 Not str republican 3032\n", "7 Other party 393\n", "8 Strong democrat 3490\n", "9 Strong republican 2314" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_count(gss_cat.partyid)" ] }, { "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", "
fn
<category><int64>
0missing155
1ind8409
2dem7180
3rep5346
4other393
\n", "
\n" ], "text/plain": [ " f n\n", " \n", "0 missing 155\n", "1 ind 8409\n", "2 dem 7180\n", "3 rep 5346\n", "4 other 393" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "partyid2 = fct_collapse(\n", " gss_cat.partyid,\n", " missing = c(\"No answer\", \"Don't know\"),\n", " other = \"Other party\",\n", " rep = c(\"Strong republican\", \"Not str republican\"),\n", " ind = c(\"Ind,near rep\", \"Independent\", \"Ind,near dem\"),\n", " dem = c(\"Not str democrat\", \"Strong democrat\")\n", ")\n", "fct_count(partyid2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## fct_recode" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['fruit', 'bear', 'fruit', 'dear']\n", "Categories (3, object): ['fruit', 'bear', 'dear']" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = factor(c(\"apple\", \"bear\", \"banana\", \"dear\"))\n", "fct_recode(x, fruit=[\"apple\", \"banana\"])" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 14:01:25][datar][WARNING] [fct_recode] Unknown levels in `_f`: {'bananana'}\n" ] }, { "data": { "text/plain": [ "['fruit', 'bear', 'banana', 'dear']\n", "Categories (4, object): ['fruit', 'banana', 'bear', 'dear']" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# If you make a mistake you'll get a warning\n", "fct_recode(x, fruit=[\"apple\", \"bananana\"])" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[NaN, 'fruit', 'bear', 'dear']\n", "Categories (3, object): ['fruit', 'bear', 'dear']" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_recode(x, {NULL: \"apple\"}, fruit = \"banana\")" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['an apple', 'a bear', 'banana', 'dear']\n", "Categories (4, object): ['an apple', 'banana', 'a bear', 'dear']" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Anything cannot be a keyword directly, use a dict\n", "fct_recode(x, {\"an apple\": \"apple\", \"a bear\": \"bear\"})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## fct_lump, fct_lump_min, fct_lump_prop, fct_lump_n, and fct_lump_lowfreq" ] }, { "cell_type": "code", "execution_count": 11, "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", "
ABCDEFGHI
<int64><int64><int64><int64><int64><int64><int64><int64><int64>
count401052711111
\n", "
\n" ], "text/plain": [ " A B C D E F G H I\n", " \n", "count 40 10 5 27 1 1 1 1 1" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = factor(rep(LETTERS[:9], times = c(40, 10, 5, 27, 1, 1, 1, 1, 1)))\n", "table(x)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['A', 'A', 'A', 'A', 'A', ..., 'Other', 'Other', 'Other', 'Other', 'Other']\n", "Length: 87\n", "Categories (4, object): ['A', 'B', 'D', 'Other']" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" }, { "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", "
ABDOther
<int64><int64><int64><int64>
count40102710
\n", "
\n" ], "text/plain": [ " A B D Other\n", " \n", "count 40 10 27 10" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x >> fct_lump_n(3) \n", "table(_)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['A', 'A', 'A', 'A', 'A', ..., 'Other', 'Other', 'Other', 'Other', 'Other']\n", "Length: 87\n", "Categories (4, object): ['A', 'B', 'D', 'Other']" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" }, { "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", "
ABDOther
<int64><int64><int64><int64>
count40102710
\n", "
\n" ], "text/plain": [ " A B D Other\n", " \n", "count 40 10 27 10" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x >> fct_lump_prop(0.10) \n", "table(_)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['A', 'A', 'A', 'A', 'A', ..., 'Other', 'Other', 'Other', 'Other', 'Other']\n", "Length: 87\n", "Categories (5, object): ['A', 'B', 'C', 'D', 'Other']" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" }, { "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", "
ABCDOther
<int64><int64><int64><int64><int64>
count40105275
\n", "
\n" ], "text/plain": [ " A B C D Other\n", " \n", "count 40 10 5 27 5" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x >> fct_lump_min(5) \n", "table(_)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['A', 'A', 'A', 'A', 'A', ..., 'Other', 'Other', 'Other', 'Other', 'Other']\n", "Length: 87\n", "Categories (3, object): ['A', 'D', 'Other']" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" }, { "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", "
ADOther
<int64><int64><int64>
count402720
\n", "
\n" ], "text/plain": [ " A D Other\n", " \n", "count 40 27 20" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x >> fct_lump_lowfreq() \n", "table(_)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['D', 'E', 'D', 'I', 'E', ..., 'D', 'E', 'L', 'D', 'E']\n", "Length: 100\n", "Categories (12, object): ['B', 'C', 'D', 'E', ..., 'J', 'K', 'L', 'M']" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = factor(LETTERS[rpois(100, 5)])\n", "x" ] }, { "cell_type": "code", "execution_count": 17, "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", "
BCDEFGHIJKLM
<int64><int64><int64><int64><int64><int64><int64><int64><int64><int64><int64><int64>
count1917181813884112
\n", "
\n" ], "text/plain": [ " B C D E F G H I J \\\n", " \n", "count 1 9 17 18 18 13 8 8 4 \n", "\n", " K L M \n", " \n", "count 1 1 2 " ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "table(x)" ] }, { "cell_type": "code", "execution_count": 18, "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", "
BCDEFGHIJKLM
<int64><int64><int64><int64><int64><int64><int64><int64><int64><int64><int64><int64>
count1917181813884112
\n", "
\n" ], "text/plain": [ " B C D E F G H I J \\\n", " \n", "count 1 9 17 18 18 13 8 8 4 \n", "\n", " K L M \n", " \n", "count 1 1 2 " ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "table(fct_lump_lowfreq(x))" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['D', 'E', 'D', 'Other', 'E', ..., 'D', 'E', 'Other', 'D', 'E']\n", "Length: 100\n", "Categories (4, object): ['D', 'E', 'F', 'Other']" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_lump_n(x, n = 3)" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['D', 'E', 'D', 'Other', 'E', ..., 'D', 'E', 'Other', 'D', 'E']\n", "Length: 100\n", "Categories (5, object): ['D', 'E', 'F', 'G', 'Other']" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_lump_prop(x, prop = 0.1)" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Other', 'Other', 'Other', 'Other', 'Other', ..., 'Other', 'Other', 'L', 'Other', 'Other']\n", "Length: 100\n", "Categories (4, object): ['B', 'K', 'L', 'Other']" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Use negative values to collapse the most common\n", "fct_lump_n(x, n = -3)" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Other', 'Other', 'Other', 'I', 'Other', ..., 'Other', 'Other', 'L', 'Other', 'Other']\n", "Length: 100\n", "Categories (9, object): ['B', 'C', 'H', 'I', ..., 'K', 'L', 'M', 'Other']" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_lump_prop(x, prop = -0.1)" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['D', 'E', 'D', 'Other', 'E', ..., 'D', 'E', 'Other', 'D', 'E']\n", "Length: 100\n", "Categories (6, object): ['B', 'C', 'D', 'E', 'H', 'Other']" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w = c(rep(2, 50), rep(1, 50))\n", "fct_lump_n(x, n = 5, w = w)" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['D', 'E', 'D', 'I', 'E', ..., 'D', 'E', 'Other', 'D', 'E']\n", "Length: 100\n", "Categories (8, object): ['C', 'D', 'E', 'F', 'G', 'H', 'I', 'Other']" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_lump_n(x, n = 6)" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['D', 'E', 'D', 'Other', 'E', ..., 'D', 'E', 'Other', 'D', 'E']\n", "Length: 100\n", "Categories (6, object): ['C', 'D', 'E', 'F', 'G', 'Other']" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_lump_n(x, n = 6, ties_method = \"max\")" ] }, { "cell_type": "code", "execution_count": 26, "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", "
DEFGOther
<int64><int64><int64><int64><int64>
count1718181334
\n", "
\n" ], "text/plain": [ " D E F G Other\n", " \n", "count 17 18 18 13 34" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Use fct_lump_min() to lump together all levels with fewer than `n` values\n", "table(fct_lump_min(x, min = 10))\n" ] }, { "cell_type": "code", "execution_count": 27, "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", "
DEFOther
<int64><int64><int64><int64>
count17181847
\n", "
\n" ], "text/plain": [ " D E F Other\n", " \n", "count 17 18 18 47" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "table(fct_lump_min(x, min = 15))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## fct_other" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Other', 'Other', 'Other', 'Other', 'Other', ..., 'Other', 'Other', 'Other', 'Other', 'Other']\n", "Length: 100\n", "Categories (2, object): ['B', 'Other']" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_other(x, keep = c(\"A\", \"B\"))" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['D', 'E', 'D', 'I', 'E', ..., 'D', 'E', 'L', 'D', 'E']\n", "Length: 100\n", "Categories (12, object): ['C', 'D', 'E', 'F', ..., 'K', 'L', 'M', 'Other']" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_other(x, drop = c(\"A\", \"B\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## fct_recode" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['fruit', 'bear', 'fruit', 'dear']\n", "Categories (3, object): ['fruit', 'bear', 'dear']" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = factor(c(\"apple\", \"bear\", \"banana\", \"dear\"))\n", "fct_recode(x, fruit = [\"apple\", \"banana\"])" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 14:01:52][datar][WARNING] [fct_recode] Unknown levels in `_f`: {'bananana'}\n" ] }, { "data": { "text/plain": [ "['fruit', 'bear', 'banana', 'dear']\n", "Categories (4, object): ['fruit', 'banana', 'bear', 'dear']" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# If you make a mistake you'll get a warning\n", "fct_recode(x, fruit = [\"apple\", \"bananana\"])" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[NaN, 'fruit', 'bear', 'dear']\n", "Categories (3, object): ['fruit', 'bear', 'dear']" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# If you name the level NULL it will be removed\n", "fct_recode(x, {NULL: \"apple\"}, fruit = \"banana\")" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['an apple', 'a bear', 'banana', 'dear']\n", "Categories (4, object): ['an apple', 'banana', 'a bear', 'dear']" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_recode(x, {\"an apple\": \"apple\", \"a bear\": \"bear\"})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## fct_relabel" ] }, { "cell_type": "code", "execution_count": 34, "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", "
fn
<category><int64>
0Don't know1
1Ind,near dem2499
2Ind,near rep1791
3Independent4119
4No answer154
5Not str democrat3690
6Not str republican3032
7Other party393
8Strong democrat3490
9Strong republican2314
\n", "
\n" ], "text/plain": [ " f n\n", " \n", "0 Don't know 1\n", "1 Ind,near dem 2499\n", "2 Ind,near rep 1791\n", "3 Independent 4119\n", "4 No answer 154\n", "5 Not str democrat 3690\n", "6 Not str republican 3032\n", "7 Other party 393\n", "8 Strong democrat 3490\n", "9 Strong republican 2314" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gss_cat.partyid >> fct_count()" ] }, { "cell_type": "code", "execution_count": 35, "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", "
fn
<category><int64>
0Don't know1
1Ind, near dem2499
2Ind, near rep1791
3Independent4119
4No answer154
5Not str democrat3690
6Not str republican3032
7Other party393
8Strong democrat3490
9Strong republican2314
\n", "
\n" ], "text/plain": [ " f n\n", " \n", "0 Don't know 1\n", "1 Ind, near dem 2499\n", "2 Ind, near rep 1791\n", "3 Independent 4119\n", "4 No answer 154\n", "5 Not str democrat 3690\n", "6 Not str republican 3032\n", "7 Other party 393\n", "8 Strong democrat 3490\n", "9 Strong republican 2314" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gss_cat.partyid >> fct_relabel(lambda old: gsub(\",\", \", \", old)) >> fct_count()" ] }, { "cell_type": "code", "execution_count": 36, "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", "
fn
<category><int64>
0$1000 to 2999395
1$10000 - 149991168
2$15000 - 199991048
3$20000 - 249991283
4$25000 or more7363
5$3000 to 3999276
6$4000 to 4999226
7$5000 to 5999227
8$6000 to 6999215
9$7000 to 7999188
10$8000 to 9999340
11Don't know267
12Lt $1000286
13No answer183
14Not applicable7043
15Refused975
\n", "
\n" ], "text/plain": [ " f n\n", " \n", "0 $1000 to 2999 395\n", "1 $10000 - 14999 1168\n", "2 $15000 - 19999 1048\n", "3 $20000 - 24999 1283\n", "4 $25000 or more 7363\n", "5 $3000 to 3999 276\n", "6 $4000 to 4999 226\n", "7 $5000 to 5999 227\n", "8 $6000 to 6999 215\n", "9 $7000 to 7999 188\n", "10 $8000 to 9999 340\n", "11 Don't know 267\n", "12 Lt $1000 286\n", "13 No answer 183\n", "14 Not applicable 7043\n", "15 Refused 975" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_count(gss_cat.rincome)" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array(['Gt $0.0', 'Gt $10000.0', 'Gt $15000.0', 'Gt $20000.0',\n", " 'Gt $25000.0', 'Gt $0.0', 'Gt $0.0', 'Gt $5000.0', 'Gt $5000.0',\n", " 'Gt $5000.0', 'Gt $5000.0', \"Don't know\", 'Gt $0.0', 'No answer',\n", " 'Not applicable', 'Refused'], dtype=object)" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def convert_income(income):\n", " regex = r\"^(?:Lt |)[$]([0-9]+).*$\"\n", " is_range = grepl(regex, income)\n", " num_income = as_numeric(gsub(regex, r\"\\1\", income[is_range]))\n", " num_income = trunc(num_income / 5000) * 5000\n", " income[is_range] = paste0(\"Gt $\", num_income)\n", " return income\n", "\n", "convert_income(levels(gss_cat.rincome))" ] }, { "cell_type": "code", "execution_count": 38, "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", "
fn
<category><int64>
0Gt $0.01183
1Gt $10000.01168
2Gt $15000.01048
3Gt $20000.01283
4Gt $25000.07363
5Gt $5000.0970
6Don't know267
7No answer183
8Not applicable7043
9Refused975
\n", "
\n" ], "text/plain": [ " f n\n", " \n", "0 Gt $0.0 1183\n", "1 Gt $10000.0 1168\n", "2 Gt $15000.0 1048\n", "3 Gt $20000.0 1283\n", "4 Gt $25000.0 7363\n", "5 Gt $5000.0 970\n", "6 Don't know 267\n", "7 No answer 183\n", "8 Not applicable 7043\n", "9 Refused 975" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rincome2 = fct_relabel(gss_cat.rincome, convert_income)\n", "fct_count(rincome2)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 2 } ================================================ FILE: docs/notebooks/forcats_misc.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ as_factor
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Convert a vector to a factor vector\n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "\n", "##### Returns:\n", "  The factor vector \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_count
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Count entries in a factor\n", "\n", "##### Args:\n", "  `_f`: A factor \n", "  `sort`: If True, sort the result so that the most common values float to \n", "    the top \n", "\n", "  `prop`: If True, compute the fraction of marginal table. \n", "\n", "##### Returns:\n", "  A data frame with columns `f`, `n` and `p`, if prop is True \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_match
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Test for presence of levels in a factor\n", "\n", "Do any of `lvls` occur in `_f`? \n", "\n", "##### Args:\n", "  `_f`: A factor \n", "  `lvls`: A vector specifying levels to look for. \n", "\n", "##### Returns:\n", "  A logical factor \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ fct_unique
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Unique values of a factor\n", "\n", "##### Args:\n", "  `_f`: A factor \n", "\n", "##### Returns:\n", "  The factor with the unique values in `_f` \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ lvls_reorder
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Leaves values of a factor as they are, but changes the order by\n", "given indices \n", "\n", "##### Args:\n", "  `f`: A factor (or character vector). \n", "  `idx`: A integer index, with one integer for each existing level. \n", "  `new_levels`: A character vector of new levels. \n", "  `ordered`: A logical which determines the \"ordered\" status of the \n", "    output factor. `None` preserves the existing status of the factor. \n", "\n", "##### Returns:\n", "  The factor with levels reordered \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ lvls_revalue
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### changes the values of existing levels; there must\n", "be one new level for each old level \n", "\n", "##### Args:\n", "  `_f`: A factor \n", "  `new_levels`: A character vector of new levels. \n", "\n", "##### Returns:\n", "  The factor with the new levels \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ lvls_expand
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Expands the set of levels; the new levels must\n", "include the old levels. \n", "\n", "##### Args:\n", "  `_f`: A factor \n", "  `new_levels`: The new levels. Must include the old ones \n", "\n", "##### Returns:\n", "  The factor with the new levels \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ lvls_union
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Find all levels in a list of factors\n", "\n", "##### Args:\n", "  `fs`: A list of factors \n", "\n", "##### Returns:\n", "  A list of all levels \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%run nb_helpers.py\n", "\n", "import numpy\n", "from datar.all import *\n", "from datar.data import gss_cat\n", "\n", "\n", "nb_header(\n", " as_factor,\n", " fct_count,\n", " fct_match,\n", " fct_unique,\n", " lvls_reorder,\n", " lvls_revalue,\n", " lvls_expand,\n", " lvls_union,\n", " book=\"forcat_lvl_addrm\",\n", ")\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## as_factor" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a', 'z', 'g']\n", "Categories (3, object): ['a', 'g', 'z']" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = c(\"a\", \"z\", \"g\")\n", "as_factor(x)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['1.1', '11', '2.2', '22']\n", "Categories (4, object): ['1.1', '11', '2.2', '22']" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "y = c(\"1.1\", \"11\", \"2.2\", \"22\")\n", "as_factor(y)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "FutureWarning: Index.ravel returning ndarray is deprecated; in a future version this will return a view on self.\n" ] }, { "data": { "text/plain": [ "[1.1, 11.0, 2.2, 22.0]\n", "Categories (4, float64): [1.1, 2.2, 11.0, 22.0]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "z = as_numeric(y)\n", "as_factor(z)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## fct_count" ] }, { "cell_type": "code", "execution_count": 5, "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", "
bcdeiklmno...qrstuvwxyz
<int64><int64><int64><int64><int64><int64><int64><int64><int64><int64>...<int64><int64><int64><int64><int64><int64><int64><int64><int64><int64>
count88837145672141054...522187491713412872112
\n", "

1 rows × 21 columns

\n", "
\n" ], "text/plain": [ " b c d e i k l m n \\\n", " \n", "count 8 88 37 1 45 67 2 14 105 \n", "\n", " o ... q r s t u v w \\\n", " ... \n", "count 4 5 22 1 87 49 17 134 \n", "\n", " x y z \n", " \n", "count 128 72 112 \n", "\n", "[1 rows x 21 columns]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct = factor(sample(letters)[rpois(1000, 10)])\n", "table(fct)" ] }, { "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fn
<category><int64>
0b8
1c88
2d37
3e1
4i45
5k67
6l2
7m14
8n105
9o4
10p2
11q5
12r22
13s1
14t87
15u49
16v17
17w134
18x128
19y72
20z112
\n", "
\n" ], "text/plain": [ " f n\n", " \n", "0 b 8\n", "1 c 88\n", "2 d 37\n", "3 e 1\n", "4 i 45\n", "5 k 67\n", "6 l 2\n", "7 m 14\n", "8 n 105\n", "9 o 4\n", "10 p 2\n", "11 q 5\n", "12 r 22\n", "13 s 1\n", "14 t 87\n", "15 u 49\n", "16 v 17\n", "17 w 134\n", "18 x 128\n", "19 y 72\n", "20 z 112" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_count(fct)" ] }, { "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", "
fn
<category><int64>
17w134
18x128
20z112
8n105
1c88
14t87
19y72
5k67
15u49
4i45
2d37
12r22
16v17
7m14
0b8
11q5
9o4
6l2
10p2
3e1
13s1
\n", "
\n" ], "text/plain": [ " f n\n", " \n", "17 w 134\n", "18 x 128\n", "20 z 112\n", "8 n 105\n", "1 c 88\n", "14 t 87\n", "19 y 72\n", "5 k 67\n", "15 u 49\n", "4 i 45\n", "2 d 37\n", "12 r 22\n", "16 v 17\n", "7 m 14\n", "0 b 8\n", "11 q 5\n", "9 o 4\n", "6 l 2\n", "10 p 2\n", "3 e 1\n", "13 s 1" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_count(fct, sort = TRUE)" ] }, { "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", "
fnp
<category><int64><float64>
17w1340.134
18x1280.128
20z1120.112
8n1050.105
1c880.088
14t870.087
19y720.072
5k670.067
15u490.049
4i450.045
2d370.037
12r220.022
16v170.017
7m140.014
0b80.008
11q50.005
9o40.004
6l20.002
10p20.002
3e10.001
13s10.001
\n", "
\n" ], "text/plain": [ " f n p\n", " \n", "17 w 134 0.134\n", "18 x 128 0.128\n", "20 z 112 0.112\n", "8 n 105 0.105\n", "1 c 88 0.088\n", "14 t 87 0.087\n", "19 y 72 0.072\n", "5 k 67 0.067\n", "15 u 49 0.049\n", "4 i 45 0.045\n", "2 d 37 0.037\n", "12 r 22 0.022\n", "16 v 17 0.017\n", "7 m 14 0.014\n", "0 b 8 0.008\n", "11 q 5 0.005\n", "9 o 4 0.004\n", "6 l 2 0.002\n", "10 p 2 0.002\n", "3 e 1 0.001\n", "13 s 1 0.001" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_count(fct, sort = TRUE, prop = TRUE)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## fct_match" ] }, { "cell_type": "code", "execution_count": 9, "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", "
FalseTrue
<int64><int64>
count798313500
\n", "
\n" ], "text/plain": [ " False True \n", " \n", "count 7983 13500" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "table(fct_match(gss_cat.marital, c(\"Married\", \"Divorced\")))" ] }, { "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", "
False
<int64>
count21483
\n", "
\n" ], "text/plain": [ " False\n", " \n", "count 21483" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "table(numpy.isin(gss_cat.marital, c(\"Maried\", \"Davorced\")))" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[ValueError] Levels not present in factor: ['Maried' 'Davorced'].\n" ] } ], "source": [ "with try_catch():\n", " table(fct_match(gss_cat.marital, c(\"Maried\", \"Davorced\")))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## fct_unique" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array(['p', 'k', 'i', 'j', 'e', 'r', 'm', 'g', 'n', 'f', 'o', 'h', 'l',\n", " 'd', 'c'], dtype=object)" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct = factor(letters[rpois(100, 10)-1])\n", "\n", "unique(fct)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['c', 'd', 'e', 'f', 'g', ..., 'm', 'n', 'o', 'p', 'r']\n", "Length: 15\n", "Categories (15, object): ['c', 'd', 'e', 'f', ..., 'n', 'o', 'p', 'r']" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct_unique(fct)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## lvls_reorder, lvls_revalue and lvls_expand" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a', 'b', 'c']\n", "Categories (3, object): ['c', 'b', 'a']" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fct = factor(c(\"a\", \"b\", \"c\"))\n", "lvls_reorder(fct, [2,1,0])" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['apple', 'banana', 'carrot']\n", "Categories (3, object): ['apple', 'banana', 'carrot']" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lvls_revalue(fct, c(\"apple\", \"banana\", \"carrot\"))" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a', 'b', 'c']\n", "Categories (4, object): ['a', 'b', 'c', 'd']" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lvls_expand(fct, c(\"a\", \"b\", \"c\", \"d\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## lvls_union" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array(['a', 'b'], dtype=object)" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fs = [factor(\"a\"), factor(\"b\"), factor(c(\"a\", \"b\"))]\n", "lvls_union(fs)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 2 } ================================================ FILE: docs/notebooks/full_seq.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "occasional-onion", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:58.337680Z", "iopub.status.busy": "2021-07-16T22:27:58.336855Z", "iopub.status.idle": "2021-07-16T22:27:59.226466Z", "shell.execute_reply": "2021-07-16T22:27:59.226860Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ full_seq
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Create the full sequence of values in a vector\n", "\n", "##### Args:\n", "  `x`: A numeric vector. \n", "  `period`: Gap between each observation. The existing data will be \n", "    checked to ensure that it is actually of this periodicity. \n", "\n", "  `tol`: Numerical tolerance for checking periodicity. \n", "\n", "##### Returns:\n", "  The full sequence \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://tidyr.tidyverse.org/reference/full_seq.html\n", "%run nb_helpers.py\n", "\n", "from datar.all import *\n", "\n", "nb_header(full_seq)" ] }, { "cell_type": "code", "execution_count": 2, "id": "convenient-professional", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:59.233189Z", "iopub.status.busy": "2021-07-16T22:27:59.232551Z", "iopub.status.idle": "2021-07-16T22:27:59.245528Z", "shell.execute_reply": "2021-07-16T22:27:59.246036Z" } }, "outputs": [ { "data": { "text/plain": [ "array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "full_seq(c(1, 2, 4, 5, 10), 1)" ] }, { "cell_type": "code", "execution_count": null, "id": "ad52e92c", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/group_by.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:13.703680Z", "iopub.status.busy": "2021-07-16T22:27:13.701440Z", "iopub.status.idle": "2021-07-16T22:27:14.914697Z", "shell.execute_reply": "2021-07-16T22:27:14.915141Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ group_by
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Create a grouped frame\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/group_by.html \n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `*args`: A variable or function of variables to group by. \n", "  `_add`: If `True`, add grouping variables to an existing group. \n", "  `_drop`: If `True`, drop grouping variables from the output. \n", "\n", "##### Returns:\n", "  A grouped frame \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ ungroup
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Remove grouping variables\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/ungroup.html \n", "\n", "##### Args:\n", "  `_data`: A grouped frame \n", "  `*cols`: Columns to remove grouping variables from. \n", "\n", "##### Returns:\n", "  A data frame \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/group_by.html\n", "%run nb_helpers.py\n", "\n", "from datar.data import mtcars\n", "from datar.all import *\n", "\n", "nb_header(group_by, ungroup)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:14.976182Z", "iopub.status.busy": "2021-07-16T22:27:14.975600Z", "iopub.status.idle": "2021-07-16T22:27:15.004416Z", "shell.execute_reply": "2021-07-16T22:27:15.004970Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
021.06160.01103.902.62016.460144
121.06160.01103.902.87517.020144
222.84108.0933.852.32018.611141
321.46258.01103.083.21519.441031
418.78360.01753.153.44017.020032
518.16225.01052.763.46020.221031
614.38360.02453.213.57015.840034
724.44146.7623.693.19020.001042
822.84140.8953.923.15022.901042
919.26167.61233.923.44018.301044
1017.86167.61233.923.44018.901044
1116.48275.81803.074.07017.400033
1217.38275.81803.073.73017.600033
1315.28275.81803.073.78018.000033
1410.48472.02052.935.25017.980034
1510.48460.02153.005.42417.820034
1614.78440.02303.235.34517.420034
1732.4478.7664.082.20019.471141
1830.4475.7524.931.61518.521142
1933.9471.1654.221.83519.901141
2021.54120.1973.702.46520.011031
2115.58318.01502.763.52016.870032
2215.28304.01503.153.43517.300032
2313.38350.02453.733.84015.410034
2419.28400.01753.083.84517.050032
2527.3479.0664.081.93518.901141
2626.04120.3914.432.14016.700152
2730.4495.11133.771.51316.901152
2815.88351.02644.223.17014.500154
2919.76145.01753.622.77015.500156
3015.08301.03353.543.57014.600158
3121.44121.01094.112.78018.601142
\n", "
\n", "

TibbleGrouped: cyl (n=3)" ], "text/plain": [ " mpg cyl disp hp drat wt qsec vs \\\n", " \n", "0 21.0 6 160.0 110 3.90 2.620 16.46 0 \n", "1 21.0 6 160.0 110 3.90 2.875 17.02 0 \n", "2 22.8 4 108.0 93 3.85 2.320 18.61 1 \n", "3 21.4 6 258.0 110 3.08 3.215 19.44 1 \n", "4 18.7 8 360.0 175 3.15 3.440 17.02 0 \n", "5 18.1 6 225.0 105 2.76 3.460 20.22 1 \n", "6 14.3 8 360.0 245 3.21 3.570 15.84 0 \n", "7 24.4 4 146.7 62 3.69 3.190 20.00 1 \n", "8 22.8 4 140.8 95 3.92 3.150 22.90 1 \n", "9 19.2 6 167.6 123 3.92 3.440 18.30 1 \n", "10 17.8 6 167.6 123 3.92 3.440 18.90 1 \n", "11 16.4 8 275.8 180 3.07 4.070 17.40 0 \n", "12 17.3 8 275.8 180 3.07 3.730 17.60 0 \n", "13 15.2 8 275.8 180 3.07 3.780 18.00 0 \n", "14 10.4 8 472.0 205 2.93 5.250 17.98 0 \n", "15 10.4 8 460.0 215 3.00 5.424 17.82 0 \n", "16 14.7 8 440.0 230 3.23 5.345 17.42 0 \n", "17 32.4 4 78.7 66 4.08 2.200 19.47 1 \n", "18 30.4 4 75.7 52 4.93 1.615 18.52 1 \n", "19 33.9 4 71.1 65 4.22 1.835 19.90 1 \n", "20 21.5 4 120.1 97 3.70 2.465 20.01 1 \n", "21 15.5 8 318.0 150 2.76 3.520 16.87 0 \n", "22 15.2 8 304.0 150 3.15 3.435 17.30 0 \n", "23 13.3 8 350.0 245 3.73 3.840 15.41 0 \n", "24 19.2 8 400.0 175 3.08 3.845 17.05 0 \n", "25 27.3 4 79.0 66 4.08 1.935 18.90 1 \n", "26 26.0 4 120.3 91 4.43 2.140 16.70 0 \n", "27 30.4 4 95.1 113 3.77 1.513 16.90 1 \n", "28 15.8 8 351.0 264 4.22 3.170 14.50 0 \n", "29 19.7 6 145.0 175 3.62 2.770 15.50 0 \n", "30 15.0 8 301.0 335 3.54 3.570 14.60 0 \n", "31 21.4 4 121.0 109 4.11 2.780 18.60 1 \n", "\n", " am gear carb \n", " \n", "0 1 4 4 \n", "1 1 4 4 \n", "2 1 4 1 \n", "3 0 3 1 \n", "4 0 3 2 \n", "5 0 3 1 \n", "6 0 3 4 \n", "7 0 4 2 \n", "8 0 4 2 \n", "9 0 4 4 \n", "10 0 4 4 \n", "11 0 3 3 \n", "12 0 3 3 \n", "13 0 3 3 \n", "14 0 3 4 \n", "15 0 3 4 \n", "16 0 3 4 \n", "17 1 4 1 \n", "18 1 4 2 \n", "19 1 4 1 \n", "20 0 3 1 \n", "21 0 3 2 \n", "22 0 3 2 \n", "23 0 3 4 \n", "24 0 3 2 \n", "25 1 4 1 \n", "26 1 5 2 \n", "27 1 5 2 \n", "28 1 5 4 \n", "29 1 5 6 \n", "30 1 5 8 \n", "31 1 4 2 \n", "[TibbleGrouped: cyl (n=3)]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "by_cyl = mtcars >> group_by(f.cyl) \n", "by_cyl" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.017114Z", "iopub.status.busy": "2021-07-16T22:27:15.016495Z", "iopub.status.idle": "2021-07-16T22:27:15.049093Z", "shell.execute_reply": "2021-07-16T22:27:15.049650Z" } }, "outputs": [ { "data": { "text/plain": [ "['cyl']" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "by_cyl >> group_vars()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.132668Z", "iopub.status.busy": "2021-07-16T22:27:15.132114Z", "iopub.status.idle": "2021-07-16T22:27:15.177747Z", "shell.execute_reply": "2021-07-16T22:27:15.178134Z" } }, "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", "
cyldisphp
<int64><float64><float64>
06183.314286122.285714
14105.13636482.636364
28353.100000209.214286
\n", "
\n" ], "text/plain": [ " cyl disp hp\n", " \n", "0 6 183.314286 122.285714\n", "1 4 105.136364 82.636364\n", "2 8 353.100000 209.214286" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "by_cyl >> summarise(\n", " disp = mean(f.disp),\n", " hp = mean(f.hp)\n", ")" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.229676Z", "iopub.status.busy": "2021-07-16T22:27:15.229126Z", "iopub.status.idle": "2021-07-16T22:27:15.281912Z", "shell.execute_reply": "2021-07-16T22:27:15.282358Z" } }, "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", "
cyldisphp
<int64><float64><float64>
06183.314286122.285714
14105.13636482.636364
28353.100000209.214286
\n", "
\n" ], "text/plain": [ " cyl disp hp\n", " \n", "0 6 183.314286 122.285714\n", "1 4 105.136364 82.636364\n", "2 8 353.100000 209.214286" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "by_cyl >> summarise(\n", " disp = f.disp.mean(),\n", " hp = f.hp.mean()\n", ")" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.443180Z", "iopub.status.busy": "2021-07-16T22:27:15.442440Z", "iopub.status.idle": "2021-07-16T22:27:15.529983Z", "shell.execute_reply": "2021-07-16T22:27:15.530485Z" } }, "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", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
021.46258.01103.083.21519.441031
124.44146.7623.693.19020.001042
210.48472.02052.935.25017.980034
\n", "
\n", "

TibbleGrouped: cyl (n=3)" ], "text/plain": [ " mpg cyl disp hp drat wt qsec vs \\\n", " \n", "0 21.4 6 258.0 110 3.08 3.215 19.44 1 \n", "1 24.4 4 146.7 62 3.69 3.190 20.00 1 \n", "2 10.4 8 472.0 205 2.93 5.250 17.98 0 \n", "\n", " am gear carb \n", " \n", "0 0 3 1 \n", "1 0 4 2 \n", "2 0 3 4 \n", "[TibbleGrouped: cyl (n=3)]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "by_cyl >> filter(f.disp == max(f.disp))" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.614261Z", "iopub.status.busy": "2021-07-16T22:27:15.613607Z", "iopub.status.idle": "2021-07-16T22:27:15.648443Z", "shell.execute_reply": "2021-07-16T22:27:15.648848Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 14:03:28][datar][ INFO] `summarise()` has grouped output by ['vs'] (override with `_groups` argument)\n" ] }, { "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", "
vsamn
<int64><int64><int64>
0016
1117
2107
30012
\n", "
\n", "

TibbleGrouped: vs (n=2)" ], "text/plain": [ " vs am n\n", " \n", "0 0 1 6\n", "1 1 1 7\n", "2 1 0 7\n", "3 0 0 12\n", "[TibbleGrouped: vs (n=2)]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "by_vs_am = mtcars >> group_by(f.vs, f.am)\n", "by_vs = by_vs_am >> summarise(n=n())\n", "by_vs" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.669009Z", "iopub.status.busy": "2021-07-16T22:27:15.668452Z", "iopub.status.idle": "2021-07-16T22:27:15.690146Z", "shell.execute_reply": "2021-07-16T22:27:15.690536Z" } }, "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", "
vsn
<int64><int64>
0018
1114
\n", "
\n" ], "text/plain": [ " vs n\n", " \n", "0 0 18\n", "1 1 14" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "by_vs >> summarise(n=sum(f.n))" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.710665Z", "iopub.status.busy": "2021-07-16T22:27:15.710003Z", "iopub.status.idle": "2021-07-16T22:27:15.738089Z", "shell.execute_reply": "2021-07-16T22:27:15.738657Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
n
<int64>
032
\n", "
\n" ], "text/plain": [ " n\n", " \n", "0 32" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "by_vs >> \\\n", " ungroup() >> \\\n", " summarise(n = sum(f.n))" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.786635Z", "iopub.status.busy": "2021-07-16T22:27:15.785325Z", "iopub.status.idle": "2021-07-16T22:27:15.800853Z", "shell.execute_reply": "2021-07-16T22:27:15.801238Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
mpgcyldisphpdratwtqsecvsamgearcarbvsam
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64><int64>
021.06160.01103.902.62016.4601441
121.06160.01103.902.87517.0201441
222.84108.0933.852.32018.6111412
321.46258.01103.083.21519.4410311
418.78360.01753.153.44017.0200320
518.16225.01052.763.46020.2210311
614.38360.02453.213.57015.8400340
724.44146.7623.693.19020.0010421
822.84140.8953.923.15022.9010421
919.26167.61233.923.44018.3010441
1017.86167.61233.923.44018.9010441
1116.48275.81803.074.07017.4000330
1217.38275.81803.073.73017.6000330
1315.28275.81803.073.78018.0000330
1410.48472.02052.935.25017.9800340
1510.48460.02153.005.42417.8200340
1614.78440.02303.235.34517.4200340
1732.4478.7664.082.20019.4711412
1830.4475.7524.931.61518.5211422
1933.9471.1654.221.83519.9011412
2021.54120.1973.702.46520.0110311
2115.58318.01502.763.52016.8700320
2215.28304.01503.153.43517.3000320
2313.38350.02453.733.84015.4100340
2419.28400.01753.083.84517.0500320
2527.3479.0664.081.93518.9011412
2626.04120.3914.432.14016.7001521
2730.4495.11133.771.51316.9011522
2815.88351.02644.223.17014.5001541
2919.76145.01753.622.77015.5001561
3015.08301.03353.543.57014.6001581
3121.44121.01094.112.78018.6011422
\n", "
\n", "

TibbleGrouped: vsam (n=3)" ], "text/plain": [ " mpg cyl disp hp drat wt qsec vs \\\n", " \n", "0 21.0 6 160.0 110 3.90 2.620 16.46 0 \n", "1 21.0 6 160.0 110 3.90 2.875 17.02 0 \n", "2 22.8 4 108.0 93 3.85 2.320 18.61 1 \n", "3 21.4 6 258.0 110 3.08 3.215 19.44 1 \n", "4 18.7 8 360.0 175 3.15 3.440 17.02 0 \n", "5 18.1 6 225.0 105 2.76 3.460 20.22 1 \n", "6 14.3 8 360.0 245 3.21 3.570 15.84 0 \n", "7 24.4 4 146.7 62 3.69 3.190 20.00 1 \n", "8 22.8 4 140.8 95 3.92 3.150 22.90 1 \n", "9 19.2 6 167.6 123 3.92 3.440 18.30 1 \n", "10 17.8 6 167.6 123 3.92 3.440 18.90 1 \n", "11 16.4 8 275.8 180 3.07 4.070 17.40 0 \n", "12 17.3 8 275.8 180 3.07 3.730 17.60 0 \n", "13 15.2 8 275.8 180 3.07 3.780 18.00 0 \n", "14 10.4 8 472.0 205 2.93 5.250 17.98 0 \n", "15 10.4 8 460.0 215 3.00 5.424 17.82 0 \n", "16 14.7 8 440.0 230 3.23 5.345 17.42 0 \n", "17 32.4 4 78.7 66 4.08 2.200 19.47 1 \n", "18 30.4 4 75.7 52 4.93 1.615 18.52 1 \n", "19 33.9 4 71.1 65 4.22 1.835 19.90 1 \n", "20 21.5 4 120.1 97 3.70 2.465 20.01 1 \n", "21 15.5 8 318.0 150 2.76 3.520 16.87 0 \n", "22 15.2 8 304.0 150 3.15 3.435 17.30 0 \n", "23 13.3 8 350.0 245 3.73 3.840 15.41 0 \n", "24 19.2 8 400.0 175 3.08 3.845 17.05 0 \n", "25 27.3 4 79.0 66 4.08 1.935 18.90 1 \n", "26 26.0 4 120.3 91 4.43 2.140 16.70 0 \n", "27 30.4 4 95.1 113 3.77 1.513 16.90 1 \n", "28 15.8 8 351.0 264 4.22 3.170 14.50 0 \n", "29 19.7 6 145.0 175 3.62 2.770 15.50 0 \n", "30 15.0 8 301.0 335 3.54 3.570 14.60 0 \n", "31 21.4 4 121.0 109 4.11 2.780 18.60 1 \n", "\n", " am gear carb vsam \n", " \n", "0 1 4 4 1 \n", "1 1 4 4 1 \n", "2 1 4 1 2 \n", "3 0 3 1 1 \n", "4 0 3 2 0 \n", "5 0 3 1 1 \n", "6 0 3 4 0 \n", "7 0 4 2 1 \n", "8 0 4 2 1 \n", "9 0 4 4 1 \n", "10 0 4 4 1 \n", "11 0 3 3 0 \n", "12 0 3 3 0 \n", "13 0 3 3 0 \n", "14 0 3 4 0 \n", "15 0 3 4 0 \n", "16 0 3 4 0 \n", "17 1 4 1 2 \n", "18 1 4 2 2 \n", "19 1 4 1 2 \n", "20 0 3 1 1 \n", "21 0 3 2 0 \n", "22 0 3 2 0 \n", "23 0 3 4 0 \n", "24 0 3 2 0 \n", "25 1 4 1 2 \n", "26 1 5 2 1 \n", "27 1 5 2 2 \n", "28 1 5 4 1 \n", "29 1 5 6 1 \n", "30 1 5 8 1 \n", "31 1 4 2 2 \n", "[TibbleGrouped: vsam (n=3)]" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars_vsam = mtcars >> group_by(vsam=f.vs + f.am) \n", "mtcars_vsam " ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.816915Z", "iopub.status.busy": "2021-07-16T22:27:15.816370Z", "iopub.status.idle": "2021-07-16T22:27:15.831042Z", "shell.execute_reply": "2021-07-16T22:27:15.831483Z" } }, "outputs": [ { "data": { "text/plain": [ "['vs', 'am']" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "by_cyl >> \\\n", " group_by(f.vs, f.am) >> \\\n", " group_vars()" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.852030Z", "iopub.status.busy": "2021-07-16T22:27:15.851473Z", "iopub.status.idle": "2021-07-16T22:27:15.897903Z", "shell.execute_reply": "2021-07-16T22:27:15.898295Z" } }, "outputs": [ { "data": { "text/plain": [ "['cyl', 'vs', 'am']" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "by_cyl >> \\\n", " group_by(f.vs, f.am, _add=True) >> \\\n", " group_vars()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 4 } ================================================ FILE: docs/notebooks/group_map.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 2, "id": "57a3cb89", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:15.978059Z", "iopub.status.busy": "2021-07-16T22:28:15.977453Z", "iopub.status.idle": "2021-07-16T22:28:17.260200Z", "shell.execute_reply": "2021-07-16T22:28:17.260642Z" } }, "outputs": [ { "data": { "text/html": [ "

Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ group_map
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Apply a function to each group\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/group_map.html \n", "\n", "##### Args:\n", "  `_data`: A grouped frame \n", "  `_f`: A function to apply to each group. \n", "  `*args`: Additional arguments to pass to `func`. \n", "  `_keep`: If `True`, keep the grouping variables in the output. \n", "  `**kwargs`: Additional keyword arguments to pass to `func`. \n", "\n", "##### Returns:\n", "  A list of results \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/group_map.html\n", "%run nb_helpers.py\n", "\n", "from datar.data import mtcars, iris\n", "from datar.all import *\n", "\n", "nb_header(group_map)" ] }, { "cell_type": "code", "execution_count": 3, "id": "8dae4674", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:17.269961Z", "iopub.status.busy": "2021-07-16T22:28:17.269298Z", "iopub.status.idle": "2021-07-16T22:28:17.374049Z", "shell.execute_reply": "2021-07-16T22:28:17.374622Z" } }, "outputs": [ { "data": { "text/plain": [ "[ mpg disp hp drat ... vs am gear carb\n", " ... \n", " 0 21.0 160.0 110 3.9 ... 0 1 4 4\n", " 1 21.0 160.0 110 3.9 0 1 4 4\n", " \n", " [2 rows x 10 columns],\n", " mpg disp hp drat ... vs am gear carb\n", " ... \n", " 0 22.8 108.0 93 3.85 ... 1 1 4 1\n", " 1 24.4 146.7 62 3.69 1 0 4 2\n", " \n", " [2 rows x 10 columns],\n", " mpg disp hp drat ... vs am gear carb\n", " ... \n", " 0 18.7 360.0 175 3.15 ... 0 0 3 2\n", " 1 14.3 360.0 245 3.21 0 0 3 4\n", " \n", " [2 rows x 10 columns]]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list(\n", " mtcars >> \\\n", " group_by(f.cyl) >> \\\n", " group_map(lambda df: df >> head(2))\n", ")\n" ] }, { "cell_type": "code", "execution_count": 4, "id": "3dd99448", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:17.471163Z", "iopub.status.busy": "2021-07-16T22:28:17.469789Z", "iopub.status.idle": "2021-07-16T22:28:17.656298Z", "shell.execute_reply": "2021-07-16T22:28:17.656823Z" } }, "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", "
cylmpgdisphpdratwtqsecvsamgearcarb
<int64><float64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
0621.0160.01103.902.62016.460144
1621.0160.01103.902.87517.020144
0422.8108.0933.852.32018.611141
1424.4146.7623.693.19020.001042
0818.7360.01753.153.44017.020032
1814.3360.02453.213.57015.840034
\n", "
\n", "

TibbleGrouped: cyl (n=3)" ], "text/plain": [ " cyl mpg disp hp ... vs am gear carb\n", " ... \n", "0 6 21.0 160.0 110 ... 0 1 4 4\n", "1 6 21.0 160.0 110 ... 0 1 4 4\n", "0 4 22.8 108.0 93 ... 1 1 4 1\n", "1 4 24.4 146.7 62 ... 1 0 4 2\n", "0 8 18.7 360.0 175 ... 0 0 3 2\n", "1 8 14.3 360.0 245 0 0 3 4\n", "\n", "[6 rows x 11 columns]\n", "[TibbleGrouped: cyl (n=3)]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "mtcars >> \\\n", " group_by(f.cyl) >> \\\n", " group_modify(lambda df: df >> head(2))" ] }, { "cell_type": "code", "execution_count": 5, "id": "9713979f", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:17.705307Z", "iopub.status.busy": "2021-07-16T22:28:17.704323Z", "iopub.status.idle": "2021-07-16T22:28:17.736655Z", "shell.execute_reply": "2021-07-16T22:28:17.733142Z" } }, "outputs": [ { "data": { "text/plain": [ "[array([1.4 , 1.5 , 1.575]),\n", " array([4. , 4.35, 4.6 ]),\n", " array([5.1 , 5.55 , 5.875])]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list(\n", " iris >> \\\n", " group_by(f.Species) >> \\\n", " group_map(lambda df: quantile(df['Petal_Length'], probs=c(0.25, 0.5, 0.75)))\n", ")" ] }, { "cell_type": "code", "execution_count": 6, "id": "f1da70a0", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:17.775636Z", "iopub.status.busy": "2021-07-16T22:28:17.774540Z", "iopub.status.idle": "2021-07-16T22:28:17.786685Z", "shell.execute_reply": "2021-07-16T22:28:17.787352Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(50, 4)\n", "(50, 4)\n", "(50, 4)\n" ] } ], "source": [ "iris >> \\\n", " group_by(f.Species) >> \\\n", " group_walk(lambda df: print(df.shape))" ] }, { "cell_type": "code", "execution_count": 7, "id": "fe130860", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:17.821207Z", "iopub.status.busy": "2021-07-16T22:28:17.820364Z", "iopub.status.idle": "2021-07-16T22:28:17.836773Z", "shell.execute_reply": "2021-07-16T22:28:17.837212Z" } }, "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", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Mazda RX421.06160.01103.92.62016.460144
Mazda RX4 Wag21.06160.01103.92.87517.020144
\n", "
\n" ], "text/plain": [ " mpg cyl disp ... am gear carb\n", " ... \n", "Mazda RX4 21.0 6 160.0 ... 1 4 4\n", "Mazda RX4 Wag 21.0 6 160.0 1 4 4\n", "\n", "[2 rows x 11 columns]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> \\\n", " group_modify(lambda df: df >> head(2))" ] }, { "cell_type": "code", "execution_count": null, "id": "af50d40c", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/group_split.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "47292892", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:52.255547Z", "iopub.status.busy": "2021-07-16T22:27:52.254748Z", "iopub.status.idle": "2021-07-16T22:27:53.206679Z", "shell.execute_reply": "2021-07-16T22:27:53.207313Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ group_split
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Split a grouped frame into a list of data frames\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/group_split.html \n", "\n", "##### Args:\n", "  `_data`: A grouped frame \n", "  `*args`: Additional arguments to pass to `func`. \n", "  `_keep`: If `True`, keep the grouping variables in the output. \n", "  `**kwargs`: Additional keyword arguments to pass to `func`. \n", "\n", "##### Returns:\n", "  A list of data frames \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/group_split.html\n", "%run nb_helpers.py\n", "\n", "from datar.data import iris\n", "from datar.all import *\n", "\n", "nb_header(group_split)" ] }, { "cell_type": "code", "execution_count": 2, "id": "a2008be0", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.213365Z", "iopub.status.busy": "2021-07-16T22:27:53.212184Z", "iopub.status.idle": "2021-07-16T22:27:53.288326Z", "shell.execute_reply": "2021-07-16T22:27:53.287655Z" } }, "outputs": [ { "data": { "text/plain": [ "[ Sepal_Length Sepal_Width Petal_Length Petal_Width Species\n", " \n", " 0 5.1 3.5 1.4 0.2 setosa\n", " 1 4.9 3.0 1.4 0.2 setosa\n", " 2 4.7 3.2 1.3 0.2 setosa\n", " 3 4.6 3.1 1.5 0.2 setosa\n", " 4 5.0 3.6 1.4 0.2 setosa\n", " 5 5.4 3.9 1.7 0.4 setosa\n", " 6 4.6 3.4 1.4 0.3 setosa\n", " 7 5.0 3.4 1.5 0.2 setosa\n", " 8 4.4 2.9 1.4 0.2 setosa\n", " 9 4.9 3.1 1.5 0.1 setosa\n", " 10 5.4 3.7 1.5 0.2 setosa\n", " 11 4.8 3.4 1.6 0.2 setosa\n", " 12 4.8 3.0 1.4 0.1 setosa\n", " 13 4.3 3.0 1.1 0.1 setosa\n", " 14 5.8 4.0 1.2 0.2 setosa\n", " 15 5.7 4.4 1.5 0.4 setosa\n", " 16 5.4 3.9 1.3 0.4 setosa\n", " 17 5.1 3.5 1.4 0.3 setosa\n", " 18 5.7 3.8 1.7 0.3 setosa\n", " 19 5.1 3.8 1.5 0.3 setosa\n", " 20 5.4 3.4 1.7 0.2 setosa\n", " 21 5.1 3.7 1.5 0.4 setosa\n", " 22 4.6 3.6 1.0 0.2 setosa\n", " 23 5.1 3.3 1.7 0.5 setosa\n", " 24 4.8 3.4 1.9 0.2 setosa\n", " 25 5.0 3.0 1.6 0.2 setosa\n", " 26 5.0 3.4 1.6 0.4 setosa\n", " 27 5.2 3.5 1.5 0.2 setosa\n", " 28 5.2 3.4 1.4 0.2 setosa\n", " 29 4.7 3.2 1.6 0.2 setosa\n", " 30 4.8 3.1 1.6 0.2 setosa\n", " 31 5.4 3.4 1.5 0.4 setosa\n", " 32 5.2 4.1 1.5 0.1 setosa\n", " 33 5.5 4.2 1.4 0.2 setosa\n", " 34 4.9 3.1 1.5 0.2 setosa\n", " 35 5.0 3.2 1.2 0.2 setosa\n", " 36 5.5 3.5 1.3 0.2 setosa\n", " 37 4.9 3.6 1.4 0.1 setosa\n", " 38 4.4 3.0 1.3 0.2 setosa\n", " 39 5.1 3.4 1.5 0.2 setosa\n", " 40 5.0 3.5 1.3 0.3 setosa\n", " 41 4.5 2.3 1.3 0.3 setosa\n", " 42 4.4 3.2 1.3 0.2 setosa\n", " 43 5.0 3.5 1.6 0.6 setosa\n", " 44 5.1 3.8 1.9 0.4 setosa\n", " 45 4.8 3.0 1.4 0.3 setosa\n", " 46 5.1 3.8 1.6 0.2 setosa\n", " 47 4.6 3.2 1.4 0.2 setosa\n", " 48 5.3 3.7 1.5 0.2 setosa\n", " 49 5.0 3.3 1.4 0.2 setosa,\n", " Sepal_Length Sepal_Width Petal_Length Petal_Width Species\n", " \n", " 0 7.0 3.2 4.7 1.4 versicolor\n", " 1 6.4 3.2 4.5 1.5 versicolor\n", " 2 6.9 3.1 4.9 1.5 versicolor\n", " 3 5.5 2.3 4.0 1.3 versicolor\n", " 4 6.5 2.8 4.6 1.5 versicolor\n", " 5 5.7 2.8 4.5 1.3 versicolor\n", " 6 6.3 3.3 4.7 1.6 versicolor\n", " 7 4.9 2.4 3.3 1.0 versicolor\n", " 8 6.6 2.9 4.6 1.3 versicolor\n", " 9 5.2 2.7 3.9 1.4 versicolor\n", " 10 5.0 2.0 3.5 1.0 versicolor\n", " 11 5.9 3.0 4.2 1.5 versicolor\n", " 12 6.0 2.2 4.0 1.0 versicolor\n", " 13 6.1 2.9 4.7 1.4 versicolor\n", " 14 5.6 2.9 3.6 1.3 versicolor\n", " 15 6.7 3.1 4.4 1.4 versicolor\n", " 16 5.6 3.0 4.5 1.5 versicolor\n", " 17 5.8 2.7 4.1 1.0 versicolor\n", " 18 6.2 2.2 4.5 1.5 versicolor\n", " 19 5.6 2.5 3.9 1.1 versicolor\n", " 20 5.9 3.2 4.8 1.8 versicolor\n", " 21 6.1 2.8 4.0 1.3 versicolor\n", " 22 6.3 2.5 4.9 1.5 versicolor\n", " 23 6.1 2.8 4.7 1.2 versicolor\n", " 24 6.4 2.9 4.3 1.3 versicolor\n", " 25 6.6 3.0 4.4 1.4 versicolor\n", " 26 6.8 2.8 4.8 1.4 versicolor\n", " 27 6.7 3.0 5.0 1.7 versicolor\n", " 28 6.0 2.9 4.5 1.5 versicolor\n", " 29 5.7 2.6 3.5 1.0 versicolor\n", " 30 5.5 2.4 3.8 1.1 versicolor\n", " 31 5.5 2.4 3.7 1.0 versicolor\n", " 32 5.8 2.7 3.9 1.2 versicolor\n", " 33 6.0 2.7 5.1 1.6 versicolor\n", " 34 5.4 3.0 4.5 1.5 versicolor\n", " 35 6.0 3.4 4.5 1.6 versicolor\n", " 36 6.7 3.1 4.7 1.5 versicolor\n", " 37 6.3 2.3 4.4 1.3 versicolor\n", " 38 5.6 3.0 4.1 1.3 versicolor\n", " 39 5.5 2.5 4.0 1.3 versicolor\n", " 40 5.5 2.6 4.4 1.2 versicolor\n", " 41 6.1 3.0 4.6 1.4 versicolor\n", " 42 5.8 2.6 4.0 1.2 versicolor\n", " 43 5.0 2.3 3.3 1.0 versicolor\n", " 44 5.6 2.7 4.2 1.3 versicolor\n", " 45 5.7 3.0 4.2 1.2 versicolor\n", " 46 5.7 2.9 4.2 1.3 versicolor\n", " 47 6.2 2.9 4.3 1.3 versicolor\n", " 48 5.1 2.5 3.0 1.1 versicolor\n", " 49 5.7 2.8 4.1 1.3 versicolor,\n", " Sepal_Length Sepal_Width Petal_Length Petal_Width Species\n", " \n", " 0 6.3 3.3 6.0 2.5 virginica\n", " 1 5.8 2.7 5.1 1.9 virginica\n", " 2 7.1 3.0 5.9 2.1 virginica\n", " 3 6.3 2.9 5.6 1.8 virginica\n", " 4 6.5 3.0 5.8 2.2 virginica\n", " 5 7.6 3.0 6.6 2.1 virginica\n", " 6 4.9 2.5 4.5 1.7 virginica\n", " 7 7.3 2.9 6.3 1.8 virginica\n", " 8 6.7 2.5 5.8 1.8 virginica\n", " 9 7.2 3.6 6.1 2.5 virginica\n", " 10 6.5 3.2 5.1 2.0 virginica\n", " 11 6.4 2.7 5.3 1.9 virginica\n", " 12 6.8 3.0 5.5 2.1 virginica\n", " 13 5.7 2.5 5.0 2.0 virginica\n", " 14 5.8 2.8 5.1 2.4 virginica\n", " 15 6.4 3.2 5.3 2.3 virginica\n", " 16 6.5 3.0 5.5 1.8 virginica\n", " 17 7.7 3.8 6.7 2.2 virginica\n", " 18 7.7 2.6 6.9 2.3 virginica\n", " 19 6.0 2.2 5.0 1.5 virginica\n", " 20 6.9 3.2 5.7 2.3 virginica\n", " 21 5.6 2.8 4.9 2.0 virginica\n", " 22 7.7 2.8 6.7 2.0 virginica\n", " 23 6.3 2.7 4.9 1.8 virginica\n", " 24 6.7 3.3 5.7 2.1 virginica\n", " 25 7.2 3.2 6.0 1.8 virginica\n", " 26 6.2 2.8 4.8 1.8 virginica\n", " 27 6.1 3.0 4.9 1.8 virginica\n", " 28 6.4 2.8 5.6 2.1 virginica\n", " 29 7.2 3.0 5.8 1.6 virginica\n", " 30 7.4 2.8 6.1 1.9 virginica\n", " 31 7.9 3.8 6.4 2.0 virginica\n", " 32 6.4 2.8 5.6 2.2 virginica\n", " 33 6.3 2.8 5.1 1.5 virginica\n", " 34 6.1 2.6 5.6 1.4 virginica\n", " 35 7.7 3.0 6.1 2.3 virginica\n", " 36 6.3 3.4 5.6 2.4 virginica\n", " 37 6.4 3.1 5.5 1.8 virginica\n", " 38 6.0 3.0 4.8 1.8 virginica\n", " 39 6.9 3.1 5.4 2.1 virginica\n", " 40 6.7 3.1 5.6 2.4 virginica\n", " 41 6.9 3.1 5.1 2.3 virginica\n", " 42 5.8 2.7 5.1 1.9 virginica\n", " 43 6.8 3.2 5.9 2.3 virginica\n", " 44 6.7 3.3 5.7 2.5 virginica\n", " 45 6.7 3.0 5.2 2.3 virginica\n", " 46 6.3 2.5 5.0 1.9 virginica\n", " 47 6.5 3.0 5.2 2.0 virginica\n", " 48 6.2 3.4 5.4 2.3 virginica\n", " 49 5.9 3.0 5.1 1.8 virginica]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ir = iris >> group_by(f.Species)\n", "\n", "list(group_split(ir))" ] }, { "cell_type": "code", "execution_count": 3, "id": "3ec457eb", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.300912Z", "iopub.status.busy": "2021-07-16T22:27:53.300148Z", "iopub.status.idle": "2021-07-16T22:27:53.304391Z", "shell.execute_reply": "2021-07-16T22:27:53.303877Z" } }, "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", "
Species
<object>
0setosa
1versicolor
2virginica
\n", "
\n" ], "text/plain": [ " Species\n", " \n", "0 setosa\n", "1 versicolor\n", "2 virginica" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "group_keys(ir)" ] }, { "cell_type": "code", "execution_count": 4, "id": "495b5d8c", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.320666Z", "iopub.status.busy": "2021-07-16T22:27:53.320074Z", "iopub.status.idle": "2021-07-16T22:27:53.451293Z", "shell.execute_reply": "2021-07-16T22:27:53.450611Z" } }, "outputs": [ { "data": { "text/plain": [ "[ Sepal_Length Sepal_Width Petal_Length Petal_Width Species\n", " \n", " 0 5.1 3.5 1.4 0.2 setosa\n", " 1 5.4 3.9 1.7 0.4 setosa\n", " 2 5.4 3.7 1.5 0.2 setosa\n", " 3 5.8 4.0 1.2 0.2 setosa\n", " 4 5.7 4.4 1.5 0.4 setosa\n", " 5 5.4 3.9 1.3 0.4 setosa\n", " 6 5.1 3.5 1.4 0.3 setosa\n", " 7 5.7 3.8 1.7 0.3 setosa\n", " 8 5.1 3.8 1.5 0.3 setosa\n", " 9 5.4 3.4 1.7 0.2 setosa\n", " 10 5.1 3.7 1.5 0.4 setosa\n", " 11 5.1 3.3 1.7 0.5 setosa\n", " 12 5.2 3.5 1.5 0.2 setosa\n", " 13 5.2 3.4 1.4 0.2 setosa\n", " 14 5.4 3.4 1.5 0.4 setosa\n", " 15 5.2 4.1 1.5 0.1 setosa\n", " 16 5.5 4.2 1.4 0.2 setosa\n", " 17 5.5 3.5 1.3 0.2 setosa\n", " 18 5.1 3.4 1.5 0.2 setosa\n", " 19 5.1 3.8 1.9 0.4 setosa\n", " 20 5.1 3.8 1.6 0.2 setosa\n", " 21 5.3 3.7 1.5 0.2 setosa,\n", " Sepal_Length Sepal_Width Petal_Length Petal_Width Species\n", " \n", " 0 7.0 3.2 4.7 1.4 versicolor\n", " 1 6.4 3.2 4.5 1.5 versicolor\n", " 2 6.9 3.1 4.9 1.5 versicolor\n", " 3 6.5 2.8 4.6 1.5 versicolor\n", " 4 6.3 3.3 4.7 1.6 versicolor\n", " 5 6.6 2.9 4.6 1.3 versicolor\n", " 6 6.0 2.2 4.0 1.0 versicolor\n", " 7 6.1 2.9 4.7 1.4 versicolor\n", " 8 6.7 3.1 4.4 1.4 versicolor\n", " 9 6.2 2.2 4.5 1.5 versicolor\n", " 10 6.1 2.8 4.0 1.3 versicolor\n", " 11 6.3 2.5 4.9 1.5 versicolor\n", " 12 6.1 2.8 4.7 1.2 versicolor\n", " 13 6.4 2.9 4.3 1.3 versicolor\n", " 14 6.6 3.0 4.4 1.4 versicolor\n", " 15 6.8 2.8 4.8 1.4 versicolor\n", " 16 6.7 3.0 5.0 1.7 versicolor\n", " 17 6.0 2.9 4.5 1.5 versicolor\n", " 18 6.0 2.7 5.1 1.6 versicolor\n", " 19 6.0 3.4 4.5 1.6 versicolor\n", " 20 6.7 3.1 4.7 1.5 versicolor\n", " 21 6.3 2.3 4.4 1.3 versicolor\n", " 22 6.1 3.0 4.6 1.4 versicolor\n", " 23 6.2 2.9 4.3 1.3 versicolor,\n", " Sepal_Length Sepal_Width Petal_Length Petal_Width Species\n", " \n", " 0 7.1 3.0 5.9 2.1 virginica\n", " 1 7.6 3.0 6.6 2.1 virginica\n", " 2 7.3 2.9 6.3 1.8 virginica\n", " 3 6.7 2.5 5.8 1.8 virginica\n", " 4 7.2 3.6 6.1 2.5 virginica\n", " 5 6.8 3.0 5.5 2.1 virginica\n", " 6 7.7 3.8 6.7 2.2 virginica\n", " 7 7.7 2.6 6.9 2.3 virginica\n", " 8 6.9 3.2 5.7 2.3 virginica\n", " 9 7.7 2.8 6.7 2.0 virginica\n", " 10 6.7 3.3 5.7 2.1 virginica\n", " 11 7.2 3.2 6.0 1.8 virginica\n", " 12 7.2 3.0 5.8 1.6 virginica\n", " 13 7.4 2.8 6.1 1.9 virginica\n", " 14 7.9 3.8 6.4 2.0 virginica\n", " 15 7.7 3.0 6.1 2.3 virginica\n", " 16 6.9 3.1 5.4 2.1 virginica\n", " 17 6.7 3.1 5.6 2.4 virginica\n", " 18 6.9 3.1 5.1 2.3 virginica\n", " 19 6.8 3.2 5.9 2.3 virginica\n", " 20 6.7 3.3 5.7 2.5 virginica\n", " 21 6.7 3.0 5.2 2.3 virginica]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ir = iris >> \\\n", " group_by(f.Species) >> \\\n", " filter(f['Sepal_Length'] > mean(f['Sepal_Length']))\n", "list(group_split(ir))" ] }, { "cell_type": "code", "execution_count": 5, "id": "250034b0", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.458909Z", "iopub.status.busy": "2021-07-16T22:27:53.458364Z", "iopub.status.idle": "2021-07-16T22:27:53.461501Z", "shell.execute_reply": "2021-07-16T22:27:53.461898Z" } }, "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", "
Species
<object>
0setosa
1versicolor
2virginica
\n", "
\n" ], "text/plain": [ " Species\n", " \n", "0 setosa\n", "1 versicolor\n", "2 virginica" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "group_keys(ir)" ] }, { "cell_type": "code", "execution_count": 6, "id": "a9d564a6", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.504622Z", "iopub.status.busy": "2021-07-16T22:27:53.504035Z", "iopub.status.idle": "2021-07-16T22:27:53.507391Z", "shell.execute_reply": "2021-07-16T22:27:53.507943Z" } }, "outputs": [ { "data": { "text/plain": [ "[ Sepal_Length Sepal_Width Petal_Length Petal_Width Species\n", " \n", " 0 5.1 3.5 1.4 0.2 setosa\n", " 1 4.9 3.0 1.4 0.2 setosa\n", " 2 4.7 3.2 1.3 0.2 setosa\n", " 3 4.6 3.1 1.5 0.2 setosa\n", " 4 5.0 3.6 1.4 0.2 setosa\n", " 5 5.4 3.9 1.7 0.4 setosa\n", " 6 4.6 3.4 1.4 0.3 setosa\n", " 7 5.0 3.4 1.5 0.2 setosa\n", " 8 4.4 2.9 1.4 0.2 setosa\n", " 9 4.9 3.1 1.5 0.1 setosa\n", " 10 5.4 3.7 1.5 0.2 setosa\n", " 11 4.8 3.4 1.6 0.2 setosa\n", " 12 4.8 3.0 1.4 0.1 setosa\n", " 13 4.3 3.0 1.1 0.1 setosa\n", " 14 5.8 4.0 1.2 0.2 setosa\n", " 15 5.7 4.4 1.5 0.4 setosa\n", " 16 5.4 3.9 1.3 0.4 setosa\n", " 17 5.1 3.5 1.4 0.3 setosa\n", " 18 5.7 3.8 1.7 0.3 setosa\n", " 19 5.1 3.8 1.5 0.3 setosa\n", " 20 5.4 3.4 1.7 0.2 setosa\n", " 21 5.1 3.7 1.5 0.4 setosa\n", " 22 4.6 3.6 1.0 0.2 setosa\n", " 23 5.1 3.3 1.7 0.5 setosa\n", " 24 4.8 3.4 1.9 0.2 setosa\n", " 25 5.0 3.0 1.6 0.2 setosa\n", " 26 5.0 3.4 1.6 0.4 setosa\n", " 27 5.2 3.5 1.5 0.2 setosa\n", " 28 5.2 3.4 1.4 0.2 setosa\n", " 29 4.7 3.2 1.6 0.2 setosa\n", " 30 4.8 3.1 1.6 0.2 setosa\n", " 31 5.4 3.4 1.5 0.4 setosa\n", " 32 5.2 4.1 1.5 0.1 setosa\n", " 33 5.5 4.2 1.4 0.2 setosa\n", " 34 4.9 3.1 1.5 0.2 setosa\n", " 35 5.0 3.2 1.2 0.2 setosa\n", " 36 5.5 3.5 1.3 0.2 setosa\n", " 37 4.9 3.6 1.4 0.1 setosa\n", " 38 4.4 3.0 1.3 0.2 setosa\n", " 39 5.1 3.4 1.5 0.2 setosa\n", " 40 5.0 3.5 1.3 0.3 setosa\n", " 41 4.5 2.3 1.3 0.3 setosa\n", " 42 4.4 3.2 1.3 0.2 setosa\n", " 43 5.0 3.5 1.6 0.6 setosa\n", " 44 5.1 3.8 1.9 0.4 setosa\n", " 45 4.8 3.0 1.4 0.3 setosa\n", " 46 5.1 3.8 1.6 0.2 setosa\n", " 47 4.6 3.2 1.4 0.2 setosa\n", " 48 5.3 3.7 1.5 0.2 setosa\n", " 49 5.0 3.3 1.4 0.2 setosa,\n", " Sepal_Length Sepal_Width Petal_Length Petal_Width Species\n", " \n", " 0 7.0 3.2 4.7 1.4 versicolor\n", " 1 6.4 3.2 4.5 1.5 versicolor\n", " 2 6.9 3.1 4.9 1.5 versicolor\n", " 3 5.5 2.3 4.0 1.3 versicolor\n", " 4 6.5 2.8 4.6 1.5 versicolor\n", " 5 5.7 2.8 4.5 1.3 versicolor\n", " 6 6.3 3.3 4.7 1.6 versicolor\n", " 7 4.9 2.4 3.3 1.0 versicolor\n", " 8 6.6 2.9 4.6 1.3 versicolor\n", " 9 5.2 2.7 3.9 1.4 versicolor\n", " 10 5.0 2.0 3.5 1.0 versicolor\n", " 11 5.9 3.0 4.2 1.5 versicolor\n", " 12 6.0 2.2 4.0 1.0 versicolor\n", " 13 6.1 2.9 4.7 1.4 versicolor\n", " 14 5.6 2.9 3.6 1.3 versicolor\n", " 15 6.7 3.1 4.4 1.4 versicolor\n", " 16 5.6 3.0 4.5 1.5 versicolor\n", " 17 5.8 2.7 4.1 1.0 versicolor\n", " 18 6.2 2.2 4.5 1.5 versicolor\n", " 19 5.6 2.5 3.9 1.1 versicolor\n", " 20 5.9 3.2 4.8 1.8 versicolor\n", " 21 6.1 2.8 4.0 1.3 versicolor\n", " 22 6.3 2.5 4.9 1.5 versicolor\n", " 23 6.1 2.8 4.7 1.2 versicolor\n", " 24 6.4 2.9 4.3 1.3 versicolor\n", " 25 6.6 3.0 4.4 1.4 versicolor\n", " 26 6.8 2.8 4.8 1.4 versicolor\n", " 27 6.7 3.0 5.0 1.7 versicolor\n", " 28 6.0 2.9 4.5 1.5 versicolor\n", " 29 5.7 2.6 3.5 1.0 versicolor\n", " 30 5.5 2.4 3.8 1.1 versicolor\n", " 31 5.5 2.4 3.7 1.0 versicolor\n", " 32 5.8 2.7 3.9 1.2 versicolor\n", " 33 6.0 2.7 5.1 1.6 versicolor\n", " 34 5.4 3.0 4.5 1.5 versicolor\n", " 35 6.0 3.4 4.5 1.6 versicolor\n", " 36 6.7 3.1 4.7 1.5 versicolor\n", " 37 6.3 2.3 4.4 1.3 versicolor\n", " 38 5.6 3.0 4.1 1.3 versicolor\n", " 39 5.5 2.5 4.0 1.3 versicolor\n", " 40 5.5 2.6 4.4 1.2 versicolor\n", " 41 6.1 3.0 4.6 1.4 versicolor\n", " 42 5.8 2.6 4.0 1.2 versicolor\n", " 43 5.0 2.3 3.3 1.0 versicolor\n", " 44 5.6 2.7 4.2 1.3 versicolor\n", " 45 5.7 3.0 4.2 1.2 versicolor\n", " 46 5.7 2.9 4.2 1.3 versicolor\n", " 47 6.2 2.9 4.3 1.3 versicolor\n", " 48 5.1 2.5 3.0 1.1 versicolor\n", " 49 5.7 2.8 4.1 1.3 versicolor,\n", " Sepal_Length Sepal_Width Petal_Length Petal_Width Species\n", " \n", " 0 6.3 3.3 6.0 2.5 virginica\n", " 1 5.8 2.7 5.1 1.9 virginica\n", " 2 7.1 3.0 5.9 2.1 virginica\n", " 3 6.3 2.9 5.6 1.8 virginica\n", " 4 6.5 3.0 5.8 2.2 virginica\n", " 5 7.6 3.0 6.6 2.1 virginica\n", " 6 4.9 2.5 4.5 1.7 virginica\n", " 7 7.3 2.9 6.3 1.8 virginica\n", " 8 6.7 2.5 5.8 1.8 virginica\n", " 9 7.2 3.6 6.1 2.5 virginica\n", " 10 6.5 3.2 5.1 2.0 virginica\n", " 11 6.4 2.7 5.3 1.9 virginica\n", " 12 6.8 3.0 5.5 2.1 virginica\n", " 13 5.7 2.5 5.0 2.0 virginica\n", " 14 5.8 2.8 5.1 2.4 virginica\n", " 15 6.4 3.2 5.3 2.3 virginica\n", " 16 6.5 3.0 5.5 1.8 virginica\n", " 17 7.7 3.8 6.7 2.2 virginica\n", " 18 7.7 2.6 6.9 2.3 virginica\n", " 19 6.0 2.2 5.0 1.5 virginica\n", " 20 6.9 3.2 5.7 2.3 virginica\n", " 21 5.6 2.8 4.9 2.0 virginica\n", " 22 7.7 2.8 6.7 2.0 virginica\n", " 23 6.3 2.7 4.9 1.8 virginica\n", " 24 6.7 3.3 5.7 2.1 virginica\n", " 25 7.2 3.2 6.0 1.8 virginica\n", " 26 6.2 2.8 4.8 1.8 virginica\n", " 27 6.1 3.0 4.9 1.8 virginica\n", " 28 6.4 2.8 5.6 2.1 virginica\n", " 29 7.2 3.0 5.8 1.6 virginica\n", " 30 7.4 2.8 6.1 1.9 virginica\n", " 31 7.9 3.8 6.4 2.0 virginica\n", " 32 6.4 2.8 5.6 2.2 virginica\n", " 33 6.3 2.8 5.1 1.5 virginica\n", " 34 6.1 2.6 5.6 1.4 virginica\n", " 35 7.7 3.0 6.1 2.3 virginica\n", " 36 6.3 3.4 5.6 2.4 virginica\n", " 37 6.4 3.1 5.5 1.8 virginica\n", " 38 6.0 3.0 4.8 1.8 virginica\n", " 39 6.9 3.1 5.4 2.1 virginica\n", " 40 6.7 3.1 5.6 2.4 virginica\n", " 41 6.9 3.1 5.1 2.3 virginica\n", " 42 5.8 2.7 5.1 1.9 virginica\n", " 43 6.8 3.2 5.9 2.3 virginica\n", " 44 6.7 3.3 5.7 2.5 virginica\n", " 45 6.7 3.0 5.2 2.3 virginica\n", " 46 6.3 2.5 5.0 1.9 virginica\n", " 47 6.5 3.0 5.2 2.0 virginica\n", " 48 6.2 3.4 5.4 2.3 virginica\n", " 49 5.9 3.0 5.1 1.8 virginica]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list(iris >> group_split(f.Species))" ] }, { "cell_type": "code", "execution_count": 7, "id": "ef9086c8", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.522213Z", "iopub.status.busy": "2021-07-16T22:27:53.521593Z", "iopub.status.idle": "2021-07-16T22:27:53.526006Z", "shell.execute_reply": "2021-07-16T22:27:53.526356Z" } }, "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", "
Species
<object>
0setosa
1versicolor
2virginica
\n", "
\n" ], "text/plain": [ " Species\n", " \n", "0 setosa\n", "1 versicolor\n", "2 virginica" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# group_keys(...) deprecated in dplyr\n", "iris >> group_by(f.Species) >> group_keys()" ] }, { "cell_type": "code", "execution_count": 8, "id": "65de8d54", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.549647Z", "iopub.status.busy": "2021-07-16T22:27:53.548678Z", "iopub.status.idle": "2021-07-16T22:27:53.555041Z", "shell.execute_reply": "2021-07-16T22:27:53.555395Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 14:07:59][datar][WARNING] `_keep` is ignored in `group_split()`.\n" ] }, { "data": { "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "out = iris >> group_by(f.Species) >> group_keys() >> rowwise() >> group_split()\n", "out" ] }, { "cell_type": "code", "execution_count": 9, "id": "264e6811", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.567713Z", "iopub.status.busy": "2021-07-16T22:27:53.567079Z", "iopub.status.idle": "2021-07-16T22:27:53.570183Z", "shell.execute_reply": "2021-07-16T22:27:53.570745Z" } }, "outputs": [ { "data": { "text/plain": [ "[ Species\n", " \n", " 0 setosa,\n", " Species\n", " \n", " 0 versicolor,\n", " Species\n", " \n", " 0 virginica]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list(out)" ] }, { "cell_type": "code", "execution_count": null, "id": "0d64b7b1", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/group_trim.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "9941c94b", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:00.630674Z", "iopub.status.busy": "2021-07-16T22:28:00.630102Z", "iopub.status.idle": "2021-07-16T22:28:01.530300Z", "shell.execute_reply": "2021-07-16T22:28:01.530718Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ group_trim
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Remove empty groups\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/group_trim.html \n", "\n", "##### Args:\n", "  `_data`: A grouped frame \n", "  `_drop`: See `group_by`. \n", "\n", "##### Returns:\n", "  A grouped frame \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/group_trim.html\n", "%run nb_helpers.py\n", "\n", "from datar.all import *\n", "\n", "nb_header(group_trim)" ] }, { "cell_type": "code", "execution_count": 3, "id": "d4c86c45", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:01.592992Z", "iopub.status.busy": "2021-07-16T22:28:01.583766Z", "iopub.status.idle": "2021-07-16T22:28:01.685184Z", "shell.execute_reply": "2021-07-16T22:28:01.684381Z" } }, "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", "
x_rows
<category><object>
0a[0]
1b[1]
2c[]
\n", "
\n" ], "text/plain": [ " x _rows\n", " \n", "0 a [0]\n", "1 b [1]\n", "2 c []" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x=factor([\"a\", \"b\"], levels=list(\"abc\")))\n", "df >> group_by(f.x, _drop=False) >> group_data()" ] }, { "cell_type": "code", "execution_count": 4, "id": "a11f49fc", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:01.749108Z", "iopub.status.busy": "2021-07-16T22:28:01.742401Z", "iopub.status.idle": "2021-07-16T22:28:01.861904Z", "shell.execute_reply": "2021-07-16T22:28:01.862322Z" } }, "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", "
x_rows
<category><object>
0a[0]
1b[1]
\n", "
\n" ], "text/plain": [ " x _rows\n", " \n", "0 a [0]\n", "1 b [1]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> group_by(f.x, _drop=False) >> group_trim() >> group_data()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/lead-lag.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "framed-grill", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:15.236681Z", "iopub.status.busy": "2021-07-16T22:28:15.235899Z", "iopub.status.idle": "2021-07-16T22:28:16.151393Z", "shell.execute_reply": "2021-07-16T22:28:16.151807Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ lead
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Shift a vector by `n` positions.\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/lead.html \n", "\n", "##### Args:\n", "  `x`: A vector \n", "  `n`: The number of positions to shift. \n", "  `default`: The default value to use for positions that don't exist. \n", "  `order_by`: A vector of column names to order by. \n", "\n", "##### Returns:\n", "  A vector \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ lag
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Shift a vector by `n` positions.\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/lag.html \n", "\n", "##### Args:\n", "  `x`: A vector \n", "  `n`: The number of positions to shift. \n", "  `default`: The default value to use for positions that don't exist. \n", "  `order_by`: A vector of column names to order by. \n", "\n", "##### Returns:\n", "  A vector \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/lead-lag.html\n", "%run nb_helpers.py\n", "\n", "from datar.all import *\n", "\n", "nb_header(lead, lag, book='lead-lag')" ] }, { "cell_type": "code", "execution_count": 2, "id": "interior-union", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:16.159285Z", "iopub.status.busy": "2021-07-16T22:28:16.158685Z", "iopub.status.idle": "2021-07-16T22:28:16.162326Z", "shell.execute_reply": "2021-07-16T22:28:16.162843Z" } }, "outputs": [ { "data": { "text/plain": [ "0 NaN\n", "1 1.0\n", "2 2.0\n", "3 3.0\n", "4 4.0\n", "dtype: float64" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = [1,2,3,4,5]\n", "\n", "lag(x)" ] }, { "cell_type": "code", "execution_count": 3, "id": "adopted-review", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:16.170772Z", "iopub.status.busy": "2021-07-16T22:28:16.169913Z", "iopub.status.idle": "2021-07-16T22:28:16.173717Z", "shell.execute_reply": "2021-07-16T22:28:16.174185Z" } }, "outputs": [ { "data": { "text/plain": [ "0 2.0\n", "1 3.0\n", "2 4.0\n", "3 5.0\n", "4 NaN\n", "dtype: float64" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lead(x)" ] }, { "cell_type": "code", "execution_count": 4, "id": "precious-generator", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:16.184680Z", "iopub.status.busy": "2021-07-16T22:28:16.183995Z", "iopub.status.idle": "2021-07-16T22:28:16.679235Z", "shell.execute_reply": "2021-07-16T22:28:16.679737Z" } }, "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", "
behindxahead
<float64><int64><float64>
0NaN12.0
11.023.0
22.034.0
33.045.0
44.05NaN
\n", "
\n" ], "text/plain": [ " behind x ahead\n", " \n", "0 NaN 1 2.0\n", "1 1.0 2 3.0\n", "2 2.0 3 4.0\n", "3 3.0 4 5.0\n", "4 4.0 5 NaN" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tibble(behind=lag(x), x=x, ahead=lead(x))" ] }, { "cell_type": "code", "execution_count": 5, "id": "associate-heading", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:16.705380Z", "iopub.status.busy": "2021-07-16T22:28:16.703301Z", "iopub.status.idle": "2021-07-16T22:28:16.715171Z", "shell.execute_reply": "2021-07-16T22:28:16.715814Z" } }, "outputs": [ { "data": { "text/plain": [ "0 NaN\n", "1 1.0\n", "2 2.0\n", "3 3.0\n", "4 4.0\n", "dtype: float64" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lag(x, n=1)" ] }, { "cell_type": "code", "execution_count": 6, "id": "pretty-greeting", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:16.728204Z", "iopub.status.busy": "2021-07-16T22:28:16.727629Z", "iopub.status.idle": "2021-07-16T22:28:16.740330Z", "shell.execute_reply": "2021-07-16T22:28:16.740767Z" } }, "outputs": [ { "data": { "text/plain": [ "0 NaN\n", "1 NaN\n", "2 1.0\n", "3 2.0\n", "4 3.0\n", "dtype: float64" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lag(x, n=2)" ] }, { "cell_type": "code", "execution_count": 7, "id": "excessive-corrections", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:16.753161Z", "iopub.status.busy": "2021-07-16T22:28:16.751770Z", "iopub.status.idle": "2021-07-16T22:28:16.765917Z", "shell.execute_reply": "2021-07-16T22:28:16.766714Z" } }, "outputs": [ { "data": { "text/plain": [ "0 2.0\n", "1 3.0\n", "2 4.0\n", "3 5.0\n", "4 NaN\n", "dtype: float64" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lead(x, n=1)" ] }, { "cell_type": "code", "execution_count": 8, "id": "ambient-auckland", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:16.780643Z", "iopub.status.busy": "2021-07-16T22:28:16.779113Z", "iopub.status.idle": "2021-07-16T22:28:16.792480Z", "shell.execute_reply": "2021-07-16T22:28:16.792914Z" } }, "outputs": [ { "data": { "text/plain": [ "0 3.0\n", "1 4.0\n", "2 5.0\n", "3 NaN\n", "4 NaN\n", "dtype: float64" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lead(x, n=2)" ] }, { "cell_type": "code", "execution_count": 9, "id": "lined-arnold", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:16.803720Z", "iopub.status.busy": "2021-07-16T22:28:16.802831Z", "iopub.status.idle": "2021-07-16T22:28:16.810039Z", "shell.execute_reply": "2021-07-16T22:28:16.810456Z" } }, "outputs": [ { "data": { "text/plain": [ "0 0\n", "1 1\n", "2 2\n", "3 3\n", "4 4\n", "dtype: int64" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lag(x, default=0)" ] }, { "cell_type": "code", "execution_count": 10, "id": "academic-directive", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:16.823358Z", "iopub.status.busy": "2021-07-16T22:28:16.822752Z", "iopub.status.idle": "2021-07-16T22:28:16.834898Z", "shell.execute_reply": "2021-07-16T22:28:16.835571Z" } }, "outputs": [ { "data": { "text/plain": [ "0 2\n", "1 3\n", "2 4\n", "3 5\n", "4 6\n", "dtype: int64" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lead(x, default=6)" ] }, { "cell_type": "code", "execution_count": 11, "id": "responsible-complement", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:16.868990Z", "iopub.status.busy": "2021-07-16T22:28:16.868135Z", "iopub.status.idle": "2021-07-16T22:28:17.102872Z", "shell.execute_reply": "2021-07-16T22:28:17.103273Z" } }, "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", "
yearvalueprevious_year_value
<int64><int64><float64>
0200001.0
1200119.0
220024NaN
3200394.0
42004160.0
520052516.0
\n", "
\n" ], "text/plain": [ " year value previous_year_value\n", " \n", "0 2000 0 1.0\n", "1 2001 1 9.0\n", "2 2002 4 NaN\n", "3 2003 9 4.0\n", "4 2004 16 0.0\n", "5 2005 25 16.0" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scrambled = slice_sample(\n", " tibble(year=[2000, 2001, 2002, 2003, 2004, 2005], \n", " value=[a**2 for a in range(6)]), \n", " prop=1\n", ") \n", "\n", "scrambled >> mutate(previous_year_value = lag(f.value)) >> arrange(f.year)" ] }, { "cell_type": "code", "execution_count": 12, "id": "driven-criminal", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:17.171662Z", "iopub.status.busy": "2021-07-16T22:28:17.170605Z", "iopub.status.idle": "2021-07-16T22:28:17.197979Z", "shell.execute_reply": "2021-07-16T22:28:17.196133Z" } }, "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", "
yearvalueprevious_year_value
<int64><int64><float64>
0200000.0
120011NaN
2200244.0
3200391.0
42004169.0
520052516.0
\n", "
\n" ], "text/plain": [ " year value previous_year_value\n", " \n", "0 2000 0 0.0\n", "1 2001 1 NaN\n", "2 2002 4 4.0\n", "3 2003 9 1.0\n", "4 2004 16 9.0\n", "5 2005 25 16.0" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Use this for lag(value, order_by = year) instead\n", "scrambled >> mutate(previous_year_value = lag(f.value, order_by=f.year)) >> arrange(f.year)\n" ] }, { "cell_type": "code", "execution_count": null, "id": "satisfied-seafood", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/mutate-joins.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "particular-aurora", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:44.282107Z", "iopub.status.busy": "2021-07-16T22:27:44.281107Z", "iopub.status.idle": "2021-07-16T22:27:45.500481Z", "shell.execute_reply": "2021-07-16T22:27:45.500907Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ inner_join
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Inner join two data frames by matching rows.\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/join.html \n", "\n", "##### Args:\n", "  `x`: A data frame \n", "  `y`: A data frame \n", "  `by`: A list of column names to join by. \n", "    If None, use the intersection of the columns of x and y. \n", "\n", "  `copy`: If True, always copy the data. \n", "  `suffix`: A tuple of suffixes to apply to overlapping columns. \n", "  `keep`: If True, keep the grouping variables in the output. \n", "\n", "##### Returns:\n", "  A data frame \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ left_join
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Left join two data frames by matching rows.\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/join.html \n", "\n", "##### Args:\n", "  `x`: A data frame \n", "  `y`: A data frame \n", "  `by`: A list of column names to join by. \n", "    If None, use the intersection of the columns of x and y. \n", "\n", "  `copy`: If True, always copy the data. \n", "  `suffix`: A tuple of suffixes to apply to overlapping columns. \n", "  `keep`: If True, keep the grouping variables in the output. \n", "\n", "##### Returns:\n", "  A data frame \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ right_join
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Right join two data frames by matching rows.\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/join.html \n", "\n", "##### Args:\n", "  `x`: A data frame \n", "  `y`: A data frame \n", "  `by`: A list of column names to join by. \n", "    If None, use the intersection of the columns of x and y. \n", "\n", "  `copy`: If True, always copy the data. \n", "  `suffix`: A tuple of suffixes to apply to overlapping columns. \n", "  `keep`: If True, keep the grouping variables in the output. \n", "\n", "##### Returns:\n", "  A data frame \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ full_join
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Full join two data frames by matching rows.\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/join.html \n", "\n", "##### Args:\n", "  `x`: A data frame \n", "  `y`: A data frame \n", "  `by`: A list of column names to join by. \n", "    If None, use the intersection of the columns of x and y. \n", "\n", "  `copy`: If True, always copy the data. \n", "  `suffix`: A tuple of suffixes to apply to overlapping columns. \n", "  `keep`: If True, keep the grouping variables in the output. \n", "\n", "##### Returns:\n", "  A data frame \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/mutate-joins.html\n", "%run nb_helpers.py\n", "\n", "from datar.data import band_members, band_instruments, band_instruments2\n", "from datar.all import *\n", "\n", "nb_header(inner_join, left_join, right_join, full_join, book='mutate-joins')" ] }, { "cell_type": "code", "execution_count": 2, "id": "specialized-renewal", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:45.539298Z", "iopub.status.busy": "2021-07-16T22:27:45.538740Z", "iopub.status.idle": "2021-07-16T22:27:45.600718Z", "shell.execute_reply": "2021-07-16T22:27:45.601156Z" } }, "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", "
namebandplays
<object><object><object>
0JohnBeatlesguitar
1PaulBeatlesbass
\n", "
\n" ], "text/plain": [ " name band plays\n", " \n", "0 John Beatles guitar\n", "1 Paul Beatles bass" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "band_members >> inner_join(band_instruments)" ] }, { "cell_type": "code", "execution_count": 3, "id": "scientific-replica", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:45.617582Z", "iopub.status.busy": "2021-07-16T22:27:45.616769Z", "iopub.status.idle": "2021-07-16T22:27:45.623503Z", "shell.execute_reply": "2021-07-16T22:27:45.624815Z" } }, "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", "
namebandplays
<object><object><object>
0MickStonesNaN
1JohnBeatlesguitar
2PaulBeatlesbass
\n", "
\n" ], "text/plain": [ " name band plays\n", " \n", "0 Mick Stones NaN\n", "1 John Beatles guitar\n", "2 Paul Beatles bass" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "band_members >> left_join(band_instruments)" ] }, { "cell_type": "code", "execution_count": 4, "id": "bibliographic-brain", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:45.649051Z", "iopub.status.busy": "2021-07-16T22:27:45.648385Z", "iopub.status.idle": "2021-07-16T22:27:45.653705Z", "shell.execute_reply": "2021-07-16T22:27:45.654115Z" } }, "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", "
namebandplays
<object><object><object>
0JohnBeatlesguitar
1PaulBeatlesbass
2KeithNaNguitar
\n", "
\n" ], "text/plain": [ " name band plays\n", " \n", "0 John Beatles guitar\n", "1 Paul Beatles bass\n", "2 Keith NaN guitar" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "band_members >> right_join(band_instruments)" ] }, { "cell_type": "code", "execution_count": 5, "id": "timely-variable", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:45.670644Z", "iopub.status.busy": "2021-07-16T22:27:45.669677Z", "iopub.status.idle": "2021-07-16T22:27:45.706452Z", "shell.execute_reply": "2021-07-16T22:27:45.706961Z" } }, "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", "
namebandplays
<object><object><object>
0MickStonesNaN
1JohnBeatlesguitar
2PaulBeatlesbass
3KeithNaNguitar
\n", "
\n" ], "text/plain": [ " name band plays\n", " \n", "0 Mick Stones NaN\n", "1 John Beatles guitar\n", "2 Paul Beatles bass\n", "3 Keith NaN guitar" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "band_members >> full_join(band_instruments)" ] }, { "cell_type": "code", "execution_count": 6, "id": "imperial-advisory", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:45.727825Z", "iopub.status.busy": "2021-07-16T22:27:45.727141Z", "iopub.status.idle": "2021-07-16T22:27:45.734867Z", "shell.execute_reply": "2021-07-16T22:27:45.734025Z" } }, "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", "
namebandplays
<object><object><object>
0JohnBeatlesguitar
1PaulBeatlesbass
\n", "
\n" ], "text/plain": [ " name band plays\n", " \n", "0 John Beatles guitar\n", "1 Paul Beatles bass" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "band_members >> inner_join(band_instruments, by=f.name)" ] }, { "cell_type": "code", "execution_count": 7, "id": "expensive-indonesian", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:45.753597Z", "iopub.status.busy": "2021-07-16T22:27:45.752807Z", "iopub.status.idle": "2021-07-16T22:27:45.759345Z", "shell.execute_reply": "2021-07-16T22:27:45.759864Z" } }, "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", "
namebandplays
<object><object><object>
0MickStonesNaN
1JohnBeatlesguitar
2PaulBeatlesbass
3NaNNaNguitar
\n", "
\n" ], "text/plain": [ " name band plays\n", " \n", "0 Mick Stones NaN\n", "1 John Beatles guitar\n", "2 Paul Beatles bass\n", "3 NaN NaN guitar" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "band_members >> full_join(band_instruments2, by={'name': 'artist'})" ] }, { "cell_type": "code", "execution_count": 8, "id": "patient-castle", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:45.771977Z", "iopub.status.busy": "2021-07-16T22:27:45.765790Z", "iopub.status.idle": "2021-07-16T22:27:45.778140Z", "shell.execute_reply": "2021-07-16T22:27:45.777544Z" } }, "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", "
namebandartistplays
<object><object><object><object>
0MickStonesNaNNaN
1JohnBeatlesJohnguitar
2PaulBeatlesPaulbass
3NaNNaNKeithguitar
\n", "
\n" ], "text/plain": [ " name band artist plays\n", " \n", "0 Mick Stones NaN NaN\n", "1 John Beatles John guitar\n", "2 Paul Beatles Paul bass\n", "3 NaN NaN Keith guitar" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "band_members >> full_join(band_instruments2, by={'name': 'artist'}, keep=True)" ] }, { "cell_type": "code", "execution_count": 9, "id": "finite-nicholas", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:45.783635Z", "iopub.status.busy": "2021-07-16T22:27:45.782999Z", "iopub.status.idle": "2021-07-16T22:27:45.948252Z", "shell.execute_reply": "2021-07-16T22:27:45.948713Z" } }, "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", "
xy
<int64><object>
01first
11second
22third
33NaN
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 1 first\n", "1 1 second\n", "2 2 third\n", "3 3 NaN" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df1 = tibble(x=[1,2,3])\n", "df2 = tibble(x=[1,1,2], y=[\"first\", \"second\", \"third\"])\n", "df1 >> left_join(df2)" ] }, { "cell_type": "code", "execution_count": 10, "id": "collected-airport", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:45.989893Z", "iopub.status.busy": "2021-07-16T22:27:45.989298Z", "iopub.status.idle": "2021-07-16T22:27:46.001899Z", "shell.execute_reply": "2021-07-16T22:27:46.002262Z" } }, "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", "
xyz
<float64><int64><int64>
01.023
1NaN23
\n", "
\n" ], "text/plain": [ " x y z\n", " \n", "0 1.0 2 3\n", "1 NaN 2 3" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df1 = tibble(x=[1, NA], y=2)\n", "df2 = tibble(x=[1, NA], z=3)\n", "left_join(df1, df2) # na_matches not supported yet" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/mutate.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:29.409806Z", "iopub.status.busy": "2021-07-16T22:27:29.408934Z", "iopub.status.idle": "2021-07-16T22:27:30.997229Z", "shell.execute_reply": "2021-07-16T22:27:30.998642Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ mutate
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Add new columns to a data frame.\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/mutate.html \n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `_keep`: allows you to control which columns from _data are retained \n", "    in the output: \n", "\n", "    - \"all\", the default, retains all variables.\n", "\n", "    - \"used\" keeps any variables used to make new variables;\n", "      it's useful for checking your work as it displays inputs and \n", "      outputs side-by-side. \n", "\n", "    - \"unused\" keeps only existing variables not used to make new\n", "      variables. \n", "\n", "    - \"none\", only keeps grouping keys (like transmute()).\n", "\n", "  `_before`: A list of column names to put the new columns before. \n", "  `_after`: A list of column names to put the new columns after. \n", "  `*args`: and \n", "  `**kwargs`: Name-value pairs. The name gives the name of the column \n", "    in the output. The value can be: \n", "\n", "    - A vector of length 1, which will be recycled to the correct\n", "      length. \n", "\n", "    - A vector the same length as the current group (or the whole\n", "      data frame if ungrouped). \n", "\n", "    - None to remove the column\n", "\n", "##### Returns:\n", "  An object of the same type as _data. The output has the following \n", "  properties: \n", "  - Rows are not affected.\n", "  - Existing columns will be preserved according to the _keep\n", "    argument. New columns will be placed according to the \n", "    _before and _after arguments. If _keep = \"none\" \n", "    (as in transmute()), the output order is determined only \n", "    by ..., not the order of existing columns. \n", "\n", "  - Columns given value None will be removed\n", "  - Groups will be recomputed if a grouping variable is mutated.\n", "  - Data frame attributes are preserved.\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ transmute
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Add new columns to a data frame and remove existing columns\n", "using mutate with `_keep=\"none\"`. \n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/mutate.html \n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `_before`: A list of column names to put the new columns before. \n", "  `_after`: A list of column names to put the new columns after. \n", "  `*args`: and \n", "  `**kwargs`: Name-value pairs. The name gives the name of the column \n", "    in the output. The value can be: \n", "\n", "    - A vector of length 1, which will be recycled to the correct\n", "      length. \n", "\n", "    - A vector the same length as the current group (or the whole\n", "      data frame if ungrouped). \n", "\n", "    - None to remove the column\n", "\n", "##### Returns:\n", "  An object of the same type as _data. The output has the following \n", "  properties: \n", "  - Rows are not affected.\n", "  - Existing columns will be preserved according to the _keep\n", "    argument. New columns will be placed according to the \n", "    _before and _after arguments. If _keep = \"none\" \n", "    (as in transmute()), the output order is determined only \n", "    by ..., not the order of existing columns. \n", "\n", "  - Columns given value None will be removed\n", "  - Groups will be recomputed if a grouping variable is mutated.\n", "  - Data frame attributes are preserved.\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/mutate.html\n", "%run nb_helpers.py\n", "\n", "from datar.data import starwars\n", "from datar.all import *\n", "\n", "nb_header(mutate, transmute)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:31.141772Z", "iopub.status.busy": "2021-07-16T22:27:31.139442Z", "iopub.status.idle": "2021-07-16T22:27:31.385585Z", "shell.execute_reply": "2021-07-16T22:27:31.386137Z" } }, "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", "
namemassmass2mass2_squared
<object><float64><float64><float64>
0Luke Skywalker77.0154.023716.0
1C-3PO75.0150.022500.0
2R2-D232.064.04096.0
3Darth Vader136.0272.073984.0
...............
4Leia Organa49.098.09604.0
82ReyNaNNaNNaN
83Poe DameronNaNNaNNaN
84BB8NaNNaNNaN
85Captain PhasmaNaNNaNNaN
86Padmé Amidala45.090.08100.0
\n", "

87 rows × 4 columns

\n", "
\n" ], "text/plain": [ " name mass mass2 mass2_squared\n", " \n", "0 Luke Skywalker 77.0 154.0 23716.0\n", "1 C-3PO 75.0 150.0 22500.0\n", "2 R2-D2 32.0 64.0 4096.0\n", "3 Darth Vader 136.0 272.0 73984.0\n", ".. ... ... ... ...\n", "4 Leia Organa 49.0 98.0 9604.0\n", "82 Rey NaN NaN NaN\n", "83 Poe Dameron NaN NaN NaN\n", "84 BB8 NaN NaN NaN\n", "85 Captain Phasma NaN NaN NaN\n", "86 Padmé Amidala 45.0 90.0 8100.0\n", "\n", "[87 rows x 4 columns]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> \\\n", " select(f.name, f.mass) >> \\\n", " mutate(\n", " mass2 = f.mass * 2,\n", " mass2_squared = f.mass2 * f.mass2\n", ")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:31.461979Z", "iopub.status.busy": "2021-07-16T22:27:31.461231Z", "iopub.status.idle": "2021-07-16T22:27:31.496176Z", "shell.execute_reply": "2021-07-16T22:27:31.496697Z" } }, "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", "
nameheighthomeworld
<object><float64><object>
0Luke Skywalker5.643045Tatooine
1C-3PO5.479003Tatooine
2R2-D23.149606Naboo
3Darth Vader6.627297Tatooine
............
4Leia Organa4.921260Alderaan
82ReyNaNNaN
83Poe DameronNaNNaN
84BB8NaNNaN
85Captain PhasmaNaNNaN
86Padmé Amidala5.413386Naboo
\n", "

87 rows × 3 columns

\n", "
\n" ], "text/plain": [ " name height homeworld\n", " \n", "0 Luke Skywalker 5.643045 Tatooine\n", "1 C-3PO 5.479003 Tatooine\n", "2 R2-D2 3.149606 Naboo\n", "3 Darth Vader 6.627297 Tatooine\n", ".. ... ... ...\n", "4 Leia Organa 4.921260 Alderaan\n", "82 Rey NaN NaN\n", "83 Poe Dameron NaN NaN\n", "84 BB8 NaN NaN\n", "85 Captain Phasma NaN NaN\n", "86 Padmé Amidala 5.413386 Naboo\n", "\n", "[87 rows x 3 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> \\\n", " select(f.name, f.height, f.mass, f.homeworld) >> \\\n", " mutate(\n", " mass = NULL,\n", " height = f.height * 0.0328084 # convert to feet\n", ")" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:31.600675Z", "iopub.status.busy": "2021-07-16T22:27:31.599829Z", "iopub.status.idle": "2021-07-16T22:27:31.841281Z", "shell.execute_reply": "2021-07-16T22:27:31.841670Z" } }, "outputs": [ { "data": { "text/plain": [ "name object\n", "homeworld category\n", "species category\n", "dtype: object" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" }, { "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", "
namehomeworldspecies
<object><category><category>
0Luke SkywalkerTatooineHuman
1C-3POTatooineDroid
2R2-D2NabooDroid
3Darth VaderTatooineHuman
............
4Leia OrganaAlderaanHuman
82ReyNaNHuman
83Poe DameronNaNHuman
84BB8NaNDroid
85Captain PhasmaNaNNaN
86Padmé AmidalaNabooHuman
\n", "

87 rows × 3 columns

\n", "
\n" ], "text/plain": [ " name homeworld species\n", " \n", "0 Luke Skywalker Tatooine Human\n", "1 C-3PO Tatooine Droid\n", "2 R2-D2 Naboo Droid\n", "3 Darth Vader Tatooine Human\n", ".. ... ... ...\n", "4 Leia Organa Alderaan Human\n", "82 Rey NaN Human\n", "83 Poe Dameron NaN Human\n", "84 BB8 NaN Droid\n", "85 Captain Phasma NaN NaN\n", "86 Padmé Amidala Naboo Human\n", "\n", "[87 rows x 3 columns]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = starwars >> \\\n", " select(f.name, f.homeworld, f.species) >> \\\n", " mutate(across(~f.name, as_factor))\n", "\n", "x.dtypes\n", "x" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:32.021295Z", "iopub.status.busy": "2021-07-16T22:27:32.017771Z", "iopub.status.idle": "2021-07-16T22:27:33.341775Z", "shell.execute_reply": "2021-07-16T22:27:33.344792Z" } }, "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", "
namemasshomeworldrank
<object><float64><object><float64>
0Luke Skywalker77.0Tatooine5.0
1C-3PO75.0Tatooine6.0
2R2-D232.0Naboo6.0
3Darth Vader136.0Tatooine1.0
...............
4Leia Organa49.0Alderaan2.0
82ReyNaNNaNNaN
83Poe DameronNaNNaNNaN
84BB8NaNNaNNaN
85Captain PhasmaNaNNaNNaN
86Padmé Amidala45.0Naboo5.0
\n", "

87 rows × 4 columns

\n", "
\n", "

TibbleGrouped: homeworld (n=49)" ], "text/plain": [ " name mass homeworld rank\n", " \n", "0 Luke Skywalker 77.0 Tatooine 5.0\n", "1 C-3PO 75.0 Tatooine 6.0\n", "2 R2-D2 32.0 Naboo 6.0\n", "3 Darth Vader 136.0 Tatooine 1.0\n", ".. ... ... ... ...\n", "4 Leia Organa 49.0 Alderaan 2.0\n", "82 Rey NaN NaN NaN\n", "83 Poe Dameron NaN NaN NaN\n", "84 BB8 NaN NaN NaN\n", "85 Captain Phasma NaN NaN NaN\n", "86 Padmé Amidala 45.0 Naboo 5.0\n", "\n", "[87 rows x 4 columns]\n", "[TibbleGrouped: homeworld (n=49)]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> \\\n", " select(f.name, f.mass, f.homeworld) >> \\\n", " group_by(f.homeworld) >> \\\n", " mutate(rank=min_rank(desc(f.mass))) " ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:33.378882Z", "iopub.status.busy": "2021-07-16T22:27:33.378130Z", "iopub.status.idle": "2021-07-16T22:27:33.629759Z", "shell.execute_reply": "2021-07-16T22:27:33.630203Z" } }, "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", "
xyz
<int64><int64><int64>
0123
\n", "
\n" ], "text/plain": [ " x y z\n", " \n", "0 1 2 3" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x=1, y=2)\n", "\n", "df >> mutate(z=f.x+f.y)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:33.748376Z", "iopub.status.busy": "2021-07-16T22:27:33.747738Z", "iopub.status.idle": "2021-07-16T22:27:33.758078Z", "shell.execute_reply": "2021-07-16T22:27:33.758450Z" } }, "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", "
xzy
<int64><int64><int64>
0132
\n", "
\n" ], "text/plain": [ " x z y\n", " \n", "0 1 3 2" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> mutate(z=f.x+f.y, _before=1) " ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:33.807964Z", "iopub.status.busy": "2021-07-16T22:27:33.807276Z", "iopub.status.idle": "2021-07-16T22:27:33.824793Z", "shell.execute_reply": "2021-07-16T22:27:33.825249Z" } }, "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", "
xzy
<int64><int64><int64>
0132
\n", "
\n" ], "text/plain": [ " x z y\n", " \n", "0 1 3 2" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> mutate(z=f.x+f.y, _after=f.x)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:33.853847Z", "iopub.status.busy": "2021-07-16T22:27:33.853035Z", "iopub.status.idle": "2021-07-16T22:27:33.860203Z", "shell.execute_reply": "2021-07-16T22:27:33.860590Z" } }, "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", "
xzy
<int64><int64><int64>
0162
\n", "
\n" ], "text/plain": [ " x z y\n", " \n", "0 1 6 2" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# use a temporary column\n", "df >> mutate(_z=f.x+f.y, z=f._z*2, _after=f.x)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:33.903931Z", "iopub.status.busy": "2021-07-16T22:27:33.903197Z", "iopub.status.idle": "2021-07-16T22:27:33.913176Z", "shell.execute_reply": "2021-07-16T22:27:33.913626Z" } }, "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", "
xyabz
<int64><int64><object><object><int64>
012ab3
\n", "
\n" ], "text/plain": [ " x y a b z\n", " \n", "0 1 2 a b 3" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x=1, y=2, a=\"a\", b=\"b\")\n", "df >> mutate(z=f.x+f.y, _keep='all')" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:33.959501Z", "iopub.status.busy": "2021-07-16T22:27:33.958877Z", "iopub.status.idle": "2021-07-16T22:27:33.987426Z", "shell.execute_reply": "2021-07-16T22:27:33.987823Z" } }, "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", "
xyz
<int64><int64><int64>
0123
\n", "
\n" ], "text/plain": [ " x y z\n", " \n", "0 1 2 3" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> mutate(z=f.x+f.y, _keep='used')" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:34.079819Z", "iopub.status.busy": "2021-07-16T22:27:34.078253Z", "iopub.status.idle": "2021-07-16T22:27:34.098820Z", "shell.execute_reply": "2021-07-16T22:27:34.100887Z" } }, "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", "
abz
<object><object><int64>
0ab3
\n", "
\n" ], "text/plain": [ " a b z\n", " \n", "0 a b 3" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> mutate(z=f.x+f.y, _keep='unused')" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:34.156265Z", "iopub.status.busy": "2021-07-16T22:27:34.155652Z", "iopub.status.idle": "2021-07-16T22:27:34.190824Z", "shell.execute_reply": "2021-07-16T22:27:34.191228Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
z
<int64>
03
\n", "
\n" ], "text/plain": [ " z\n", " \n", "0 3" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> mutate(z=f.x+f.y, _keep='none')" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:34.225635Z", "iopub.status.busy": "2021-07-16T22:27:34.224984Z", "iopub.status.idle": "2021-07-16T22:27:34.231807Z", "shell.execute_reply": "2021-07-16T22:27:34.234535Z" } }, "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", "
namemassspeciesmass_norm
<object><float64><object><float64>
0Luke Skywalker77.0Human0.791270
1C-3PO75.0Droid0.770718
2R2-D232.0Droid0.328840
3Darth Vader136.0Human1.397569
...............
4Leia Organa49.0Human0.503536
82ReyNaNHumanNaN
83Poe DameronNaNHumanNaN
84BB8NaNDroidNaN
85Captain PhasmaNaNNaNNaN
86Padmé Amidala45.0Human0.462431
\n", "

87 rows × 4 columns

\n", "
\n" ], "text/plain": [ " name mass species mass_norm\n", " \n", "0 Luke Skywalker 77.0 Human 0.791270\n", "1 C-3PO 75.0 Droid 0.770718\n", "2 R2-D2 32.0 Droid 0.328840\n", "3 Darth Vader 136.0 Human 1.397569\n", ".. ... ... ... ...\n", "4 Leia Organa 49.0 Human 0.503536\n", "82 Rey NaN Human NaN\n", "83 Poe Dameron NaN Human NaN\n", "84 BB8 NaN Droid NaN\n", "85 Captain Phasma NaN NaN NaN\n", "86 Padmé Amidala 45.0 Human 0.462431\n", "\n", "[87 rows x 4 columns]" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> \\\n", " select(f.name, f.mass, f.species) >> \\\n", " mutate(mass_norm=f.mass/mean(f.mass)) " ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:34.326340Z", "iopub.status.busy": "2021-07-16T22:27:34.325605Z", "iopub.status.idle": "2021-07-16T22:27:34.536838Z", "shell.execute_reply": "2021-07-16T22:27:34.537283Z" } }, "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", "
namemassspeciesmass_norm
<object><float64><object><float64>
0Luke Skywalker77.0Human0.930156
1C-3PO75.0Droid1.075269
2R2-D232.0Droid0.458781
3Darth Vader136.0Human1.642873
...............
4Leia Organa49.0Human0.591917
82ReyNaNHumanNaN
83Poe DameronNaNHumanNaN
84BB8NaNDroidNaN
85Captain PhasmaNaNNaNNaN
86Padmé Amidala45.0Human0.543598
\n", "

87 rows × 4 columns

\n", "
\n" ], "text/plain": [ " name mass species mass_norm\n", " \n", "0 Luke Skywalker 77.0 Human 0.930156\n", "1 C-3PO 75.0 Droid 1.075269\n", "2 R2-D2 32.0 Droid 0.458781\n", "3 Darth Vader 136.0 Human 1.642873\n", ".. ... ... ... ...\n", "4 Leia Organa 49.0 Human 0.591917\n", "82 Rey NaN Human NaN\n", "83 Poe Dameron NaN Human NaN\n", "84 BB8 NaN Droid NaN\n", "85 Captain Phasma NaN NaN NaN\n", "86 Padmé Amidala 45.0 Human 0.543598\n", "\n", "[87 rows x 4 columns]" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> \\\n", " select(f.name, f.mass, f.species) >> \\\n", " group_by(f.species) >> \\\n", " mutate(mass_norm=f.mass / mean(f.mass)) >> \\\n", " ungroup() " ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:34.629345Z", "iopub.status.busy": "2021-07-16T22:27:34.628648Z", "iopub.status.idle": "2021-07-16T22:27:34.644407Z", "shell.execute_reply": "2021-07-16T22:27:34.644860Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
nameheightmasshair_colorskin_coloreye_colorbirth_yearsexgenderhomeworldspeciesprod
<object><float64><float64><object><object><object><float64><object><object><object><object><float64>
0Luke Skywalker172.077.0blondfairblue19.0malemasculineTatooineHuman13244.0
1C-3PO167.075.0NaNgoldyellow112.0nonemasculineTatooineDroid12525.0
2R2-D296.032.0NaNwhite, bluered33.0nonemasculineNabooDroid3072.0
3Darth Vader202.0136.0nonewhiteyellow41.9malemasculineTatooineHuman27472.0
.......................................
4Leia Organa150.049.0brownlightbrown19.0femalefeminineAlderaanHuman7350.0
82ReyNaNNaNbrownlighthazelNaNfemalefeminineNaNHumanNaN
83Poe DameronNaNNaNbrownlightbrownNaNmalemasculineNaNHumanNaN
84BB8NaNNaNnonenoneblackNaNnonemasculineNaNDroidNaN
85Captain PhasmaNaNNaNunknownunknownunknownNaNNaNNaNNaNNaNNaN
86Padmé Amidala165.045.0brownlightbrown46.0femalefeminineNabooHuman7425.0
\n", "

87 rows × 12 columns

\n", "
\n" ], "text/plain": [ " name height mass hair_color skin_color eye_color \\\n", " \n", "0 Luke Skywalker 172.0 77.0 blond fair blue \n", "1 C-3PO 167.0 75.0 NaN gold yellow \n", "2 R2-D2 96.0 32.0 NaN white, blue red \n", "3 Darth Vader 202.0 136.0 none white yellow \n", ".. ... ... ... ... ... ... \n", "4 Leia Organa 150.0 49.0 brown light brown \n", "82 Rey NaN NaN brown light hazel \n", "83 Poe Dameron NaN NaN brown light brown \n", "84 BB8 NaN NaN none none black \n", "85 Captain Phasma NaN NaN unknown unknown unknown \n", "86 Padmé Amidala 165.0 45.0 brown light brown \n", "\n", " birth_year sex gender homeworld species prod \n", " \n", "0 19.0 male masculine Tatooine Human 13244.0 \n", "1 112.0 none masculine Tatooine Droid 12525.0 \n", "2 33.0 none masculine Naboo Droid 3072.0 \n", "3 41.9 male masculine Tatooine Human 27472.0 \n", ".. ... ... ... ... ... ... \n", "4 19.0 female feminine Alderaan Human 7350.0 \n", "82 NaN female feminine NaN Human NaN \n", "83 NaN male masculine NaN Human NaN \n", "84 NaN none masculine NaN Droid NaN \n", "85 NaN NaN NaN NaN NaN NaN \n", "86 46.0 female feminine Naboo Human 7425.0 \n", "\n", "[87 rows x 12 columns]" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "vars = [\"mass\", \"height\"]\n", "starwars >> mutate(starwars, prod=f[vars[0]] * f[vars[1]])" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 4 } ================================================ FILE: docs/notebooks/n_distinct.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "several-cowboy", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:07.196543Z", "iopub.status.busy": "2021-07-16T22:28:07.195916Z", "iopub.status.idle": "2021-07-16T22:28:08.127610Z", "shell.execute_reply": "2021-07-16T22:28:08.128233Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ sample
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Sample a vector\n", "\n", "##### Args:\n", "  `x`: a vector or scaler \n", "  `size`: the size of the sample \n", "  `replace`: whether to sample with replacement \n", "  `prob`: the probabilities of sampling each element \n", "\n", "##### Returns:\n", "  The sampled vector \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ n_distinct
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Count the number of distinct values\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/distinct.html \n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `na_rm`: If `True`, remove missing values before counting. \n", "\n", "##### Returns:\n", "  The number of distinct values \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/n_distinct.html\n", "%run nb_helpers.py\n", "\n", "from datar.all import sample, n_distinct\n", "\n", "nb_header(sample, n_distinct, book='n_distinct')" ] }, { "cell_type": "code", "execution_count": 2, "id": "sharing-michigan", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:08.142741Z", "iopub.status.busy": "2021-07-16T22:28:08.141395Z", "iopub.status.idle": "2021-07-16T22:28:08.149693Z", "shell.execute_reply": "2021-07-16T22:28:08.150142Z" } }, "outputs": [ { "data": { "text/plain": [ "100000" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = sample(range(10), 1e5, replace=True)\n", "len(x)" ] }, { "cell_type": "code", "execution_count": 3, "id": "interested-store", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:08.215359Z", "iopub.status.busy": "2021-07-16T22:28:08.214713Z", "iopub.status.idle": "2021-07-16T22:28:08.311083Z", "shell.execute_reply": "2021-07-16T22:28:08.310511Z" } }, "outputs": [ { "data": { "text/plain": [ "10" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "n_distinct(x)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/na_if.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "ddb0828f", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:33.626180Z", "iopub.status.busy": "2021-07-16T22:27:33.625478Z", "iopub.status.idle": "2021-07-16T22:27:34.726717Z", "shell.execute_reply": "2021-07-16T22:27:34.725906Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ na_if
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Replace values with missing values\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/na_if.html \n", "\n", "##### Args:\n", "  `x`: A vector \n", "  `value`: Values to replace with missing values. \n", "\n", "##### Returns:\n", "  An array of values \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/na_if.html\n", "%run nb_helpers.py\n", "\n", "from datar.data import starwars\n", "from datar.all import *\n", "\n", "nb_header(na_if)" ] }, { "cell_type": "code", "execution_count": 2, "id": "6be7b8cf", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:34.742022Z", "iopub.status.busy": "2021-07-16T22:27:34.741052Z", "iopub.status.idle": "2021-07-16T22:27:34.749111Z", "shell.execute_reply": "2021-07-16T22:27:34.748355Z" } }, "outputs": [ { "data": { "text/plain": [ "0 0.0\n", "1 1.0\n", "2 NaN\n", "3 3.0\n", "4 4.0\n", "Name: x, dtype: float64" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "na_if(range(5), list(range(4,-1,-1)))" ] }, { "cell_type": "code", "execution_count": 2, "id": "c9c23967", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:34.765321Z", "iopub.status.busy": "2021-07-16T22:27:34.764648Z", "iopub.status.idle": "2021-07-16T22:27:34.914243Z", "shell.execute_reply": "2021-07-16T22:27:34.913240Z" } }, "outputs": [ { "data": { "text/plain": [ "0 100.0\n", "1 -100.0\n", "2 inf\n", "3 10.0\n", "Name: x, dtype: float64" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = tibble(x=[1, -1, 0, 10]).x\n", "100 / x" ] }, { "cell_type": "code", "execution_count": 3, "id": "b77113cc", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:34.926337Z", "iopub.status.busy": "2021-07-16T22:27:34.925244Z", "iopub.status.idle": "2021-07-16T22:27:34.929053Z", "shell.execute_reply": "2021-07-16T22:27:34.929499Z" } }, "outputs": [ { "data": { "text/plain": [ "0 1.0\n", "1 -1.0\n", "2 NaN\n", "3 10.0\n", "Name: x, dtype: float64" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "na_if(x, 0)" ] }, { "cell_type": "code", "execution_count": 4, "id": "9855ec95", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:34.939256Z", "iopub.status.busy": "2021-07-16T22:27:34.937975Z", "iopub.status.idle": "2021-07-16T22:27:34.961121Z", "shell.execute_reply": "2021-07-16T22:27:34.961571Z" } }, "outputs": [ { "data": { "text/plain": [ "0 abc\n", "1 def\n", "2 NaN\n", "3 ghi\n", "Name: x, dtype: object" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "y = tibble(y=[\"abc\", \"def\", \"\", \"ghi\"]).y\n", "na_if(y, \"\")" ] }, { "cell_type": "code", "execution_count": 5, "id": "5296a66c", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:35.019008Z", "iopub.status.busy": "2021-07-16T22:27:35.016615Z", "iopub.status.idle": "2021-07-16T22:27:35.082509Z", "shell.execute_reply": "2021-07-16T22:27:35.083282Z" } }, "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", "
nameeye_color
<object><object>
0Luke Skywalkerblue
1C-3POyellow
2R2-D2red
3Darth Vaderyellow
.........
4Leia Organabrown
82Reyhazel
83Poe Dameronbrown
84BB8black
85Captain PhasmaNaN
86Padmé Amidalabrown
\n", "

87 rows × 2 columns

\n", "
\n" ], "text/plain": [ " name eye_color\n", " \n", "0 Luke Skywalker blue\n", "1 C-3PO yellow\n", "2 R2-D2 red\n", "3 Darth Vader yellow\n", ".. ... ...\n", "4 Leia Organa brown\n", "82 Rey hazel\n", "83 Poe Dameron brown\n", "84 BB8 black\n", "85 Captain Phasma NaN\n", "86 Padmé Amidala brown\n", "\n", "[87 rows x 2 columns]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> \\\n", " select(f.name, f.eye_color) >> \\\n", " mutate(eye_color = na_if(f.eye_color, \"unknown\"))" ] }, { "cell_type": "code", "execution_count": 6, "id": "11e9a9d2", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:35.180726Z", "iopub.status.busy": "2021-07-16T22:27:35.180148Z", "iopub.status.idle": "2021-07-16T22:27:35.188513Z", "shell.execute_reply": "2021-07-16T22:27:35.188945Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
nameheightmasshair_colorskin_coloreye_colorbirth_yearsexgenderhomeworldspecies
<object><float64><float64><object><object><object><float64><object><object><object><object>
0Luke Skywalker172.077.0blondfairblue19.0malemasculineTatooineHuman
1C-3PO167.075.0NaNgoldyellow112.0nonemasculineTatooineDroid
2R2-D296.032.0NaNwhite, bluered33.0nonemasculineNabooDroid
3Darth Vader202.0136.0nonewhiteyellow41.9malemasculineTatooineHuman
....................................
4Leia Organa150.049.0brownlightbrown19.0femalefeminineAlderaanHuman
82ReyNaNNaNbrownlighthazelNaNfemalefeminineNaNHuman
83Poe DameronNaNNaNbrownlightbrownNaNmalemasculineNaNHuman
84BB8NaNNaNnonenoneblackNaNnonemasculineNaNDroid
85Captain PhasmaNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
86Padmé Amidala165.045.0brownlightbrown46.0femalefeminineNabooHuman
\n", "

87 rows × 11 columns

\n", "
\n" ], "text/plain": [ " name height mass hair_color skin_color eye_color \\\n", " \n", "0 Luke Skywalker 172.0 77.0 blond fair blue \n", "1 C-3PO 167.0 75.0 NaN gold yellow \n", "2 R2-D2 96.0 32.0 NaN white, blue red \n", "3 Darth Vader 202.0 136.0 none white yellow \n", ".. ... ... ... ... ... ... \n", "4 Leia Organa 150.0 49.0 brown light brown \n", "82 Rey NaN NaN brown light hazel \n", "83 Poe Dameron NaN NaN brown light brown \n", "84 BB8 NaN NaN none none black \n", "85 Captain Phasma NaN NaN NaN NaN NaN \n", "86 Padmé Amidala 165.0 45.0 brown light brown \n", "\n", " birth_year sex gender homeworld species \n", " \n", "0 19.0 male masculine Tatooine Human \n", "1 112.0 none masculine Tatooine Droid \n", "2 33.0 none masculine Naboo Droid \n", "3 41.9 male masculine Tatooine Human \n", ".. ... ... ... ... ... \n", "4 19.0 female feminine Alderaan Human \n", "82 NaN female feminine NaN Human \n", "83 NaN male masculine NaN Human \n", "84 NaN none masculine NaN Droid \n", "85 NaN NaN NaN NaN NaN \n", "86 46.0 female feminine Naboo Human \n", "\n", "[87 rows x 11 columns]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> \\\n", " mutate(across(where(is_character), lambda x: na_if(x, \"unknown\")))" ] }, { "cell_type": "code", "execution_count": null, "id": "4f05cb1f", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/nb_helpers.py ================================================ """helpers for notebooks""" from contextlib import contextmanager from IPython.display import display, Markdown, HTML from IPython.core.interactiveshell import InteractiveShell import pardoc from varname.helpers import debug # noqa from datar import options options(allow_conflict_names=True) InteractiveShell.ast_node_interactivity = "all" BINDER_URL = ( "https://mybinder.org/v2/gh/pwwang/datar/" "dev?filepath=docs%2Fnotebooks%2F" ) def nb_header(*funcs, book=None): """Print the header of a notebooks, mostly the docs""" if book is None: book = funcs[0].__name__ display( HTML( '
' 'Try this notebook on ' f'' "binder.
" ) ) for func in funcs: try: parsed = pardoc.google_parser.parse(func.__doc__) try: del parsed["Examples"] except KeyError: pass except Exception: formatted = func.__doc__ else: formatted = pardoc.google_parser.format( parsed, to="markdown", heading=5, indent_base="  ", ) display(Markdown( f'{"#"*3} ' '
' f'★ {func.__name__}' '
') ) display(Markdown(formatted)) @contextmanager def try_catch(): """Catch the error and print it out""" try: yield except Exception as exc: print(f"[{type(exc).__name__}] {exc}") ================================================ FILE: docs/notebooks/near.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "permanent-waters", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:33.908144Z", "iopub.status.busy": "2021-07-16T22:28:33.907513Z", "iopub.status.idle": "2021-07-16T22:28:34.718530Z", "shell.execute_reply": "2021-07-16T22:28:34.718946Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ near
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Check if values are approximately equal\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/near.html \n", "\n", "##### Args:\n", "  `x`: A numeric vector \n", "  `y`: A numeric vector \n", "  `tol`: Tolerance \n", "\n", "##### Returns:\n", "  An array of boolean values \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/near.html\n", "%run nb_helpers.py\n", "\n", "from datar.all import *\n", "\n", "nb_header(near)" ] }, { "cell_type": "code", "execution_count": 2, "id": "employed-supplier", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:34.724636Z", "iopub.status.busy": "2021-07-16T22:28:34.723973Z", "iopub.status.idle": "2021-07-16T22:28:34.727483Z", "shell.execute_reply": "2021-07-16T22:28:34.727978Z" } }, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sqrt(2.0) ** 2.0 == 2.0" ] }, { "cell_type": "code", "execution_count": 3, "id": "black-decimal", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:34.734438Z", "iopub.status.busy": "2021-07-16T22:28:34.733793Z", "iopub.status.idle": "2021-07-16T22:28:34.736689Z", "shell.execute_reply": "2021-07-16T22:28:34.737085Z" } }, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "near(sqrt(2.0) ** 2.0, 2.0)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/nest-join.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "adverse-thesis", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:21.040914Z", "iopub.status.busy": "2021-07-16T22:28:21.040207Z", "iopub.status.idle": "2021-07-16T22:28:22.128495Z", "shell.execute_reply": "2021-07-16T22:28:22.128914Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ nest_join
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Nest join two data frames by matching rows.\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/join.html \n", "\n", "##### Args:\n", "  `x`: A data frame \n", "  `y`: A data frame \n", "  `by`: A list of column names to join by. \n", "    If None, use the intersection of the columns of x and y. \n", "\n", "  `copy`: If True, always copy the data. \n", "  `keep`: If True, keep the grouping variables in the output. \n", "  `name`: The name of the column to store the nested data frame. \n", "\n", "##### Returns:\n", "  A data frame \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/nest_join.html\n", "%run nb_helpers.py\n", "\n", "from datar.data import band_members, band_instruments\n", "from datar.all import *\n", "\n", "nb_header(nest_join, book='nest-join')" ] }, { "cell_type": "code", "execution_count": 2, "id": "green-continuity", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:22.136012Z", "iopub.status.busy": "2021-07-16T22:28:22.135245Z", "iopub.status.idle": "2021-07-16T22:28:22.213886Z", "shell.execute_reply": "2021-07-16T22:28:22.214257Z" } }, "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", "
nameband_y_joined
<object><object><object>
0MickStones<DF 0x1>
1JohnBeatles<DF 1x1>
2PaulBeatles<DF 1x1>
\n", "
\n" ], "text/plain": [ " name band _y_joined\n", " \n", "0 Mick Stones \n", "1 John Beatles \n", "2 Paul Beatles " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nested = band_members >> nest_join(band_instruments)\n", "nested" ] }, { "cell_type": "code", "execution_count": 3, "id": "french-egyptian", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:22.228931Z", "iopub.status.busy": "2021-07-16T22:28:22.228284Z", "iopub.status.idle": "2021-07-16T22:28:22.238218Z", "shell.execute_reply": "2021-07-16T22:28:22.237726Z" } }, "outputs": [ { "data": { "text/plain": [ "[Empty Tibble\n", " Columns: [plays]\n", " Index: [],\n", " plays\n", " \n", " 0 guitar]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nested >> head(2) >> pull(f._y_joined, to='list')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/nest.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:25.625315Z", "iopub.status.busy": "2021-07-16T22:28:25.624736Z", "iopub.status.idle": "2021-07-16T22:28:26.572586Z", "shell.execute_reply": "2021-07-16T22:28:26.573026Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ nest
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Nesting creates a list-column of data frames\n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `**cols`: Columns to nest \n", "  `_names_sep`: If `None`, the default, the names will be left as is. \n", "    Inner names will come from the former outer names \n", "    If a string, the inner and outer names will be used together. \n", "    The names of the new outer columns will be formed by pasting \n", "    together the outer and the inner column names, separated by \n", "    `_names_sep`. \n", "\n", "##### Returns:\n", "  Nested data frame. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ unnest
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Flattens list-column of data frames back out into regular columns.\n", "\n", "##### Args:\n", "  `data`: A data frame to flatten. \n", "  `*cols`: Columns to unnest. \n", "  `keep_empty`: By default, you get one row of output for each element \n", "    of the list your unchopping/unnesting. \n", "    This means that if there's a size-0 element \n", "    (like NULL or an empty data frame), that entire row will be \n", "    dropped from the output. \n", "    If you want to preserve all rows, use `keep_empty` = `True` to \n", "    replace size-0 elements with a single row of missing values. \n", "\n", "  `dtypes`: Providing the dtypes for the output columns. \n", "    Could be a single dtype, which will be applied to all columns, or \n", "    a dictionary of dtypes with keys for the columns and values the \n", "    dtypes. \n", "\n", "  `names_sep`: If `None`, the default, the names will be left as is. \n", "    Inner names will come from the former outer names \n", "    If a string, the inner and outer names will be used together. \n", "    The names of the new outer columns will be formed by pasting \n", "    together the outer and the inner column names, separated by \n", "    `names_sep`. \n", "\n", "  `names_repair`: treatment of problematic column names: \n", "    - \"minimal\": No name repair or checks, beyond basic existence,\n", "\n", "    - \"unique\": Make sure names are unique and not empty,\n", "\n", "    - \"check_unique\": (default value), no name repair,\n", "      but check they are unique, \n", "\n", "    - \"universal\": Make the names unique and syntactic\n", "\n", "    - a function: apply custom name repair\n", "\n", "##### Returns:\n", "  Data frame with selected columns unnested. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%run nb_helpers.py\n", "from datar.data import iris, fish_encounters, mtcars\n", "from datar.all import *\n", "\n", "nb_header(nest, unnest)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:26.583824Z", "iopub.status.busy": "2021-07-16T22:28:26.583030Z", "iopub.status.idle": "2021-07-16T22:28:27.019996Z", "shell.execute_reply": "2021-07-16T22:28:27.020368Z" } }, "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", "
xdata
<int64><object>
01<DF 3x2>
12<DF 2x2>
23<DF 1x2>
\n", "
\n" ], "text/plain": [ " x data\n", " \n", "0 1 \n", "1 2 \n", "2 3 " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x = c(1, 1, 1, 2, 2, 3), y = c[1:7], z = c[7:1])\n", "df >> nest(data=c(f.y, f.z))" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:27.060315Z", "iopub.status.busy": "2021-07-16T22:28:27.059733Z", "iopub.status.idle": "2021-07-16T22:28:27.064175Z", "shell.execute_reply": "2021-07-16T22:28:27.065038Z" } }, "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", "
xyz
<int64><object><object>
01[1, 2, 3][7, 6, 5]
12[4, 5][4, 3]
23[6][2]
\n", "
\n" ], "text/plain": [ " x y z\n", " \n", "0 1 [1, 2, 3] [7, 6, 5]\n", "1 2 [4, 5] [4, 3]\n", "2 3 [6] [2]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> chop(c(f.y, f.z))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:27.076559Z", "iopub.status.busy": "2021-07-16T22:28:27.075937Z", "iopub.status.idle": "2021-07-16T22:28:27.112744Z", "shell.execute_reply": "2021-07-16T22:28:27.113138Z" } }, "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", "
xdata
<int64><object>
01<DF 3x2>
12<DF 2x2>
23<DF 1x2>
\n", "
\n" ], "text/plain": [ " x data\n", " \n", "0 1 \n", "1 2 \n", "2 3 " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> nest(data=any_of(c(f.y, f.z)))" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:27.142333Z", "iopub.status.busy": "2021-07-16T22:28:27.141724Z", "iopub.status.idle": "2021-07-16T22:28:27.165121Z", "shell.execute_reply": "2021-07-16T22:28:27.165508Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Sepal_LengthSepal_WidthPetal_LengthPetal_Width
<float64><float64><float64><float64>
05.13.51.40.2
14.93.01.40.2
24.73.21.30.2
34.63.11.50.2
45.03.61.40.2
55.43.91.70.4
64.63.41.40.3
75.03.41.50.2
84.42.91.40.2
94.93.11.50.1
105.43.71.50.2
114.83.41.60.2
124.83.01.40.1
134.33.01.10.1
145.84.01.20.2
155.74.41.50.4
165.43.91.30.4
175.13.51.40.3
185.73.81.70.3
195.13.81.50.3
205.43.41.70.2
215.13.71.50.4
224.63.61.00.2
235.13.31.70.5
244.83.41.90.2
255.03.01.60.2
265.03.41.60.4
275.23.51.50.2
285.23.41.40.2
294.73.21.60.2
304.83.11.60.2
315.43.41.50.4
325.24.11.50.1
335.54.21.40.2
344.93.11.50.2
355.03.21.20.2
365.53.51.30.2
374.93.61.40.1
384.43.01.30.2
395.13.41.50.2
405.03.51.30.3
414.52.31.30.3
424.43.21.30.2
435.03.51.60.6
445.13.81.90.4
454.83.01.40.3
465.13.81.60.2
474.63.21.40.2
485.33.71.50.2
495.03.31.40.2
\n", "
\n" ], "text/plain": [ " Sepal_Length Sepal_Width Petal_Length Petal_Width\n", " \n", "0 5.1 3.5 1.4 0.2\n", "1 4.9 3.0 1.4 0.2\n", "2 4.7 3.2 1.3 0.2\n", "3 4.6 3.1 1.5 0.2\n", "4 5.0 3.6 1.4 0.2\n", "5 5.4 3.9 1.7 0.4\n", "6 4.6 3.4 1.4 0.3\n", "7 5.0 3.4 1.5 0.2\n", "8 4.4 2.9 1.4 0.2\n", "9 4.9 3.1 1.5 0.1\n", "10 5.4 3.7 1.5 0.2\n", "11 4.8 3.4 1.6 0.2\n", "12 4.8 3.0 1.4 0.1\n", "13 4.3 3.0 1.1 0.1\n", "14 5.8 4.0 1.2 0.2\n", "15 5.7 4.4 1.5 0.4\n", "16 5.4 3.9 1.3 0.4\n", "17 5.1 3.5 1.4 0.3\n", "18 5.7 3.8 1.7 0.3\n", "19 5.1 3.8 1.5 0.3\n", "20 5.4 3.4 1.7 0.2\n", "21 5.1 3.7 1.5 0.4\n", "22 4.6 3.6 1.0 0.2\n", "23 5.1 3.3 1.7 0.5\n", "24 4.8 3.4 1.9 0.2\n", "25 5.0 3.0 1.6 0.2\n", "26 5.0 3.4 1.6 0.4\n", "27 5.2 3.5 1.5 0.2\n", "28 5.2 3.4 1.4 0.2\n", "29 4.7 3.2 1.6 0.2\n", "30 4.8 3.1 1.6 0.2\n", "31 5.4 3.4 1.5 0.4\n", "32 5.2 4.1 1.5 0.1\n", "33 5.5 4.2 1.4 0.2\n", "34 4.9 3.1 1.5 0.2\n", "35 5.0 3.2 1.2 0.2\n", "36 5.5 3.5 1.3 0.2\n", "37 4.9 3.6 1.4 0.1\n", "38 4.4 3.0 1.3 0.2\n", "39 5.1 3.4 1.5 0.2\n", "40 5.0 3.5 1.3 0.3\n", "41 4.5 2.3 1.3 0.3\n", "42 4.4 3.2 1.3 0.2\n", "43 5.0 3.5 1.6 0.6\n", "44 5.1 3.8 1.9 0.4\n", "45 4.8 3.0 1.4 0.3\n", "46 5.1 3.8 1.6 0.2\n", "47 4.6 3.2 1.4 0.2\n", "48 5.3 3.7 1.5 0.2\n", "49 5.0 3.3 1.4 0.2" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "out = iris >> nest(data=~f.Species)\n", "out.data[0]" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:27.186712Z", "iopub.status.busy": "2021-07-16T22:28:27.177083Z", "iopub.status.idle": "2021-07-16T22:28:27.196394Z", "shell.execute_reply": "2021-07-16T22:28:27.195914Z" } }, "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", "
Speciesdata
<object><object>
0setosa<DF 50x4>
1versicolor<DF 50x4>
2virginica<DF 50x4>
\n", "
\n" ], "text/plain": [ " Species data\n", " \n", "0 setosa \n", "1 versicolor \n", "2 virginica " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nest_vars = colnames(iris)[:4]\n", "iris >> nest(data = any_of(nest_vars))" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:27.207533Z", "iopub.status.busy": "2021-07-16T22:28:27.206940Z", "iopub.status.idle": "2021-07-16T22:28:27.234790Z", "shell.execute_reply": "2021-07-16T22:28:27.235261Z" } }, "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", "
Speciespetalsepal
<object><object><object>
0setosa<DF 50x2><DF 50x2>
1versicolor<DF 50x2><DF 50x2>
2virginica<DF 50x2><DF 50x2>
\n", "
\n" ], "text/plain": [ " Species petal sepal\n", " \n", "0 setosa \n", "1 versicolor \n", "2 virginica " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> nest(petal = starts_with(\"Petal\"), sepal = starts_with(\"Sepal\"))" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:27.265853Z", "iopub.status.busy": "2021-07-16T22:28:27.246908Z", "iopub.status.idle": "2021-07-16T22:28:27.279510Z", "shell.execute_reply": "2021-07-16T22:28:27.279907Z" } }, "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", "
Specieswidthlength
<object><object><object>
0setosa<DF 50x2><DF 50x2>
1versicolor<DF 50x2><DF 50x2>
2virginica<DF 50x2><DF 50x2>
\n", "
\n" ], "text/plain": [ " Species width length\n", " \n", "0 setosa \n", "1 versicolor \n", "2 virginica " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> nest(width = contains(\"Width\"), length = contains(\"Length\"))" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:27.333173Z", "iopub.status.busy": "2021-07-16T22:28:27.302622Z", "iopub.status.idle": "2021-07-16T22:28:27.338132Z", "shell.execute_reply": "2021-07-16T22:28:27.337041Z" } }, "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", "
fishdata
<int64><object>
04842<DF 11x2>
14843<DF 11x2>
24844<DF 11x2>
34845<DF 5x2>
44847<DF 3x2>
54848<DF 4x2>
64849<DF 2x2>
74850<DF 6x2>
84851<DF 2x2>
94854<DF 2x2>
104855<DF 5x2>
114857<DF 9x2>
124858<DF 11x2>
134859<DF 5x2>
144861<DF 11x2>
154862<DF 9x2>
164863<DF 2x2>
174864<DF 2x2>
184865<DF 3x2>
\n", "
\n", "

TibbleGrouped: fish (n=19)" ], "text/plain": [ " fish data\n", " \n", "0 4842 \n", "1 4843 \n", "2 4844 \n", "3 4845 \n", "4 4847 \n", "5 4848 \n", "6 4849 \n", "7 4850 \n", "8 4851 \n", "9 4854 \n", "10 4855 \n", "11 4857 \n", "12 4858 \n", "13 4859 \n", "14 4861 \n", "15 4862 \n", "16 4863 \n", "17 4864 \n", "18 4865 \n", "[TibbleGrouped: fish (n=19)]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fish_encounters >> group_by(f.fish) >> nest()" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:27.401063Z", "iopub.status.busy": "2021-07-16T22:28:27.398103Z", "iopub.status.idle": "2021-07-16T22:28:27.445576Z", "shell.execute_reply": "2021-07-16T22:28:27.445023Z" } }, "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", "
cyldatamodels
<int64><object><object>
06<DF 7x10><df 7x10>
14<DF 11x10><df 11x10>
28<DF 14x10><df 14x10>
\n", "
\n", "

TibbleGrouped: cyl (n=3)" ], "text/plain": [ " cyl data models\n", " \n", "0 6 \n", "1 4 \n", "2 8 \n", "[TibbleGrouped: cyl (n=3)]" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from pipda import register_func\n", "@register_func()\n", "def get_models(dfs):\n", " # do whatever with the dfs\n", " \n", " return dfs.transform(lambda df: f\"\")\n", "\n", "mtcars >> group_by(f.cyl) >> nest() >> mutate(\n", " models=get_models(f.data)\n", ")" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:27.451681Z", "iopub.status.busy": "2021-07-16T22:28:27.451136Z", "iopub.status.idle": "2021-07-16T22:28:27.522976Z", "shell.execute_reply": "2021-07-16T22:28:27.523384Z" } }, "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", "
xab
<int64><int64><int64>
0212
1314
2323
3332
\n", "
\n" ], "text/plain": [ " x a b\n", " \n", "0 2 1 2\n", "1 3 1 4\n", "2 3 2 3\n", "3 3 3 2" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(\n", " x = c[1:4],\n", " y = [\n", " NULL,\n", " tibble(a = 1, b = 2),\n", " tibble(a = c[1:4], b = c[4:1])\n", " ]\n", ")\n", "df >> unnest(f.y, dtypes=int)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:27.535876Z", "iopub.status.busy": "2021-07-16T22:28:27.535230Z", "iopub.status.idle": "2021-07-16T22:28:27.539200Z", "shell.execute_reply": "2021-07-16T22:28:27.539748Z" } }, "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", "
xab
<int64><float64><float64>
01NaNNaN
121.02.0
231.04.0
332.03.0
433.02.0
\n", "
\n" ], "text/plain": [ " x a b\n", " \n", "0 1 NaN NaN\n", "1 2 1.0 2.0\n", "2 3 1.0 4.0\n", "3 3 2.0 3.0\n", "4 3 3.0 2.0" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> unnest(f.y, keep_empty=True)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:27.550880Z", "iopub.status.busy": "2021-07-16T22:28:27.550236Z", "iopub.status.idle": "2021-07-16T22:28:27.583140Z", "shell.execute_reply": "2021-07-16T22:28:27.582704Z" } }, "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", "
abc
<object><int64><int64>
0a111
1b211
2c322
\n", "
\n" ], "text/plain": [ " a b c\n", " \n", "0 a 1 11\n", "1 b 2 11\n", "2 c 3 22" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(\n", " a = [c(\"a\", \"b\"), \"c\"],\n", " b = [[1,2], 3],\n", " c = c(11, 22)\n", ")\n", "df >> unnest(c(f.a, f.b))" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:27.614822Z", "iopub.status.busy": "2021-07-16T22:28:27.614040Z", "iopub.status.idle": "2021-07-16T22:28:27.617574Z", "shell.execute_reply": "2021-07-16T22:28:27.617933Z" } }, "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", "
abc
<object><int64><int64>
0a111
1a211
2b111
3b211
4c322
\n", "
\n" ], "text/plain": [ " a b c\n", " \n", "0 a 1 11\n", "1 a 2 11\n", "2 b 1 11\n", "3 b 2 11\n", "4 c 3 22" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> unnest(f.a) >> unnest(f.b)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 2 } ================================================ FILE: docs/notebooks/nth.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "respiratory-velvet", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:04.461490Z", "iopub.status.busy": "2021-07-16T22:28:04.459178Z", "iopub.status.idle": "2021-07-16T22:28:05.559045Z", "shell.execute_reply": "2021-07-16T22:28:05.559494Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ nth
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Extract the nth element of a vector\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/nth.html \n", "\n", "##### Args:\n", "  `x`: A vector \n", "  `n`: The index of the element to extract. \n", "  `order_by`: A variable or function of variables to order by. \n", "  `default`: A default value to return if `n` is out of bounds. \n", "\n", "##### Returns:\n", "  A value \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ first
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Extract the first element of a vector\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/nth.html \n", "\n", "##### Args:\n", "  `x`: A vector \n", "  `order_by`: A variable or function of variables to order by. \n", "  `default`: A default value to return if `x` is empty. \n", "\n", "##### Returns:\n", "  A value \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ last
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Extract the last element of a vector\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/nth.html \n", "\n", "##### Args:\n", "  `x`: A vector \n", "  `order_by`: A variable or function of variables to order by. \n", "  `default`: A default value to return if `x` is empty. \n", "\n", "##### Returns:\n", "  A value \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/nth.html\n", "%run nb_helpers.py\n", "\n", "from datar.all import nth, first, last\n", "\n", "nb_header(nth, first, last)" ] }, { "cell_type": "code", "execution_count": 2, "id": "suspected-addiction", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:05.566582Z", "iopub.status.busy": "2021-07-16T22:28:05.565966Z", "iopub.status.idle": "2021-07-16T22:28:05.581974Z", "shell.execute_reply": "2021-07-16T22:28:05.582386Z" } }, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = range(10)\n", "y = range(9, -1, -1)\n", "\n", "first(x)" ] }, { "cell_type": "code", "execution_count": 3, "id": "rural-rubber", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:05.593935Z", "iopub.status.busy": "2021-07-16T22:28:05.593386Z", "iopub.status.idle": "2021-07-16T22:28:05.610636Z", "shell.execute_reply": "2021-07-16T22:28:05.611118Z" } }, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "last(y)" ] }, { "cell_type": "code", "execution_count": 4, "id": "developing-fossil", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:05.627629Z", "iopub.status.busy": "2021-07-16T22:28:05.626943Z", "iopub.status.idle": "2021-07-16T22:28:05.643278Z", "shell.execute_reply": "2021-07-16T22:28:05.643642Z" } }, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nth(x, 1)" ] }, { "cell_type": "code", "execution_count": 5, "id": "three-assignment", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:05.653602Z", "iopub.status.busy": "2021-07-16T22:28:05.652989Z", "iopub.status.idle": "2021-07-16T22:28:05.670826Z", "shell.execute_reply": "2021-07-16T22:28:05.671225Z" } }, "outputs": [ { "data": { "text/plain": [ "5" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nth(x, 5)" ] }, { "cell_type": "code", "execution_count": 6, "id": "approximate-indonesia", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:05.684961Z", "iopub.status.busy": "2021-07-16T22:28:05.684355Z", "iopub.status.idle": "2021-07-16T22:28:05.700891Z", "shell.execute_reply": "2021-07-16T22:28:05.701266Z" } }, "outputs": [ { "data": { "text/plain": [ "8" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nth(x, -2)" ] }, { "cell_type": "code", "execution_count": 7, "id": "handy-stack", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:05.716492Z", "iopub.status.busy": "2021-07-16T22:28:05.713952Z", "iopub.status.idle": "2021-07-16T22:28:05.728899Z", "shell.execute_reply": "2021-07-16T22:28:05.729314Z" } }, "outputs": [ { "data": { "text/plain": [ "nan" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nth(x, 11)" ] }, { "cell_type": "code", "execution_count": 8, "id": "everyday-kinase", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:05.739057Z", "iopub.status.busy": "2021-07-16T22:28:05.738002Z", "iopub.status.idle": "2021-07-16T22:28:05.757661Z", "shell.execute_reply": "2021-07-16T22:28:05.758059Z" } }, "outputs": [ { "data": { "text/plain": [ "9" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "last(x)" ] }, { "cell_type": "code", "execution_count": 9, "id": "remarkable-remainder", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:05.770340Z", "iopub.status.busy": "2021-07-16T22:28:05.769772Z", "iopub.status.idle": "2021-07-16T22:28:05.785794Z", "shell.execute_reply": "2021-07-16T22:28:05.786195Z" } }, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "last(x, y)" ] }, { "cell_type": "code", "execution_count": 11, "id": "advanced-stations", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:05.798241Z", "iopub.status.busy": "2021-07-16T22:28:05.797643Z", "iopub.status.idle": "2021-07-16T22:28:05.810371Z", "shell.execute_reply": "2021-07-16T22:28:05.810843Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[TypeError] _first_obj() missing 1 required positional argument: 'x'\n" ] } ], "source": [ "with try_catch():\n", " first()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/other.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 2, "id": "5ddd5613", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:45.939425Z", "iopub.status.busy": "2021-07-16T22:27:45.938609Z", "iopub.status.idle": "2021-07-16T22:27:46.866192Z", "shell.execute_reply": "2021-07-16T22:27:46.866581Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ itemgetter
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Itemgetter as a function for verb\n", "\n", "In datar expression, we can do: \n", ">>> arr = [1,2,3] \n", ">>> tibble(x=2) >> mutate(y=arr[f.x]) \n", "\n", "Since `arr[f.x]` won't compile. We need to use the `itemgetter` operator: \n", ">>> tibble(x=2) >> mutate(y=itemgetter(arr, f.x)) \n", "\n", "##### Args:\n", "  `data`: The data to be get items from \n", "  `subscr`: The subscripts \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ attrgetter
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Attrgetter as a function for verb\n", "\n", "This is helpful when we want to access to an accessor \n", "(ie. CategoricalAccessor) from a SeriesGroupBy object \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ pd_str
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Pandas' str accessor for a Series (x.str)\n", "\n", "This is helpful when x is a SeriesGroupBy object \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ pd_cat
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Pandas' cat accessor for a Series (x.cat)\n", "\n", "This is helpful when x is a SeriesGroupBy object \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ pd_dt
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Pandas' dt accessor for a Series (x.dt)\n", "\n", "This is helpful when x is a SeriesGroupBy object \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# datar specific\n", "\n", "import numpy\n", "from datar import f\n", "from datar.data import iris\n", "from datar.base import as_date, factor, c\n", "from datar.other import *\n", "from datar.dplyr import mutate, group_by\n", "from datar.tibble import tibble\n", "\n", "%run nb_helpers.py\n", "nb_header(\n", " # get, \n", " # flatten, \n", " itemgetter, \n", " attrgetter, \n", " pd_str, \n", " pd_cat, \n", " pd_dt, \n", " book='datar',\n", ")" ] }, { "cell_type": "code", "execution_count": 3, "id": "079671c5", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:46.871734Z", "iopub.status.busy": "2021-07-16T22:27:46.871143Z", "iopub.status.idle": "2021-07-16T22:27:46.903396Z", "shell.execute_reply": "2021-07-16T22:27:46.903926Z" } }, "outputs": [], "source": [ "# iris >> get(c[:5])" ] }, { "cell_type": "code", "execution_count": 4, "id": "ee9b5bd7", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:46.914499Z", "iopub.status.busy": "2021-07-16T22:27:46.913928Z", "iopub.status.idle": "2021-07-16T22:27:46.983390Z", "shell.execute_reply": "2021-07-16T22:27:46.984132Z" } }, "outputs": [], "source": [ "# iris >> get(cols=f.Species)" ] }, { "cell_type": "code", "execution_count": 5, "id": "6a2638a7", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:46.989720Z", "iopub.status.busy": "2021-07-16T22:27:46.989062Z", "iopub.status.idle": "2021-07-16T22:27:46.992070Z", "shell.execute_reply": "2021-07-16T22:27:46.992928Z" } }, "outputs": [], "source": [ "# select single element\n", "# iris >> get(1, f.Species)" ] }, { "cell_type": "code", "execution_count": 6, "id": "0b9835c1", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:47.002937Z", "iopub.status.busy": "2021-07-16T22:27:47.002274Z", "iopub.status.idle": "2021-07-16T22:27:47.005992Z", "shell.execute_reply": "2021-07-16T22:27:47.005544Z" } }, "outputs": [], "source": [ "# get it as a single-element dataframe\n", "# iris >> get([1], f.Species)" ] }, { "cell_type": "code", "execution_count": 7, "id": "dceca6e4", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:47.016728Z", "iopub.status.busy": "2021-07-16T22:27:47.016117Z", "iopub.status.idle": "2021-07-16T22:27:47.019537Z", "shell.execute_reply": "2021-07-16T22:27:47.019077Z" } }, "outputs": [], "source": [ "# or \n", "# iris >> get(1, [f.Species])" ] }, { "cell_type": "code", "execution_count": 8, "id": "62ed1ae9", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:47.024658Z", "iopub.status.busy": "2021-07-16T22:27:47.024080Z", "iopub.status.idle": "2021-07-16T22:27:47.136793Z", "shell.execute_reply": "2021-07-16T22:27:47.137236Z" } }, "outputs": [], "source": [ "df = tibble(x=c[1:3], y=c[3:5])\n", "# df >> flatten()" ] }, { "cell_type": "code", "execution_count": 12, "id": "94649970", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:47.154788Z", "iopub.status.busy": "2021-07-16T22:27:47.154185Z", "iopub.status.idle": "2021-07-16T22:27:47.179272Z", "shell.execute_reply": "2021-07-16T22:27:47.179691Z" } }, "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", "
xyab
<int64><int64><object><object>
013bd
124ce
\n", "
\n" ], "text/plain": [ " x y a b\n", " \n", "0 1 3 b d\n", "1 2 4 c e" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr = numpy.array(['a', 'b', 'c', 'd', 'e'])\n", "# df >> mutate(a=arr[f.x], b=arr[f.y]) # Error\n", "df >> mutate(a=itemgetter(arr, f.x.values), b=itemgetter(arr, f.y.values))" ] }, { "cell_type": "code", "execution_count": 13, "id": "8056429c", "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", "
xa
<object><object>
0abcABC
1defDEF
\n", "
\n" ], "text/plain": [ " x a\n", " \n", "0 abc ABC\n", "1 def DEF" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x=[\"abc\", \"def\"])\n", "df >> mutate(a=attrgetter(f.x, 'str').upper())" ] }, { "cell_type": "code", "execution_count": 14, "id": "9b1726ad", "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", "
xa
<object><object>
0abcABC
1defDEF
\n", "
\n" ], "text/plain": [ " x a\n", " \n", "0 abc ABC\n", "1 def DEF" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# or\n", "# df >> mutate(a=pd_str(f.x).upper())\n", "# or\n", "df >> mutate(a=f.x.str.upper())" ] }, { "cell_type": "code", "execution_count": 15, "id": "05d65cc8", "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", "
xga
<object><int64><object>
0abc1ab
1def2de
\n", "
\n", "

TibbleGrouped: g (n=2)" ], "text/plain": [ " x g a\n", " \n", "0 abc 1 ab\n", "1 def 2 de\n", "[TibbleGrouped: g (n=2)]" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# but when df is grouped\n", "gf = df >> group_by(g=[1, 2])\n", "# pd_str(gf.x)[:2].obj\n", "gf >> mutate(a=pd_str(gf.x)[:2])" ] }, { "cell_type": "code", "execution_count": 16, "id": "081a9d1e", "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", "
xgmonth
<datetime64[ns]><int64><int64>
02022-01-0111
12022-12-02212
\n", "
\n", "

TibbleGrouped: g (n=2)" ], "text/plain": [ " x g month\n", " \n", "0 2022-01-01 1 1\n", "1 2022-12-02 2 12\n", "[TibbleGrouped: g (n=2)]" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gf = (\n", " tibble(x=[\"2022-01-01\", \"2022-12-02\"])\n", " >> mutate(x=as_date(f.x, format=\"%Y-%m-%d\"))\n", " >> group_by(g=[1, 2])\n", ")\n", "gf >> mutate(month=pd_dt(gf.x).month)" ] }, { "cell_type": "code", "execution_count": 17, "id": "b2aaa7f0", "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", "
xgcodes
<category><int64><int8>
0110
1221
\n", "
\n", "

TibbleGrouped: g (n=2)" ], "text/plain": [ " x g codes\n", " \n", "0 1 1 0\n", "1 2 2 1\n", "[TibbleGrouped: g (n=2)]" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gf = (\n", " tibble(x=factor([1, 2], levels=[1, 2, 3]))\n", " >> group_by(g=[1, 2])\n", ")\n", "gf >> mutate(codes=pd_cat(gf.x).codes)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/pack.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:10.595610Z", "iopub.status.busy": "2021-07-16T22:28:10.594966Z", "iopub.status.idle": "2021-07-16T22:28:11.430759Z", "shell.execute_reply": "2021-07-16T22:28:11.431147Z" } }, "outputs": [ { "data": { "text/html": [ "

Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ pack
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Makes df narrow by collapsing a set of columns into a single df-column.\n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `**cols`: Columns to pack \n", "  `_names_sep`: If `None`, the default, the names will be left as is. \n", "    Inner names will come from the former outer names \n", "    If a string, the inner and outer names will be used together. \n", "    The names of the new outer columns will be formed by pasting \n", "    together the outer and the inner column names, separated by \n", "    `_names_sep`. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ unpack
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Makes df wider by expanding df-columns back out into individual columns.\n", "\n", "For empty columns, the column is kept asis, instead of removing it. \n", "\n", "##### Args:\n", "  `data`: A data frame \n", "  `cols`: Columns to unpack \n", "  `names_sep`: If `None`, the default, the names will be left as is. \n", "    Inner names will come from the former outer names \n", "    If a string, the inner and outer names will be used together. \n", "    The names of the new outer columns will be formed by pasting \n", "    together the outer and the inner column names, separated by \n", "    `_names_sep`. \n", "\n", "  `name_repair`: treatment of problematic column names: \n", "    - \"minimal\": No name repair or checks, beyond basic existence,\n", "\n", "    - \"unique\": Make sure names are unique and not empty,\n", "\n", "    - \"check_unique\": (default value), no name repair,\n", "      but check they are unique, \n", "\n", "    - \"universal\": Make the names unique and syntactic\n", "\n", "    - a function: apply custom name repair\n", "\n", "##### Returns:\n", "  Data frame with given columns unpacked. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%run nb_helpers.py\n", "\n", "from datar.data import iris\n", "from datar.all import *\n", "\n", "nb_header(pack, unpack)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:11.439093Z", "iopub.status.busy": "2021-07-16T22:28:11.437591Z", "iopub.status.idle": "2021-07-16T22:28:11.582404Z", "shell.execute_reply": "2021-07-16T22:28:11.582851Z" } }, "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", "
x1x2x3y
<int64><int64><int64><int64>
01471
12582
\n", "
\n" ], "text/plain": [ " x1 x2 x3 y\n", " \n", "0 1 4 7 1\n", "1 2 5 8 2" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x1 = c[1:3], x2 = c[4:6], x3 = c[7:9], y = c[1:3])\n", "df" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:11.623762Z", "iopub.status.busy": "2021-07-16T22:28:11.612492Z", "iopub.status.idle": "2021-07-16T22:28:11.687112Z", "shell.execute_reply": "2021-07-16T22:28:11.687525Z" } }, "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", "
yx$x1x$x2x$x3
<int64><int64><int64><int64>
01147
12258
\n", "
\n" ], "text/plain": [ " y x$x1 x$x2 x$x3\n", " \n", "0 1 1 4 7\n", "1 2 2 5 8" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> pack(x=starts_with('x'))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:11.703242Z", "iopub.status.busy": "2021-07-16T22:28:11.702526Z", "iopub.status.idle": "2021-07-16T22:28:11.710324Z", "shell.execute_reply": "2021-07-16T22:28:11.711080Z" } }, "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", "
x$x1x$x2x$x3y$y
<int64><int64><int64><int64>
01471
12582
\n", "
\n" ], "text/plain": [ " x$x1 x$x2 x$x3 y$y\n", " \n", "0 1 4 7 1\n", "1 2 5 8 2" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> pack(x=c(f.x1, f.x2, f.x3), y=f.y)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:11.736525Z", "iopub.status.busy": "2021-07-16T22:28:11.735912Z", "iopub.status.idle": "2021-07-16T22:28:11.742841Z", "shell.execute_reply": "2021-07-16T22:28:11.743497Z" } }, "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", "
SpeciesSepal$LengthSepal$WidthPetal$LengthPetal$Width
<object><float64><float64><float64><float64>
0setosa5.13.51.40.2
1setosa4.93.01.40.2
2setosa4.73.21.30.2
3setosa4.63.11.50.2
..................
4setosa5.03.61.40.2
145virginica6.73.05.22.3
146virginica6.32.55.01.9
147virginica6.53.05.22.0
148virginica6.23.45.42.3
149virginica5.93.05.11.8
\n", "

150 rows × 5 columns

\n", "
\n" ], "text/plain": [ " Species Sepal$Length Sepal$Width Petal$Length Petal$Width\n", " \n", "0 setosa 5.1 3.5 1.4 0.2\n", "1 setosa 4.9 3.0 1.4 0.2\n", "2 setosa 4.7 3.2 1.3 0.2\n", "3 setosa 4.6 3.1 1.5 0.2\n", ".. ... ... ... ... ...\n", "4 setosa 5.0 3.6 1.4 0.2\n", "145 virginica 6.7 3.0 5.2 2.3\n", "146 virginica 6.3 2.5 5.0 1.9\n", "147 virginica 6.5 3.0 5.2 2.0\n", "148 virginica 6.2 3.4 5.4 2.3\n", "149 virginica 5.9 3.0 5.1 1.8\n", "\n", "[150 rows x 5 columns]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> pack(\n", " Sepal=starts_with(\"Sepal\"),\n", " Petal=starts_with(\"Petal\"),\n", " _names_sep=\"_\"\n", ")" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:11.791974Z", "iopub.status.busy": "2021-07-16T22:28:11.791196Z", "iopub.status.idle": "2021-07-16T22:28:11.824763Z", "shell.execute_reply": "2021-07-16T22:28:11.825161Z" } }, "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", "
xy$ay$bz$Xz$Yz$Z
<int64><int64><int64><object><float64><object>
0114a0.286761True
1223b0.532775False
2332c0.497844NaN
\n", "
\n" ], "text/plain": [ " x y$a y$b z$X z$Y z$Z\n", " \n", "0 1 1 4 a 0.286761 True\n", "1 2 2 3 b 0.532775 False\n", "2 3 3 2 c 0.497844 NaN" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Unpacking ===========================================================\n", "\n", "df = tibble(\n", " x = c[1:4],\n", " y = tibble(a = c[1:4], b = c[4:1]),\n", " z = tibble(X = c(\"a\", \"b\", \"c\"), Y = runif(3), Z = c(TRUE, FALSE, NA))\n", ")\n", "df" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:11.848630Z", "iopub.status.busy": "2021-07-16T22:28:11.847790Z", "iopub.status.idle": "2021-07-16T22:28:11.896413Z", "shell.execute_reply": "2021-07-16T22:28:11.895768Z" } }, "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", "
xabz$Xz$Yz$Z
<int64><int64><int64><object><float64><object>
0114a0.286761True
1223b0.532775False
2332c0.497844NaN
\n", "
\n" ], "text/plain": [ " x a b z$X z$Y z$Z\n", " \n", "0 1 1 4 a 0.286761 True\n", "1 2 2 3 b 0.532775 False\n", "2 3 3 2 c 0.497844 NaN" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> unpack(f.y)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:11.916193Z", "iopub.status.busy": "2021-07-16T22:28:11.915622Z", "iopub.status.idle": "2021-07-16T22:28:11.931037Z", "shell.execute_reply": "2021-07-16T22:28:11.931472Z" } }, "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", "
xabXYZ
<int64><int64><int64><object><float64><object>
0114a0.286761True
1223b0.532775False
2332c0.497844NaN
\n", "
\n" ], "text/plain": [ " x a b X Y Z\n", " \n", "0 1 1 4 a 0.286761 True\n", "1 2 2 3 b 0.532775 False\n", "2 3 3 2 c 0.497844 NaN" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> unpack(c(f.y, f.z))" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:11.947604Z", "iopub.status.busy": "2021-07-16T22:28:11.946968Z", "iopub.status.idle": "2021-07-16T22:28:11.954544Z", "shell.execute_reply": "2021-07-16T22:28:11.955047Z" } }, "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", "
xy_ay_bz_Xz_Yz_Z
<int64><int64><int64><object><float64><object>
0114a0.286761True
1223b0.532775False
2332c0.497844NaN
\n", "
\n" ], "text/plain": [ " x y_a y_b z_X z_Y z_Z\n", " \n", "0 1 1 4 a 0.286761 True\n", "1 2 2 3 b 0.532775 False\n", "2 3 3 2 c 0.497844 NaN" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> unpack(c(f.y, f.z), names_sep=\"_\")\n" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:11.965059Z", "iopub.status.busy": "2021-07-16T22:28:11.964492Z", "iopub.status.idle": "2021-07-16T22:28:11.970973Z", "shell.execute_reply": "2021-07-16T22:28:11.971380Z" } }, "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", "
xabXYZ
<int64><int64><int64><object><float64><object>
0114a0.286761True
1223b0.532775False
2332c0.497844NaN
\n", "
\n" ], "text/plain": [ " x a b X Y Z\n", " \n", "0 1 1 4 a 0.286761 True\n", "1 2 2 3 b 0.532775 False\n", "2 3 3 2 c 0.497844 NaN" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "with try_catch():\n", " # indexes from inner data frame counts\n", " df >> unpack(c(2,3))" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:11.981674Z", "iopub.status.busy": "2021-07-16T22:28:11.981042Z", "iopub.status.idle": "2021-07-16T22:28:11.994499Z", "shell.execute_reply": "2021-07-16T22:28:11.995255Z" } }, "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", "
xabXYZ
<int64><int64><int64><object><float64><object>
0114a0.286761True
1223b0.532775False
2332c0.497844NaN
\n", "
\n" ], "text/plain": [ " x a b X Y Z\n", " \n", "0 1 1 4 a 0.286761 True\n", "1 2 2 3 b 0.532775 False\n", "2 3 3 2 c 0.497844 NaN" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> unpack(c(2,4))" ] } ], "metadata": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" }, "kernelspec": { "display_name": "Python 3.7.8 64-bit ('base': conda)", "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.9.5" } }, "nbformat": 4, "nbformat_minor": 2 } ================================================ FILE: docs/notebooks/pivot_longer.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "6401a1db", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:18.775999Z", "iopub.status.busy": "2021-07-16T22:27:18.775210Z", "iopub.status.idle": "2021-07-16T22:27:19.789379Z", "shell.execute_reply": "2021-07-16T22:27:19.790261Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ pivot_longer
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ " \"lengthens\" data, increasing the number of rows and\n", " decreasing the number of columns.\n", "\n", " The row order is a bit different from `tidyr` and `pandas.DataFrame.melt`.\n", " >>> df = tibble(x=c[1:2], y=c[3:4])\n", " >>> pivot_longer(df, f[f.x:f.y])\n", " >>> # name value\n", " >>> # 0 x 1\n", " >>> # 1 x 2\n", " >>> # 2 y 3\n", " >>> # 3 y 4\n", " But with `tidyr::pivot_longer`, the output will be:\n", " >>> # # A tibble: 4 x 2\n", " >>> # name value\n", " >>> # \n", " >>> # 1 x 1\n", " >>> # 2 y 3\n", " >>> # 3 x 2\n", " >>> # 4 y 4\n", "\n", " Args:\n", " _data: A data frame to pivot.\n", " cols: Columns to pivot into longer format.\n", " names_to: A string specifying the name of the column to create from\n", " the data stored in the column names of data.\n", " Can be a character vector, creating multiple columns, if names_sep\n", " or names_pattern is provided. In this case, there are two special\n", " values you can take advantage of:\n", " - `None`/`NA`/`NULL` will discard that component of the name.\n", " - `.value`/`_value` indicates that component of the name defines\n", " the name of the column containing the cell values,\n", " overriding values_to.\n", " - Different as `tidyr`: With `.value`/`_value`, if there are other\n", " parts of the names to distinguish the groups, they must be\n", " captured. For example, use `r'(\\w)_(\\d)'` to match `'a_1'` and\n", " `['.value', NA]` to discard the suffix, instead of use\n", " `r'(\\w)_\\d'` to match.\n", " names_prefix: A regular expression used to remove matching text from\n", " the start of each variable name.\n", " names_sep: and\n", " names_pattern: If names_to contains multiple values,\n", " these arguments control how the column name is broken up.\n", " names_sep takes the same specification as separate(), and\n", " can either be a numeric vector (specifying positions to break on),\n", " or a single string (specifying a regular expression to split on).\n", " names_pattern: takes the same specification as extract(),\n", " a regular expression containing matching groups (()).\n", " names_dtypes: and\n", " values_dtypes: A list of column name-prototype pairs.\n", " A prototype (or dtypes for short) is a zero-length vector\n", " (like integer() or numeric()) that defines the type, class, and\n", " attributes of a vector. Use these arguments if you want to confirm\n", " that the created columns are the types that you expect.\n", " Note that if you want to change (instead of confirm) the types\n", " of specific columns, you should use names_transform or\n", " values_transform instead.\n", " names_transform: and\n", " values_transform: A list of column name-function pairs.\n", " Use these arguments if you need to change the types of\n", " specific columns. For example,\n", " names_transform = dict(week = as.integer) would convert a\n", " character variable called week to an integer.\n", " If not specified, the type of the columns generated from names_to\n", " will be character, and the type of the variables generated from\n", " values_to will be the common type of the input columns used to\n", " generate them.\n", " names_repair: Not supported yet.\n", " values_to: A string specifying the name of the column to create from\n", " the data stored in cell values. If names_to is a character\n", " containing the special `.value`/`_value` sentinel, this value\n", " will be ignored, and the name of the value column will be derived\n", " from part of the existing column names.\n", " values_drop_na: If TRUE, will drop rows that contain only NAs in\n", " the value_to column. This effectively converts explicit missing\n", " values to implicit missing values, and should generally be used\n", " only when missing values in data were created by its structure.\n", " names_repair: treatment of problematic column names:\n", " - \"minimal\": No name repair or checks, beyond basic existence,\n", " - \"unique\": Make sure names are unique and not empty,\n", " - \"check_unique\": (default value), no name repair,\n", " but check they are unique,\n", " - \"universal\": Make the names unique and syntactic\n", " - a function: apply custom name repair\n", "\n", " Returns:\n", " The pivoted dataframe.\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://tidyr.tidyverse.org/reference/pivot_longer.html\n", "%run nb_helpers.py\n", "\n", "from datar.data import relig_income, billboard, who, anscombe\n", "from datar.all import *\n", "\n", "nb_header(pivot_longer)" ] }, { "cell_type": "code", "execution_count": 2, "id": "cde8ffb4", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:19.810290Z", "iopub.status.busy": "2021-07-16T22:27:19.809669Z", "iopub.status.idle": "2021-07-16T22:27:19.819890Z", "shell.execute_reply": "2021-07-16T22:27:19.820268Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
religion<$10k$10-20k$20-30k$30-40k$40-50k$50-75k$75-100k$100-150k>150kDon't know/refused
<object><int64><int64><int64><int64><int64><int64><int64><int64><int64><int64>
0Agnostic27346081761371221098496
1Atheist12273752357073597476
2Buddhist27213034335862395354
3Catholic41861773267063811169497926331489
4Don’t know/refused151415111035211718116
5Evangelical Prot575869106498288114869497234141529
6Hindu1979113447485437
7Historically Black Prot2282442362381972231318178339
8Jehovah's Witness2027242421301511637
9Jewish1919252530956987151162
10Mainline Prot28949561965565111079397536341328
11Mormon294048515611285494269
12Muslim67910923168622
13Orthodox13172332324738424673
14Other Christian971113131418141218
15Other Faiths20334046496346404171
16Other World Religions5234273448
17Unaffiliated217299374365341528407321258597
\n", "
\n" ], "text/plain": [ " religion <$10k $10-20k $20-30k $30-40k $40-50k \\\n", " \n", "0 Agnostic 27 34 60 81 76 \n", "1 Atheist 12 27 37 52 35 \n", "2 Buddhist 27 21 30 34 33 \n", "3 Catholic 418 617 732 670 638 \n", "4 Don’t know/refused 15 14 15 11 10 \n", "5 Evangelical Prot 575 869 1064 982 881 \n", "6 Hindu 1 9 7 9 11 \n", "7 Historically Black Prot 228 244 236 238 197 \n", "8 Jehovah's Witness 20 27 24 24 21 \n", "9 Jewish 19 19 25 25 30 \n", "10 Mainline Prot 289 495 619 655 651 \n", "11 Mormon 29 40 48 51 56 \n", "12 Muslim 6 7 9 10 9 \n", "13 Orthodox 13 17 23 32 32 \n", "14 Other Christian 9 7 11 13 13 \n", "15 Other Faiths 20 33 40 46 49 \n", "16 Other World Religions 5 2 3 4 2 \n", "17 Unaffiliated 217 299 374 365 341 \n", "\n", " $50-75k $75-100k $100-150k >150k Don't know/refused \n", " \n", "0 137 122 109 84 96 \n", "1 70 73 59 74 76 \n", "2 58 62 39 53 54 \n", "3 1116 949 792 633 1489 \n", "4 35 21 17 18 116 \n", "5 1486 949 723 414 1529 \n", "6 34 47 48 54 37 \n", "7 223 131 81 78 339 \n", "8 30 15 11 6 37 \n", "9 95 69 87 151 162 \n", "10 1107 939 753 634 1328 \n", "11 112 85 49 42 69 \n", "12 23 16 8 6 22 \n", "13 47 38 42 46 73 \n", "14 14 18 14 12 18 \n", "15 63 46 40 41 71 \n", "16 7 3 4 4 8 \n", "17 528 407 321 258 597 " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "relig_income" ] }, { "cell_type": "code", "execution_count": 3, "id": "439f9d5c", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:19.868234Z", "iopub.status.busy": "2021-07-16T22:27:19.867668Z", "iopub.status.idle": "2021-07-16T22:27:20.026238Z", "shell.execute_reply": "2021-07-16T22:27:20.026658Z" } }, "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", "
religionincomecount
<object><object><int64>
0Agnostic<$10k27
1Atheist<$10k12
2Buddhist<$10k27
3Catholic<$10k418
............
4Don’t know/refused<$10k15
175OrthodoxDon't know/refused73
176Other ChristianDon't know/refused18
177Other FaithsDon't know/refused71
178Other World ReligionsDon't know/refused8
179UnaffiliatedDon't know/refused597
\n", "

180 rows × 3 columns

\n", "
\n" ], "text/plain": [ " religion income count\n", " \n", "0 Agnostic <$10k 27\n", "1 Atheist <$10k 12\n", "2 Buddhist <$10k 27\n", "3 Catholic <$10k 418\n", ".. ... ... ...\n", "4 Don’t know/refused <$10k 15\n", "175 Orthodox Don't know/refused 73\n", "176 Other Christian Don't know/refused 18\n", "177 Other Faiths Don't know/refused 71\n", "178 Other World Religions Don't know/refused 8\n", "179 Unaffiliated Don't know/refused 597\n", "\n", "[180 rows x 3 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "relig_income >> \\\n", " pivot_longer(~f.religion, names_to=\"income\", values_to=\"count\")" ] }, { "cell_type": "code", "execution_count": 4, "id": "3f770536", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:20.063860Z", "iopub.status.busy": "2021-07-16T22:27:20.063122Z", "iopub.status.idle": "2021-07-16T22:27:20.068837Z", "shell.execute_reply": "2021-07-16T22:27:20.069227Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
artisttrackdate.enteredwk1wk2wk3wk4wk5wk6wk7...wk67wk68wk69wk70wk71wk72wk73wk74wk75wk76
<object><object><object><int64><float64><float64><float64><float64><float64><float64>...<float64><float64><float64><float64><float64><float64><float64><float64><float64><float64>
02 PacBaby Don't Cry (Keep...2000-02-268782.072.077.087.094.099.0...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
12Ge+herThe Hardest Part Of ...2000-09-029187.092.0NaNNaNNaNNaN...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
23 Doors DownKryptonite2000-04-088170.068.067.066.057.054.0...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
33 Doors DownLoser2000-10-217676.072.069.067.065.055.0...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
..................................................................
4504 BoyzWobble Wobble2000-04-155734.025.017.017.031.036.0...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
312Yankee GreyAnother Nine Minutes2000-04-298683.077.074.083.079.088.0...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
313Yearwood, TrishaReal Live Woman2000-04-018583.083.082.081.091.0NaN...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
314Ying Yang TwinsWhistle While You Tw...2000-03-189594.091.085.084.078.074.0...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
315Zombie NationKernkraft 4002000-09-029999.0NaNNaNNaNNaNNaN...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
316matchbox twentyBent2000-04-296037.029.024.022.021.018.0...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
\n", "

317 rows × 79 columns

\n", "
\n" ], "text/plain": [ " artist track date.entered wk1 wk2 \\\n", " \n", "0 2 Pac Baby Don't Cry (Keep... 2000-02-26 87 82.0 \n", "1 2Ge+her The Hardest Part Of ... 2000-09-02 91 87.0 \n", "2 3 Doors Down Kryptonite 2000-04-08 81 70.0 \n", "3 3 Doors Down Loser 2000-10-21 76 76.0 \n", ".. ... ... ... ... ... \n", "4 504 Boyz Wobble Wobble 2000-04-15 57 34.0 \n", "312 Yankee Grey Another Nine Minutes 2000-04-29 86 83.0 \n", "313 Yearwood, Trisha Real Live Woman 2000-04-01 85 83.0 \n", "314 Ying Yang Twins Whistle While You Tw... 2000-03-18 95 94.0 \n", "315 Zombie Nation Kernkraft 400 2000-09-02 99 99.0 \n", "316 matchbox twenty Bent 2000-04-29 60 37.0 \n", "\n", " wk3 wk4 wk5 wk6 wk7 ... wk67 \\\n", " ... \n", "0 72.0 77.0 87.0 94.0 99.0 ... NaN \n", "1 92.0 NaN NaN NaN NaN ... NaN \n", "2 68.0 67.0 66.0 57.0 54.0 ... NaN \n", "3 72.0 69.0 67.0 65.0 55.0 ... NaN \n", ".. ... ... ... ... ... ... ... \n", "4 25.0 17.0 17.0 31.0 36.0 ... NaN \n", "312 77.0 74.0 83.0 79.0 88.0 ... NaN \n", "313 83.0 82.0 81.0 91.0 NaN ... NaN \n", "314 91.0 85.0 84.0 78.0 74.0 ... NaN \n", "315 NaN NaN NaN NaN NaN ... NaN \n", "316 29.0 24.0 22.0 21.0 18.0 NaN \n", "\n", " wk68 wk69 wk70 wk71 wk72 wk73 wk74 \\\n", " \n", "0 NaN NaN NaN NaN NaN NaN NaN \n", "1 NaN NaN NaN NaN NaN NaN NaN \n", "2 NaN NaN NaN NaN NaN NaN NaN \n", "3 NaN NaN NaN NaN NaN NaN NaN \n", ".. ... ... ... ... ... ... ... \n", "4 NaN NaN NaN NaN NaN NaN NaN \n", "312 NaN NaN NaN NaN NaN NaN NaN \n", "313 NaN NaN NaN NaN NaN NaN NaN \n", "314 NaN NaN NaN NaN NaN NaN NaN \n", "315 NaN NaN NaN NaN NaN NaN NaN \n", "316 NaN NaN NaN NaN NaN NaN NaN \n", "\n", " wk75 wk76 \n", " \n", "0 NaN NaN \n", "1 NaN NaN \n", "2 NaN NaN \n", "3 NaN NaN \n", ".. ... ... \n", "4 NaN NaN \n", "312 NaN NaN \n", "313 NaN NaN \n", "314 NaN NaN \n", "315 NaN NaN \n", "316 NaN NaN \n", "\n", "[317 rows x 79 columns]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "billboard" ] }, { "cell_type": "code", "execution_count": 5, "id": "a84475c0", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:20.082615Z", "iopub.status.busy": "2021-07-16T22:27:20.081826Z", "iopub.status.idle": "2021-07-16T22:27:20.141538Z", "shell.execute_reply": "2021-07-16T22:27:20.140761Z" } }, "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", "
artistdate.enteredtrackweekrank
<object><object><object><object><float64>
02 Pac2000-02-26Baby Don't Cry (Keep...187.0
12Ge+her2000-09-02The Hardest Part Of ...191.0
23 Doors Down2000-04-08Kryptonite181.0
33 Doors Down2000-10-21Loser176.0
..................
4504 Boyz2000-04-15Wobble Wobble157.0
19716Creed1999-09-11Higher6350.0
19833Lonestar1999-06-05Amazed6345.0
20033Creed1999-09-11Higher6450.0
20150Lonestar1999-06-05Amazed6450.0
20350Creed1999-09-11Higher6549.0
\n", "

5307 rows × 5 columns

\n", "
\n" ], "text/plain": [ " artist date.entered track week rank\n", " \n", "0 2 Pac 2000-02-26 Baby Don't Cry (Keep... 1 87.0\n", "1 2Ge+her 2000-09-02 The Hardest Part Of ... 1 91.0\n", "2 3 Doors Down 2000-04-08 Kryptonite 1 81.0\n", "3 3 Doors Down 2000-10-21 Loser 1 76.0\n", "... ... ... ... ... ...\n", "4 504 Boyz 2000-04-15 Wobble Wobble 1 57.0\n", "19716 Creed 1999-09-11 Higher 63 50.0\n", "19833 Lonestar 1999-06-05 Amazed 63 45.0\n", "20033 Creed 1999-09-11 Higher 64 50.0\n", "20150 Lonestar 1999-06-05 Amazed 64 50.0\n", "20350 Creed 1999-09-11 Higher 65 49.0\n", "\n", "[5307 rows x 5 columns]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "billboard >> \\\n", " pivot_longer(\n", " cols = starts_with(\"wk\"),\n", " names_to = \"week\",\n", " names_prefix = \"wk\",\n", " values_to = \"rank\",\n", " values_drop_na = TRUE\n", " )" ] }, { "cell_type": "code", "execution_count": 6, "id": "8a289d74", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:20.166872Z", "iopub.status.busy": "2021-07-16T22:27:20.166271Z", "iopub.status.idle": "2021-07-16T22:27:22.170997Z", "shell.execute_reply": "2021-07-16T22:27:22.171392Z" } }, "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", "
countryiso2iso3newrel_f65yeardiagnosisgenderagecount
<object><object><object><float64><int64><object><object><object><float64>
0AfghanistanAFAFGNaN1980spm014NaN
1AfghanistanAFAFGNaN1981spm014NaN
2AfghanistanAFAFGNaN1982spm014NaN
3AfghanistanAFAFGNaN1983spm014NaN
..............................
4AfghanistanAFAFGNaN1984spm014NaN
398195ZimbabweZWZWENaN2009relf5564NaN
398196ZimbabweZWZWENaN2010relf5564NaN
398197ZimbabweZWZWENaN2011relf5564NaN
398198ZimbabweZWZWENaN2012relf5564NaN
398199ZimbabweZWZWE725.02013relf5564811.0
\n", "

398200 rows × 9 columns

\n", "
\n" ], "text/plain": [ " country iso2 iso3 newrel_f65 year diagnosis gender \\\n", " \n", "0 Afghanistan AF AFG NaN 1980 sp m \n", "1 Afghanistan AF AFG NaN 1981 sp m \n", "2 Afghanistan AF AFG NaN 1982 sp m \n", "3 Afghanistan AF AFG NaN 1983 sp m \n", "... ... ... ... ... ... ... ... \n", "4 Afghanistan AF AFG NaN 1984 sp m \n", "398195 Zimbabwe ZW ZWE NaN 2009 rel f \n", "398196 Zimbabwe ZW ZWE NaN 2010 rel f \n", "398197 Zimbabwe ZW ZWE NaN 2011 rel f \n", "398198 Zimbabwe ZW ZWE NaN 2012 rel f \n", "398199 Zimbabwe ZW ZWE 725.0 2013 rel f \n", "\n", " age count \n", " \n", "0 014 NaN \n", "1 014 NaN \n", "2 014 NaN \n", "3 014 NaN \n", "... ... ... \n", "4 014 NaN \n", "398195 5564 NaN \n", "398196 5564 NaN \n", "398197 5564 NaN \n", "398198 5564 NaN \n", "398199 5564 811.0 \n", "\n", "[398200 rows x 9 columns]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "who >> pivot_longer(\n", " cols = f[f.new_sp_m014:f.newrel_f65],\n", " names_to = c(\"diagnosis\", \"gender\", \"age\"),\n", " names_pattern = r\"new_?(.*)_(.)(.*)\",\n", " values_to = \"count\"\n", ")" ] }, { "cell_type": "code", "execution_count": 7, "id": "14c1a827", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:22.190872Z", "iopub.status.busy": "2021-07-16T22:27:22.190173Z", "iopub.status.idle": "2021-07-16T22:27:22.205577Z", "shell.execute_reply": "2021-07-16T22:27:22.205946Z" } }, "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", "
x1x2x3x4y1y2y3y4
<int64><int64><int64><int64><float64><float64><float64><float64>
010101088.049.147.466.58
188886.958.146.775.76
213131387.588.7412.747.71
399988.818.777.118.84
411111188.339.267.818.47
514141489.968.108.847.04
666687.246.136.085.25
7444194.263.105.3912.50
8121212810.849.138.155.56
977784.827.266.427.91
1055585.684.745.736.89
\n", "
\n" ], "text/plain": [ " x1 x2 x3 x4 y1 y2 y3 y4\n", " \n", "0 10 10 10 8 8.04 9.14 7.46 6.58\n", "1 8 8 8 8 6.95 8.14 6.77 5.76\n", "2 13 13 13 8 7.58 8.74 12.74 7.71\n", "3 9 9 9 8 8.81 8.77 7.11 8.84\n", "4 11 11 11 8 8.33 9.26 7.81 8.47\n", "5 14 14 14 8 9.96 8.10 8.84 7.04\n", "6 6 6 6 8 7.24 6.13 6.08 5.25\n", "7 4 4 4 19 4.26 3.10 5.39 12.50\n", "8 12 12 12 8 10.84 9.13 8.15 5.56\n", "9 7 7 7 8 4.82 7.26 6.42 7.91\n", "10 5 5 5 8 5.68 4.74 5.73 6.89" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "anscombe" ] }, { "cell_type": "code", "execution_count": 8, "id": "30591069", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:22.300082Z", "iopub.status.busy": "2021-07-16T22:27:22.299515Z", "iopub.status.idle": "2021-07-16T22:27:22.427829Z", "shell.execute_reply": "2021-07-16T22:27:22.428279Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
setxy
<object><float64><float64>
0110.08.04
1210.09.14
2310.07.46
348.06.58
418.06.95
528.08.14
638.06.77
748.05.76
8113.07.58
9213.08.74
10313.012.74
1148.07.71
1219.08.81
1329.08.77
1439.07.11
1548.08.84
16111.08.33
17211.09.26
18311.07.81
1948.08.47
20114.09.96
21214.08.10
22314.08.84
2348.07.04
2416.07.24
2526.06.13
2636.06.08
2748.05.25
2814.04.26
2924.03.10
3034.05.39
31419.012.50
32112.010.84
33212.09.13
34312.08.15
3548.05.56
3617.04.82
3727.07.26
3837.06.42
3948.07.91
4015.05.68
4125.04.74
4235.05.73
4348.06.89
\n", "
\n" ], "text/plain": [ " set x y\n", " \n", "0 1 10.0 8.04\n", "1 2 10.0 9.14\n", "2 3 10.0 7.46\n", "3 4 8.0 6.58\n", "4 1 8.0 6.95\n", "5 2 8.0 8.14\n", "6 3 8.0 6.77\n", "7 4 8.0 5.76\n", "8 1 13.0 7.58\n", "9 2 13.0 8.74\n", "10 3 13.0 12.74\n", "11 4 8.0 7.71\n", "12 1 9.0 8.81\n", "13 2 9.0 8.77\n", "14 3 9.0 7.11\n", "15 4 8.0 8.84\n", "16 1 11.0 8.33\n", "17 2 11.0 9.26\n", "18 3 11.0 7.81\n", "19 4 8.0 8.47\n", "20 1 14.0 9.96\n", "21 2 14.0 8.10\n", "22 3 14.0 8.84\n", "23 4 8.0 7.04\n", "24 1 6.0 7.24\n", "25 2 6.0 6.13\n", "26 3 6.0 6.08\n", "27 4 8.0 5.25\n", "28 1 4.0 4.26\n", "29 2 4.0 3.10\n", "30 3 4.0 5.39\n", "31 4 19.0 12.50\n", "32 1 12.0 10.84\n", "33 2 12.0 9.13\n", "34 3 12.0 8.15\n", "35 4 8.0 5.56\n", "36 1 7.0 4.82\n", "37 2 7.0 7.26\n", "38 3 7.0 6.42\n", "39 4 8.0 7.91\n", "40 1 5.0 5.68\n", "41 2 5.0 4.74\n", "42 3 5.0 5.73\n", "43 4 8.0 6.89" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "anscombe >> \\\n", " pivot_longer(everything(),\n", " names_to = c(\".value\", \"set\"),\n", " names_pattern = r\"(.)(.)\"\n", " )" ] }, { "cell_type": "code", "execution_count": null, "id": "7117e082", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/pivot_wider.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "weekly-pavilion", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:49.588782Z", "iopub.status.busy": "2021-07-16T22:27:49.587741Z", "iopub.status.idle": "2021-07-16T22:27:50.557794Z", "shell.execute_reply": "2021-07-16T22:27:50.558214Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ pivot_wider
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ " \"widens\" data, increasing the number of columns and decreasing\n", " the number of rows.\n", "\n", " Args:\n", " _data: A data frame to pivot.\n", " id_cols: A set of columns that uniquely identifies each observation.\n", " Defaults to all columns in data except for the columns specified\n", " in names_from and values_from.\n", " names_from: and\n", " values_from: A pair of arguments describing which column\n", " (or columns) to get the name of the output column (names_from),\n", " and which column (or columns) to get the cell values from\n", " (values_from).\n", " names_prefix: String added to the start of every variable name.\n", " names_sep: If names_from or values_from contains multiple variables,\n", " this will be used to join their values together into a single\n", " string to use as a column name.\n", " names_glue: Instead of names_sep and names_prefix, you can supply\n", " a glue specification that uses the names_from columns\n", " (and special _value) to create custom column names.\n", " names_sort: Should the column names be sorted? If FALSE, the default,\n", " column names are ordered by first appearance.\n", " names_repair: todo\n", " values_fill: Optionally, a (scalar) value that specifies what\n", " each value should be filled in with when missing.\n", " values_fn: Optionally, a function applied to the value in each cell\n", " in the output. You will typically use this when the combination\n", " of `id_cols` and value column does not uniquely identify\n", " an observation.\n", " This can be a dict you want to apply different aggregations to\n", " different value columns.\n", " If not specified, will be `numpy.mean`\n", "\n", " Returns:\n", " The pivoted dataframe.\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://tidyr.tidyverse.org/reference/pivot_wider.html\n", "%run nb_helpers.py\n", "\n", "from datar.data import fish_encounters, us_rent_income, warpbreaks \n", "from datar.all import *\n", "\n", "nb_header(pivot_wider)" ] }, { "cell_type": "code", "execution_count": 2, "id": "recognized-stuart", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:50.572185Z", "iopub.status.busy": "2021-07-16T22:27:50.571512Z", "iopub.status.idle": "2021-07-16T22:27:50.580526Z", "shell.execute_reply": "2021-07-16T22:27:50.580942Z" } }, "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", "
fishstationseen
<int64><object><int64>
04842Release1
14842I80_11
24842Lisbon1
34842Rstr1
............
44842Base_TD1
1094864Release1
1104864I80_11
1114865Release1
1124865I80_11
1134865Lisbon1
\n", "

114 rows × 3 columns

\n", "
\n" ], "text/plain": [ " fish station seen\n", " \n", "0 4842 Release 1\n", "1 4842 I80_1 1\n", "2 4842 Lisbon 1\n", "3 4842 Rstr 1\n", ".. ... ... ...\n", "4 4842 Base_TD 1\n", "109 4864 Release 1\n", "110 4864 I80_1 1\n", "111 4865 Release 1\n", "112 4865 I80_1 1\n", "113 4865 Lisbon 1\n", "\n", "[114 rows x 3 columns]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fish_encounters" ] }, { "cell_type": "code", "execution_count": 3, "id": "drawn-empire", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:50.699989Z", "iopub.status.busy": "2021-07-16T22:27:50.699422Z", "iopub.status.idle": "2021-07-16T22:27:50.800575Z", "shell.execute_reply": "2021-07-16T22:27:50.800954Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fishBCEBCE2BCWBCW2Base_TDI80_1LisbonMAEMAWReleaseRstr
<int64><float64><float64><float64><float64><float64><float64><float64><float64><float64><float64><float64>
048421.01.01.01.01.01.01.01.01.01.01.0
148431.01.01.01.01.01.01.01.01.01.01.0
248441.01.01.01.01.01.01.01.01.01.01.0
34845NaNNaNNaNNaN1.01.01.0NaNNaN1.01.0
44847NaNNaNNaNNaNNaN1.01.0NaNNaN1.0NaN
54848NaNNaNNaNNaNNaN1.01.0NaNNaN1.01.0
64849NaNNaNNaNNaNNaN1.0NaNNaNNaN1.0NaN
748501.0NaN1.0NaN1.01.0NaNNaNNaN1.01.0
84851NaNNaNNaNNaNNaN1.0NaNNaNNaN1.0NaN
94854NaNNaNNaNNaNNaN1.0NaNNaNNaN1.0NaN
104855NaNNaNNaNNaN1.01.01.0NaNNaN1.01.0
1148571.01.01.01.01.01.01.0NaNNaN1.01.0
1248581.01.01.01.01.01.01.01.01.01.01.0
134859NaNNaNNaNNaN1.01.01.0NaNNaN1.01.0
1448611.01.01.01.01.01.01.01.01.01.01.0
1548621.01.01.01.01.01.01.0NaNNaN1.01.0
164863NaNNaNNaNNaNNaN1.0NaNNaNNaN1.0NaN
174864NaNNaNNaNNaNNaN1.0NaNNaNNaN1.0NaN
184865NaNNaNNaNNaNNaN1.01.0NaNNaN1.0NaN
\n", "
\n" ], "text/plain": [ " fish BCE BCE2 BCW BCW2 Base_TD I80_1 \\\n", " \n", "0 4842 1.0 1.0 1.0 1.0 1.0 1.0 \n", "1 4843 1.0 1.0 1.0 1.0 1.0 1.0 \n", "2 4844 1.0 1.0 1.0 1.0 1.0 1.0 \n", "3 4845 NaN NaN NaN NaN 1.0 1.0 \n", "4 4847 NaN NaN NaN NaN NaN 1.0 \n", "5 4848 NaN NaN NaN NaN NaN 1.0 \n", "6 4849 NaN NaN NaN NaN NaN 1.0 \n", "7 4850 1.0 NaN 1.0 NaN 1.0 1.0 \n", "8 4851 NaN NaN NaN NaN NaN 1.0 \n", "9 4854 NaN NaN NaN NaN NaN 1.0 \n", "10 4855 NaN NaN NaN NaN 1.0 1.0 \n", "11 4857 1.0 1.0 1.0 1.0 1.0 1.0 \n", "12 4858 1.0 1.0 1.0 1.0 1.0 1.0 \n", "13 4859 NaN NaN NaN NaN 1.0 1.0 \n", "14 4861 1.0 1.0 1.0 1.0 1.0 1.0 \n", "15 4862 1.0 1.0 1.0 1.0 1.0 1.0 \n", "16 4863 NaN NaN NaN NaN NaN 1.0 \n", "17 4864 NaN NaN NaN NaN NaN 1.0 \n", "18 4865 NaN NaN NaN NaN NaN 1.0 \n", "\n", " Lisbon MAE MAW Release Rstr \n", " \n", "0 1.0 1.0 1.0 1.0 1.0 \n", "1 1.0 1.0 1.0 1.0 1.0 \n", "2 1.0 1.0 1.0 1.0 1.0 \n", "3 1.0 NaN NaN 1.0 1.0 \n", "4 1.0 NaN NaN 1.0 NaN \n", "5 1.0 NaN NaN 1.0 1.0 \n", "6 NaN NaN NaN 1.0 NaN \n", "7 NaN NaN NaN 1.0 1.0 \n", "8 NaN NaN NaN 1.0 NaN \n", "9 NaN NaN NaN 1.0 NaN \n", "10 1.0 NaN NaN 1.0 1.0 \n", "11 1.0 NaN NaN 1.0 1.0 \n", "12 1.0 1.0 1.0 1.0 1.0 \n", "13 1.0 NaN NaN 1.0 1.0 \n", "14 1.0 1.0 1.0 1.0 1.0 \n", "15 1.0 NaN NaN 1.0 1.0 \n", "16 NaN NaN NaN 1.0 NaN \n", "17 NaN NaN NaN 1.0 NaN \n", "18 1.0 NaN NaN 1.0 NaN " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fish_encounters >> \\\n", " pivot_wider(names_from=f.station, values_from=f.seen)" ] }, { "cell_type": "code", "execution_count": 4, "id": "prompt-geneva", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:50.848972Z", "iopub.status.busy": "2021-07-16T22:27:50.847524Z", "iopub.status.idle": "2021-07-16T22:27:50.860460Z", "shell.execute_reply": "2021-07-16T22:27:50.861007Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fishBCEBCE2BCWBCW2Base_TDI80_1LisbonMAEMAWReleaseRstr
<int64><int64><int64><int64><int64><int64><int64><int64><int64><int64><int64><int64>
0484211111111111
1484311111111111
2484411111111111
3484500001110011
4484700000110010
5484800000110011
6484900000100010
7485010101100011
8485100000100010
9485400000100010
10485500001110011
11485711111110011
12485811111111111
13485900001110011
14486111111111111
15486211111110011
16486300000100010
17486400000100010
18486500000110010
\n", "
\n" ], "text/plain": [ " fish BCE BCE2 BCW BCW2 Base_TD I80_1 Lisbon MAE \\\n", " \n", "0 4842 1 1 1 1 1 1 1 1 \n", "1 4843 1 1 1 1 1 1 1 1 \n", "2 4844 1 1 1 1 1 1 1 1 \n", "3 4845 0 0 0 0 1 1 1 0 \n", "4 4847 0 0 0 0 0 1 1 0 \n", "5 4848 0 0 0 0 0 1 1 0 \n", "6 4849 0 0 0 0 0 1 0 0 \n", "7 4850 1 0 1 0 1 1 0 0 \n", "8 4851 0 0 0 0 0 1 0 0 \n", "9 4854 0 0 0 0 0 1 0 0 \n", "10 4855 0 0 0 0 1 1 1 0 \n", "11 4857 1 1 1 1 1 1 1 0 \n", "12 4858 1 1 1 1 1 1 1 1 \n", "13 4859 0 0 0 0 1 1 1 0 \n", "14 4861 1 1 1 1 1 1 1 1 \n", "15 4862 1 1 1 1 1 1 1 0 \n", "16 4863 0 0 0 0 0 1 0 0 \n", "17 4864 0 0 0 0 0 1 0 0 \n", "18 4865 0 0 0 0 0 1 1 0 \n", "\n", " MAW Release Rstr \n", " \n", "0 1 1 1 \n", "1 1 1 1 \n", "2 1 1 1 \n", "3 0 1 1 \n", "4 0 1 0 \n", "5 0 1 1 \n", "6 0 1 0 \n", "7 0 1 1 \n", "8 0 1 0 \n", "9 0 1 0 \n", "10 0 1 1 \n", "11 0 1 1 \n", "12 1 1 1 \n", "13 0 1 1 \n", "14 1 1 1 \n", "15 0 1 1 \n", "16 0 1 0 \n", "17 0 1 0 \n", "18 0 1 0 " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fish_encounters >> \\\n", " pivot_wider(names_from=f.station, values_from=f.seen, values_fill=0)" ] }, { "cell_type": "code", "execution_count": 5, "id": "spanish-classics", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:50.884228Z", "iopub.status.busy": "2021-07-16T22:27:50.883639Z", "iopub.status.idle": "2021-07-16T22:27:50.907988Z", "shell.execute_reply": "2021-07-16T22:27:50.907167Z" } }, "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", "
GEOIDNAMEvariableestimatemoe
<int64><object><object><float64><float64>
01Alabamaincome24476.0136.0
11Alabamarent747.03.0
22Alaskaincome32940.0508.0
32Alaskarent1200.013.0
..................
44Arizonaincome27517.0148.0
9955Wisconsinrent813.03.0
10056Wyomingincome30854.0342.0
10156Wyomingrent828.011.0
10272Puerto RicoincomeNaNNaN
10372Puerto Ricorent464.06.0
\n", "

104 rows × 5 columns

\n", "
\n" ], "text/plain": [ " GEOID NAME variable estimate moe\n", " \n", "0 1 Alabama income 24476.0 136.0\n", "1 1 Alabama rent 747.0 3.0\n", "2 2 Alaska income 32940.0 508.0\n", "3 2 Alaska rent 1200.0 13.0\n", ".. ... ... ... ... ...\n", "4 4 Arizona income 27517.0 148.0\n", "99 55 Wisconsin rent 813.0 3.0\n", "100 56 Wyoming income 30854.0 342.0\n", "101 56 Wyoming rent 828.0 11.0\n", "102 72 Puerto Rico income NaN NaN\n", "103 72 Puerto Rico rent 464.0 6.0\n", "\n", "[104 rows x 5 columns]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "us_rent_income" ] }, { "cell_type": "code", "execution_count": 6, "id": "antique-winner", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:50.965105Z", "iopub.status.busy": "2021-07-16T22:27:50.964273Z", "iopub.status.idle": "2021-07-16T22:27:50.970893Z", "shell.execute_reply": "2021-07-16T22:27:50.971248Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
GEOIDNAMEestimate_incomeestimate_rentmoe_incomemoe_rent
<int64><object><float64><float64><float64><float64>
01Alabama24476.0747.0136.03.0
12Alaska32940.01200.0508.013.0
24Arizona27517.0972.0148.04.0
35Arkansas23789.0709.0165.05.0
46California29454.01358.0109.03.0
58Colorado32401.01125.0109.05.0
69Connecticut35326.01123.0195.05.0
710Delaware31560.01076.0247.010.0
811District of Columbia43198.01424.0681.017.0
912Florida25952.01077.070.03.0
1013Georgia27024.0927.0106.03.0
1115Hawaii32453.01507.0218.018.0
1216Idaho25298.0792.0208.07.0
1317Illinois30684.0952.083.03.0
1418Indiana27247.0782.0117.03.0
1519Iowa30002.0740.0143.04.0
1620Kansas29126.0801.0208.05.0
1721Kentucky24702.0713.0159.04.0
1822Louisiana25086.0825.0155.04.0
1923Maine26841.0808.0187.07.0
2024Maryland37147.01311.0152.05.0
2125Massachusetts34498.01173.0199.05.0
2226Michigan26987.0824.082.03.0
2327Minnesota32734.0906.0189.04.0
2428Mississippi22766.0740.0194.05.0
2529Missouri26999.0784.0113.04.0
2630Montana26249.0751.0206.09.0
2731Nebraska30020.0773.0146.04.0
2832Nevada29019.01017.0213.06.0
2933New Hampshire33172.01052.0387.09.0
3034New Jersey35075.01249.0148.04.0
3135New Mexico24457.0809.0214.06.0
3236New York31057.01194.069.03.0
3337North Carolina26482.0844.0111.03.0
3438North Dakota32336.0775.0245.09.0
3539Ohio27435.0764.094.02.0
3640Oklahoma26207.0766.0101.03.0
3741Oregon27389.0988.0146.04.0
3842Pennsylvania28923.0885.0119.03.0
3944Rhode Island30210.0957.0259.06.0
4045South Carolina25454.0836.0123.04.0
4146South Dakota28821.0696.0276.07.0
4247Tennessee25453.0808.0102.04.0
4348Texas28063.0952.0110.02.0
4449Utah27928.0948.0239.06.0
4550Vermont29351.0945.0361.011.0
4651Virginia32545.01166.0202.05.0
4753Washington32318.01120.0113.04.0
4854West Virginia23707.0681.0203.06.0
4955Wisconsin29868.0813.0135.03.0
5056Wyoming30854.0828.0342.011.0
5172Puerto RicoNaN464.0NaN6.0
\n", "
\n" ], "text/plain": [ " GEOID NAME estimate_income estimate_rent moe_income \\\n", " \n", "0 1 Alabama 24476.0 747.0 136.0 \n", "1 2 Alaska 32940.0 1200.0 508.0 \n", "2 4 Arizona 27517.0 972.0 148.0 \n", "3 5 Arkansas 23789.0 709.0 165.0 \n", "4 6 California 29454.0 1358.0 109.0 \n", "5 8 Colorado 32401.0 1125.0 109.0 \n", "6 9 Connecticut 35326.0 1123.0 195.0 \n", "7 10 Delaware 31560.0 1076.0 247.0 \n", "8 11 District of Columbia 43198.0 1424.0 681.0 \n", "9 12 Florida 25952.0 1077.0 70.0 \n", "10 13 Georgia 27024.0 927.0 106.0 \n", "11 15 Hawaii 32453.0 1507.0 218.0 \n", "12 16 Idaho 25298.0 792.0 208.0 \n", "13 17 Illinois 30684.0 952.0 83.0 \n", "14 18 Indiana 27247.0 782.0 117.0 \n", "15 19 Iowa 30002.0 740.0 143.0 \n", "16 20 Kansas 29126.0 801.0 208.0 \n", "17 21 Kentucky 24702.0 713.0 159.0 \n", "18 22 Louisiana 25086.0 825.0 155.0 \n", "19 23 Maine 26841.0 808.0 187.0 \n", "20 24 Maryland 37147.0 1311.0 152.0 \n", "21 25 Massachusetts 34498.0 1173.0 199.0 \n", "22 26 Michigan 26987.0 824.0 82.0 \n", "23 27 Minnesota 32734.0 906.0 189.0 \n", "24 28 Mississippi 22766.0 740.0 194.0 \n", "25 29 Missouri 26999.0 784.0 113.0 \n", "26 30 Montana 26249.0 751.0 206.0 \n", "27 31 Nebraska 30020.0 773.0 146.0 \n", "28 32 Nevada 29019.0 1017.0 213.0 \n", "29 33 New Hampshire 33172.0 1052.0 387.0 \n", "30 34 New Jersey 35075.0 1249.0 148.0 \n", "31 35 New Mexico 24457.0 809.0 214.0 \n", "32 36 New York 31057.0 1194.0 69.0 \n", "33 37 North Carolina 26482.0 844.0 111.0 \n", "34 38 North Dakota 32336.0 775.0 245.0 \n", "35 39 Ohio 27435.0 764.0 94.0 \n", "36 40 Oklahoma 26207.0 766.0 101.0 \n", "37 41 Oregon 27389.0 988.0 146.0 \n", "38 42 Pennsylvania 28923.0 885.0 119.0 \n", "39 44 Rhode Island 30210.0 957.0 259.0 \n", "40 45 South Carolina 25454.0 836.0 123.0 \n", "41 46 South Dakota 28821.0 696.0 276.0 \n", "42 47 Tennessee 25453.0 808.0 102.0 \n", "43 48 Texas 28063.0 952.0 110.0 \n", "44 49 Utah 27928.0 948.0 239.0 \n", "45 50 Vermont 29351.0 945.0 361.0 \n", "46 51 Virginia 32545.0 1166.0 202.0 \n", "47 53 Washington 32318.0 1120.0 113.0 \n", "48 54 West Virginia 23707.0 681.0 203.0 \n", "49 55 Wisconsin 29868.0 813.0 135.0 \n", "50 56 Wyoming 30854.0 828.0 342.0 \n", "51 72 Puerto Rico NaN 464.0 NaN \n", "\n", " moe_rent \n", " \n", "0 3.0 \n", "1 13.0 \n", "2 4.0 \n", "3 5.0 \n", "4 3.0 \n", "5 5.0 \n", "6 5.0 \n", "7 10.0 \n", "8 17.0 \n", "9 3.0 \n", "10 3.0 \n", "11 18.0 \n", "12 7.0 \n", "13 3.0 \n", "14 3.0 \n", "15 4.0 \n", "16 5.0 \n", "17 4.0 \n", "18 4.0 \n", "19 7.0 \n", "20 5.0 \n", "21 5.0 \n", "22 3.0 \n", "23 4.0 \n", "24 5.0 \n", "25 4.0 \n", "26 9.0 \n", "27 4.0 \n", "28 6.0 \n", "29 9.0 \n", "30 4.0 \n", "31 6.0 \n", "32 3.0 \n", "33 3.0 \n", "34 9.0 \n", "35 2.0 \n", "36 3.0 \n", "37 4.0 \n", "38 3.0 \n", "39 6.0 \n", "40 4.0 \n", "41 7.0 \n", "42 4.0 \n", "43 2.0 \n", "44 6.0 \n", "45 11.0 \n", "46 5.0 \n", "47 4.0 \n", "48 6.0 \n", "49 3.0 \n", "50 11.0 \n", "51 6.0 " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "us_rent_income >> \\\n", " pivot_wider(names_from=f.variable, values_from=c(f.estimate, f.moe))" ] }, { "cell_type": "code", "execution_count": 7, "id": "offensive-listening", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:51.019461Z", "iopub.status.busy": "2021-07-16T22:27:51.018923Z", "iopub.status.idle": "2021-07-16T22:27:51.026318Z", "shell.execute_reply": "2021-07-16T22:27:51.026706Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
GEOIDNAMEestimate.incomeestimate.rentmoe.incomemoe.rent
<int64><object><float64><float64><float64><float64>
01Alabama24476.0747.0136.03.0
12Alaska32940.01200.0508.013.0
24Arizona27517.0972.0148.04.0
35Arkansas23789.0709.0165.05.0
46California29454.01358.0109.03.0
58Colorado32401.01125.0109.05.0
69Connecticut35326.01123.0195.05.0
710Delaware31560.01076.0247.010.0
811District of Columbia43198.01424.0681.017.0
912Florida25952.01077.070.03.0
1013Georgia27024.0927.0106.03.0
1115Hawaii32453.01507.0218.018.0
1216Idaho25298.0792.0208.07.0
1317Illinois30684.0952.083.03.0
1418Indiana27247.0782.0117.03.0
1519Iowa30002.0740.0143.04.0
1620Kansas29126.0801.0208.05.0
1721Kentucky24702.0713.0159.04.0
1822Louisiana25086.0825.0155.04.0
1923Maine26841.0808.0187.07.0
2024Maryland37147.01311.0152.05.0
2125Massachusetts34498.01173.0199.05.0
2226Michigan26987.0824.082.03.0
2327Minnesota32734.0906.0189.04.0
2428Mississippi22766.0740.0194.05.0
2529Missouri26999.0784.0113.04.0
2630Montana26249.0751.0206.09.0
2731Nebraska30020.0773.0146.04.0
2832Nevada29019.01017.0213.06.0
2933New Hampshire33172.01052.0387.09.0
3034New Jersey35075.01249.0148.04.0
3135New Mexico24457.0809.0214.06.0
3236New York31057.01194.069.03.0
3337North Carolina26482.0844.0111.03.0
3438North Dakota32336.0775.0245.09.0
3539Ohio27435.0764.094.02.0
3640Oklahoma26207.0766.0101.03.0
3741Oregon27389.0988.0146.04.0
3842Pennsylvania28923.0885.0119.03.0
3944Rhode Island30210.0957.0259.06.0
4045South Carolina25454.0836.0123.04.0
4146South Dakota28821.0696.0276.07.0
4247Tennessee25453.0808.0102.04.0
4348Texas28063.0952.0110.02.0
4449Utah27928.0948.0239.06.0
4550Vermont29351.0945.0361.011.0
4651Virginia32545.01166.0202.05.0
4753Washington32318.01120.0113.04.0
4854West Virginia23707.0681.0203.06.0
4955Wisconsin29868.0813.0135.03.0
5056Wyoming30854.0828.0342.011.0
5172Puerto RicoNaN464.0NaN6.0
\n", "
\n" ], "text/plain": [ " GEOID NAME estimate.income estimate.rent moe.income \\\n", " \n", "0 1 Alabama 24476.0 747.0 136.0 \n", "1 2 Alaska 32940.0 1200.0 508.0 \n", "2 4 Arizona 27517.0 972.0 148.0 \n", "3 5 Arkansas 23789.0 709.0 165.0 \n", "4 6 California 29454.0 1358.0 109.0 \n", "5 8 Colorado 32401.0 1125.0 109.0 \n", "6 9 Connecticut 35326.0 1123.0 195.0 \n", "7 10 Delaware 31560.0 1076.0 247.0 \n", "8 11 District of Columbia 43198.0 1424.0 681.0 \n", "9 12 Florida 25952.0 1077.0 70.0 \n", "10 13 Georgia 27024.0 927.0 106.0 \n", "11 15 Hawaii 32453.0 1507.0 218.0 \n", "12 16 Idaho 25298.0 792.0 208.0 \n", "13 17 Illinois 30684.0 952.0 83.0 \n", "14 18 Indiana 27247.0 782.0 117.0 \n", "15 19 Iowa 30002.0 740.0 143.0 \n", "16 20 Kansas 29126.0 801.0 208.0 \n", "17 21 Kentucky 24702.0 713.0 159.0 \n", "18 22 Louisiana 25086.0 825.0 155.0 \n", "19 23 Maine 26841.0 808.0 187.0 \n", "20 24 Maryland 37147.0 1311.0 152.0 \n", "21 25 Massachusetts 34498.0 1173.0 199.0 \n", "22 26 Michigan 26987.0 824.0 82.0 \n", "23 27 Minnesota 32734.0 906.0 189.0 \n", "24 28 Mississippi 22766.0 740.0 194.0 \n", "25 29 Missouri 26999.0 784.0 113.0 \n", "26 30 Montana 26249.0 751.0 206.0 \n", "27 31 Nebraska 30020.0 773.0 146.0 \n", "28 32 Nevada 29019.0 1017.0 213.0 \n", "29 33 New Hampshire 33172.0 1052.0 387.0 \n", "30 34 New Jersey 35075.0 1249.0 148.0 \n", "31 35 New Mexico 24457.0 809.0 214.0 \n", "32 36 New York 31057.0 1194.0 69.0 \n", "33 37 North Carolina 26482.0 844.0 111.0 \n", "34 38 North Dakota 32336.0 775.0 245.0 \n", "35 39 Ohio 27435.0 764.0 94.0 \n", "36 40 Oklahoma 26207.0 766.0 101.0 \n", "37 41 Oregon 27389.0 988.0 146.0 \n", "38 42 Pennsylvania 28923.0 885.0 119.0 \n", "39 44 Rhode Island 30210.0 957.0 259.0 \n", "40 45 South Carolina 25454.0 836.0 123.0 \n", "41 46 South Dakota 28821.0 696.0 276.0 \n", "42 47 Tennessee 25453.0 808.0 102.0 \n", "43 48 Texas 28063.0 952.0 110.0 \n", "44 49 Utah 27928.0 948.0 239.0 \n", "45 50 Vermont 29351.0 945.0 361.0 \n", "46 51 Virginia 32545.0 1166.0 202.0 \n", "47 53 Washington 32318.0 1120.0 113.0 \n", "48 54 West Virginia 23707.0 681.0 203.0 \n", "49 55 Wisconsin 29868.0 813.0 135.0 \n", "50 56 Wyoming 30854.0 828.0 342.0 \n", "51 72 Puerto Rico NaN 464.0 NaN \n", "\n", " moe.rent \n", " \n", "0 3.0 \n", "1 13.0 \n", "2 4.0 \n", "3 5.0 \n", "4 3.0 \n", "5 5.0 \n", "6 5.0 \n", "7 10.0 \n", "8 17.0 \n", "9 3.0 \n", "10 3.0 \n", "11 18.0 \n", "12 7.0 \n", "13 3.0 \n", "14 3.0 \n", "15 4.0 \n", "16 5.0 \n", "17 4.0 \n", "18 4.0 \n", "19 7.0 \n", "20 5.0 \n", "21 5.0 \n", "22 3.0 \n", "23 4.0 \n", "24 5.0 \n", "25 4.0 \n", "26 9.0 \n", "27 4.0 \n", "28 6.0 \n", "29 9.0 \n", "30 4.0 \n", "31 6.0 \n", "32 3.0 \n", "33 3.0 \n", "34 9.0 \n", "35 2.0 \n", "36 3.0 \n", "37 4.0 \n", "38 3.0 \n", "39 6.0 \n", "40 4.0 \n", "41 7.0 \n", "42 4.0 \n", "43 2.0 \n", "44 6.0 \n", "45 11.0 \n", "46 5.0 \n", "47 4.0 \n", "48 6.0 \n", "49 3.0 \n", "50 11.0 \n", "51 6.0 " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "us_rent_income >> \\\n", " pivot_wider(\n", " names_from=f.variable,\n", " names_sep=\".\",\n", " values_from=c(f.estimate, f.moe)\n", " )" ] }, { "cell_type": "code", "execution_count": 8, "id": "active-private", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:51.088298Z", "iopub.status.busy": "2021-07-16T22:27:51.087226Z", "iopub.status.idle": "2021-07-16T22:27:51.107507Z", "shell.execute_reply": "2021-07-16T22:27:51.107976Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
GEOIDNAMEincome_estimaterent_estimateincome_moerent_moe
<int64><object><float64><float64><float64><float64>
01Alabama24476.0747.0136.03.0
12Alaska32940.01200.0508.013.0
24Arizona27517.0972.0148.04.0
35Arkansas23789.0709.0165.05.0
46California29454.01358.0109.03.0
58Colorado32401.01125.0109.05.0
69Connecticut35326.01123.0195.05.0
710Delaware31560.01076.0247.010.0
811District of Columbia43198.01424.0681.017.0
912Florida25952.01077.070.03.0
1013Georgia27024.0927.0106.03.0
1115Hawaii32453.01507.0218.018.0
1216Idaho25298.0792.0208.07.0
1317Illinois30684.0952.083.03.0
1418Indiana27247.0782.0117.03.0
1519Iowa30002.0740.0143.04.0
1620Kansas29126.0801.0208.05.0
1721Kentucky24702.0713.0159.04.0
1822Louisiana25086.0825.0155.04.0
1923Maine26841.0808.0187.07.0
2024Maryland37147.01311.0152.05.0
2125Massachusetts34498.01173.0199.05.0
2226Michigan26987.0824.082.03.0
2327Minnesota32734.0906.0189.04.0
2428Mississippi22766.0740.0194.05.0
2529Missouri26999.0784.0113.04.0
2630Montana26249.0751.0206.09.0
2731Nebraska30020.0773.0146.04.0
2832Nevada29019.01017.0213.06.0
2933New Hampshire33172.01052.0387.09.0
3034New Jersey35075.01249.0148.04.0
3135New Mexico24457.0809.0214.06.0
3236New York31057.01194.069.03.0
3337North Carolina26482.0844.0111.03.0
3438North Dakota32336.0775.0245.09.0
3539Ohio27435.0764.094.02.0
3640Oklahoma26207.0766.0101.03.0
3741Oregon27389.0988.0146.04.0
3842Pennsylvania28923.0885.0119.03.0
3944Rhode Island30210.0957.0259.06.0
4045South Carolina25454.0836.0123.04.0
4146South Dakota28821.0696.0276.07.0
4247Tennessee25453.0808.0102.04.0
4348Texas28063.0952.0110.02.0
4449Utah27928.0948.0239.06.0
4550Vermont29351.0945.0361.011.0
4651Virginia32545.01166.0202.05.0
4753Washington32318.01120.0113.04.0
4854West Virginia23707.0681.0203.06.0
4955Wisconsin29868.0813.0135.03.0
5056Wyoming30854.0828.0342.011.0
5172Puerto RicoNaN464.0NaN6.0
\n", "
\n" ], "text/plain": [ " GEOID NAME income_estimate rent_estimate income_moe \\\n", " \n", "0 1 Alabama 24476.0 747.0 136.0 \n", "1 2 Alaska 32940.0 1200.0 508.0 \n", "2 4 Arizona 27517.0 972.0 148.0 \n", "3 5 Arkansas 23789.0 709.0 165.0 \n", "4 6 California 29454.0 1358.0 109.0 \n", "5 8 Colorado 32401.0 1125.0 109.0 \n", "6 9 Connecticut 35326.0 1123.0 195.0 \n", "7 10 Delaware 31560.0 1076.0 247.0 \n", "8 11 District of Columbia 43198.0 1424.0 681.0 \n", "9 12 Florida 25952.0 1077.0 70.0 \n", "10 13 Georgia 27024.0 927.0 106.0 \n", "11 15 Hawaii 32453.0 1507.0 218.0 \n", "12 16 Idaho 25298.0 792.0 208.0 \n", "13 17 Illinois 30684.0 952.0 83.0 \n", "14 18 Indiana 27247.0 782.0 117.0 \n", "15 19 Iowa 30002.0 740.0 143.0 \n", "16 20 Kansas 29126.0 801.0 208.0 \n", "17 21 Kentucky 24702.0 713.0 159.0 \n", "18 22 Louisiana 25086.0 825.0 155.0 \n", "19 23 Maine 26841.0 808.0 187.0 \n", "20 24 Maryland 37147.0 1311.0 152.0 \n", "21 25 Massachusetts 34498.0 1173.0 199.0 \n", "22 26 Michigan 26987.0 824.0 82.0 \n", "23 27 Minnesota 32734.0 906.0 189.0 \n", "24 28 Mississippi 22766.0 740.0 194.0 \n", "25 29 Missouri 26999.0 784.0 113.0 \n", "26 30 Montana 26249.0 751.0 206.0 \n", "27 31 Nebraska 30020.0 773.0 146.0 \n", "28 32 Nevada 29019.0 1017.0 213.0 \n", "29 33 New Hampshire 33172.0 1052.0 387.0 \n", "30 34 New Jersey 35075.0 1249.0 148.0 \n", "31 35 New Mexico 24457.0 809.0 214.0 \n", "32 36 New York 31057.0 1194.0 69.0 \n", "33 37 North Carolina 26482.0 844.0 111.0 \n", "34 38 North Dakota 32336.0 775.0 245.0 \n", "35 39 Ohio 27435.0 764.0 94.0 \n", "36 40 Oklahoma 26207.0 766.0 101.0 \n", "37 41 Oregon 27389.0 988.0 146.0 \n", "38 42 Pennsylvania 28923.0 885.0 119.0 \n", "39 44 Rhode Island 30210.0 957.0 259.0 \n", "40 45 South Carolina 25454.0 836.0 123.0 \n", "41 46 South Dakota 28821.0 696.0 276.0 \n", "42 47 Tennessee 25453.0 808.0 102.0 \n", "43 48 Texas 28063.0 952.0 110.0 \n", "44 49 Utah 27928.0 948.0 239.0 \n", "45 50 Vermont 29351.0 945.0 361.0 \n", "46 51 Virginia 32545.0 1166.0 202.0 \n", "47 53 Washington 32318.0 1120.0 113.0 \n", "48 54 West Virginia 23707.0 681.0 203.0 \n", "49 55 Wisconsin 29868.0 813.0 135.0 \n", "50 56 Wyoming 30854.0 828.0 342.0 \n", "51 72 Puerto Rico NaN 464.0 NaN \n", "\n", " rent_moe \n", " \n", "0 3.0 \n", "1 13.0 \n", "2 4.0 \n", "3 5.0 \n", "4 3.0 \n", "5 5.0 \n", "6 5.0 \n", "7 10.0 \n", "8 17.0 \n", "9 3.0 \n", "10 3.0 \n", "11 18.0 \n", "12 7.0 \n", "13 3.0 \n", "14 3.0 \n", "15 4.0 \n", "16 5.0 \n", "17 4.0 \n", "18 4.0 \n", "19 7.0 \n", "20 5.0 \n", "21 5.0 \n", "22 3.0 \n", "23 4.0 \n", "24 5.0 \n", "25 4.0 \n", "26 9.0 \n", "27 4.0 \n", "28 6.0 \n", "29 9.0 \n", "30 4.0 \n", "31 6.0 \n", "32 3.0 \n", "33 3.0 \n", "34 9.0 \n", "35 2.0 \n", "36 3.0 \n", "37 4.0 \n", "38 3.0 \n", "39 6.0 \n", "40 4.0 \n", "41 7.0 \n", "42 4.0 \n", "43 2.0 \n", "44 6.0 \n", "45 11.0 \n", "46 5.0 \n", "47 4.0 \n", "48 6.0 \n", "49 3.0 \n", "50 11.0 \n", "51 6.0 " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "us_rent_income >> \\\n", " pivot_wider(\n", " names_from=f.variable,\n", " names_glue=\"{variable}_{_value}\",\n", " values_from=c(f.estimate, f.moe)\n", " )" ] }, { "cell_type": "code", "execution_count": 9, "id": "abstract-gnome", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:51.137187Z", "iopub.status.busy": "2021-07-16T22:27:51.136396Z", "iopub.status.idle": "2021-07-16T22:27:51.151097Z", "shell.execute_reply": "2021-07-16T22:27:51.151750Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
breakswooltension
<int64><object><object>
026AL
130AL
254AL
325AL
470AL
552AL
651AL
726AL
867AL
918AM
1021AM
1129AM
1217AM
1312AM
1418AM
1535AM
1630AM
1736AM
1836AH
1921AH
2024AH
2118AH
2210AH
2343AH
2428AH
2515AH
2626AH
2727BL
2814BL
2929BL
3019BL
3129BL
3231BL
3341BL
3420BL
3544BL
3642BM
3726BM
3819BM
3916BM
4039BM
4128BM
4221BM
4339BM
4429BM
4520BH
4621BH
4724BH
4817BH
4913BH
5015BH
5115BH
5216BH
5328BH
\n", "
\n" ], "text/plain": [ " breaks wool tension\n", " \n", "0 26 A L\n", "1 30 A L\n", "2 54 A L\n", "3 25 A L\n", "4 70 A L\n", "5 52 A L\n", "6 51 A L\n", "7 26 A L\n", "8 67 A L\n", "9 18 A M\n", "10 21 A M\n", "11 29 A M\n", "12 17 A M\n", "13 12 A M\n", "14 18 A M\n", "15 35 A M\n", "16 30 A M\n", "17 36 A M\n", "18 36 A H\n", "19 21 A H\n", "20 24 A H\n", "21 18 A H\n", "22 10 A H\n", "23 43 A H\n", "24 28 A H\n", "25 15 A H\n", "26 26 A H\n", "27 27 B L\n", "28 14 B L\n", "29 29 B L\n", "30 19 B L\n", "31 29 B L\n", "32 31 B L\n", "33 41 B L\n", "34 20 B L\n", "35 44 B L\n", "36 42 B M\n", "37 26 B M\n", "38 19 B M\n", "39 16 B M\n", "40 39 B M\n", "41 28 B M\n", "42 21 B M\n", "43 39 B M\n", "44 29 B M\n", "45 20 B H\n", "46 21 B H\n", "47 24 B H\n", "48 17 B H\n", "49 13 B H\n", "50 15 B H\n", "51 15 B H\n", "52 16 B H\n", "53 28 B H" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "warpbreaks" ] }, { "cell_type": "code", "execution_count": 10, "id": "strong-brunswick", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:51.182339Z", "iopub.status.busy": "2021-07-16T22:27:51.167220Z", "iopub.status.idle": "2021-07-16T22:27:51.188224Z", "shell.execute_reply": "2021-07-16T22:27:51.188967Z" } }, "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", "
tensionAB
<object><float64><float64>
0H24.55555618.777778
1L44.55555628.222222
2M24.00000028.777778
\n", "
\n" ], "text/plain": [ " tension A B\n", " \n", "0 H 24.555556 18.777778\n", "1 L 44.555556 28.222222\n", "2 M 24.000000 28.777778" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "warpbreaks >> \\\n", " pivot_wider(\n", " names_from=f.wool,\n", " values_from=f.breaks,\n", " values_fn = mean\n", " )" ] }, { "cell_type": "code", "execution_count": null, "id": "96c53ea4", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/pull.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "radio-madonna", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:37.483231Z", "iopub.status.busy": "2021-07-16T22:27:37.482643Z", "iopub.status.idle": "2021-07-16T22:27:38.290463Z", "shell.execute_reply": "2021-07-16T22:27:38.290843Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ pull
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Pull a series or a dataframe from a dataframe\n", "\n", "##### Args:\n", "  `_data`: The dataframe \n", "  `var`: The column to pull, either the name or the index \n", "  `name`: The name of the pulled value \n", "    - If `to` is frame, or the value pulled is data frame, it will be\n", "      the column names \n", "\n", "    - If `to` is series, it will be the series name. If multiple names\n", "      are given, only the first name will be used. \n", "\n", "    - If `to` is series, but value pulled is a data frame, then a\n", "      dictionary of series with the series names as keys or given `name` \n", "      as keys. \n", "\n", "  `to`: Type of data to return. \n", "    Only works when pulling `a` for name `a$b` \n", "\n", "    - series: Return a pandas Series object\n", "      Group information will be lost \n", "      If pulled value is a dataframe, it will return a dict of series, \n", "      with the series names or the `name` provided. \n", "\n", "    - array: Return a numpy.ndarray object\n", "\n", "    - frame: Return a DataFrame with that column\n", "\n", "    - list: Return a python list\n", "\n", "    - dict: Return a dict with `name` as keys and pulled value as values\n", "      Only a single column is allowed to pull \n", "\n", "    - If not provided: `series` when pulled data has only one columns.\n", "      `dict` if `name` provided and has the same length as the pulled \n", "      single column. Otherwise `frame`. \n", "\n", "##### Returns:\n", "  The data according to `to` \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/pull.html\n", "%run nb_helpers.py\n", "\n", "from datar.data import starwars, mtcars\n", "from datar.all import *\n", "\n", "nb_header(pull)" ] }, { "cell_type": "code", "execution_count": 2, "id": "brilliant-developer", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:38.298237Z", "iopub.status.busy": "2021-07-16T22:27:38.297348Z", "iopub.status.idle": "2021-07-16T22:27:38.304964Z", "shell.execute_reply": "2021-07-16T22:27:38.303969Z" } }, "outputs": [ { "data": { "text/plain": [ "Mazda RX4 4\n", "Mazda RX4 Wag 4\n", "Datsun 710 1\n", "Hornet 4 Drive 1\n", "Hornet Sportabout 2\n", "Valiant 1\n", "Duster 360 4\n", "Merc 240D 2\n", "Merc 230 2\n", "Merc 280 4\n", "Merc 280C 4\n", "Merc 450SE 3\n", "Merc 450SL 3\n", "Merc 450SLC 3\n", "Cadillac Fleetwood 4\n", "Lincoln Continental 4\n", "Chrysler Imperial 4\n", "Fiat 128 1\n", "Honda Civic 2\n", "Toyota Corolla 1\n", "Toyota Corona 1\n", "Dodge Challenger 2\n", "AMC Javelin 2\n", "Camaro Z28 4\n", "Pontiac Firebird 2\n", "Fiat X1-9 1\n", "Porsche 914-2 2\n", "Lotus Europa 2\n", "Ford Pantera L 4\n", "Ferrari Dino 6\n", "Maserati Bora 8\n", "Volvo 142E 2\n", "Name: carb, dtype: int64" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> pull(-1)" ] }, { "cell_type": "code", "execution_count": 3, "id": "national-association", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:38.311180Z", "iopub.status.busy": "2021-07-16T22:27:38.310492Z", "iopub.status.idle": "2021-07-16T22:27:38.314920Z", "shell.execute_reply": "2021-07-16T22:27:38.315327Z" } }, "outputs": [ { "data": { "text/plain": [ "[4,\n", " 4,\n", " 1,\n", " 1,\n", " 2,\n", " 1,\n", " 4,\n", " 2,\n", " 2,\n", " 4,\n", " 4,\n", " 3,\n", " 3,\n", " 3,\n", " 4,\n", " 4,\n", " 4,\n", " 1,\n", " 2,\n", " 1,\n", " 1,\n", " 2,\n", " 2,\n", " 4,\n", " 2,\n", " 1,\n", " 2,\n", " 2,\n", " 4,\n", " 6,\n", " 8,\n", " 2]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> pull(-1, to='list')" ] }, { "cell_type": "code", "execution_count": 4, "id": "known-premium", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:38.323917Z", "iopub.status.busy": "2021-07-16T22:27:38.323107Z", "iopub.status.idle": "2021-07-16T22:27:38.326904Z", "shell.execute_reply": "2021-07-16T22:27:38.327254Z" } }, "outputs": [ { "data": { "text/plain": [ "Mazda RX4 6\n", "Mazda RX4 Wag 6\n", "Datsun 710 4\n", "Hornet 4 Drive 6\n", "Hornet Sportabout 8\n", "Valiant 6\n", "Duster 360 8\n", "Merc 240D 4\n", "Merc 230 4\n", "Merc 280 6\n", "Merc 280C 6\n", "Merc 450SE 8\n", "Merc 450SL 8\n", "Merc 450SLC 8\n", "Cadillac Fleetwood 8\n", "Lincoln Continental 8\n", "Chrysler Imperial 8\n", "Fiat 128 4\n", "Honda Civic 4\n", "Toyota Corolla 4\n", "Toyota Corona 4\n", "Dodge Challenger 8\n", "AMC Javelin 8\n", "Camaro Z28 8\n", "Pontiac Firebird 8\n", "Fiat X1-9 4\n", "Porsche 914-2 4\n", "Lotus Europa 4\n", "Ford Pantera L 8\n", "Ferrari Dino 6\n", "Maserati Bora 8\n", "Volvo 142E 4\n", "Name: cyl, dtype: int64" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> pull(1)" ] }, { "cell_type": "code", "execution_count": 5, "id": "suspended-cooler", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:38.347039Z", "iopub.status.busy": "2021-07-16T22:27:38.345756Z", "iopub.status.idle": "2021-07-16T22:27:38.358557Z", "shell.execute_reply": "2021-07-16T22:27:38.357248Z" } }, "outputs": [ { "data": { "text/plain": [ "Mazda RX4 6\n", "Mazda RX4 Wag 6\n", "Datsun 710 4\n", "Hornet 4 Drive 6\n", "Hornet Sportabout 8\n", "Valiant 6\n", "Duster 360 8\n", "Merc 240D 4\n", "Merc 230 4\n", "Merc 280 6\n", "Merc 280C 6\n", "Merc 450SE 8\n", "Merc 450SL 8\n", "Merc 450SLC 8\n", "Cadillac Fleetwood 8\n", "Lincoln Continental 8\n", "Chrysler Imperial 8\n", "Fiat 128 4\n", "Honda Civic 4\n", "Toyota Corolla 4\n", "Toyota Corona 4\n", "Dodge Challenger 8\n", "AMC Javelin 8\n", "Camaro Z28 8\n", "Pontiac Firebird 8\n", "Fiat X1-9 4\n", "Porsche 914-2 4\n", "Lotus Europa 4\n", "Ford Pantera L 8\n", "Ferrari Dino 6\n", "Maserati Bora 8\n", "Volvo 142E 4\n", "Name: cyl, dtype: int64" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> pull(f.cyl)" ] }, { "cell_type": "code", "execution_count": 6, "id": "iraqi-shaft", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:38.372685Z", "iopub.status.busy": "2021-07-16T22:27:38.371837Z", "iopub.status.idle": "2021-07-16T22:27:38.546249Z", "shell.execute_reply": "2021-07-16T22:27:38.545748Z" } }, "outputs": [ { "data": { "text/plain": [ "0 10\n", "1 18\n", "2 24\n", "3 28\n", "4 30\n", "5 30\n", "6 28\n", "7 24\n", "8 18\n", "9 10\n", "Name: z, dtype: int64" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x=range(1, 11), y=range(10, 0, -1))\n", "df >> mutate(z=f.x*f.y) >> pull()" ] }, { "cell_type": "code", "execution_count": 8, "id": "danish-assignment", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:38.556438Z", "iopub.status.busy": "2021-07-16T22:27:38.555726Z", "iopub.status.idle": "2021-07-16T22:27:38.559884Z", "shell.execute_reply": "2021-07-16T22:27:38.559114Z" } }, "outputs": [ { "data": { "text/plain": [ "{'Luke Skywalker': 172.0,\n", " 'C-3PO': 167.0,\n", " 'R2-D2': 96.0,\n", " 'Darth Vader': 202.0,\n", " 'Leia Organa': 150.0,\n", " 'Owen Lars': 178.0,\n", " 'Beru Whitesun lars': 165.0,\n", " 'R5-D4': 97.0,\n", " 'Biggs Darklighter': 183.0,\n", " 'Obi-Wan Kenobi': 182.0,\n", " 'Anakin Skywalker': 188.0,\n", " 'Wilhuff Tarkin': 180.0,\n", " 'Chewbacca': 228.0,\n", " 'Han Solo': 180.0,\n", " 'Greedo': 173.0,\n", " 'Jabba Desilijic Tiure': 175.0,\n", " 'Wedge Antilles': 170.0,\n", " 'Jek Tono Porkins': 180.0,\n", " 'Yoda': 66.0,\n", " 'Palpatine': 170.0,\n", " 'Boba Fett': 183.0,\n", " 'IG-88': 200.0,\n", " 'Bossk': 190.0,\n", " 'Lando Calrissian': 177.0,\n", " 'Lobot': 175.0,\n", " 'Ackbar': 180.0,\n", " 'Mon Mothma': 150.0,\n", " 'Arvel Crynyd': nan,\n", " 'Wicket Systri Warrick': 88.0,\n", " 'Nien Nunb': 160.0,\n", " 'Qui-Gon Jinn': 193.0,\n", " 'Nute Gunray': 191.0,\n", " 'Finis Valorum': 170.0,\n", " 'Jar Jar Binks': 196.0,\n", " 'Roos Tarpals': 224.0,\n", " 'Rugor Nass': 206.0,\n", " 'Ric Olié': 183.0,\n", " 'Watto': 137.0,\n", " 'Sebulba': 112.0,\n", " 'Quarsh Panaka': 183.0,\n", " 'Shmi Skywalker': 163.0,\n", " 'Darth Maul': 175.0,\n", " 'Bib Fortuna': 180.0,\n", " 'Ayla Secura': 178.0,\n", " 'Dud Bolt': 94.0,\n", " 'Gasgano': 122.0,\n", " 'Ben Quadinaros': 163.0,\n", " 'Mace Windu': 188.0,\n", " 'Ki-Adi-Mundi': 198.0,\n", " 'Kit Fisto': 196.0,\n", " 'Eeth Koth': 171.0,\n", " 'Adi Gallia': 184.0,\n", " 'Saesee Tiin': 188.0,\n", " 'Yarael Poof': 264.0,\n", " 'Plo Koon': 188.0,\n", " 'Mas Amedda': 196.0,\n", " 'Gregar Typho': 185.0,\n", " 'Cordé': 157.0,\n", " 'Cliegg Lars': 183.0,\n", " 'Poggle the Lesser': 183.0,\n", " 'Luminara Unduli': 170.0,\n", " 'Barriss Offee': 166.0,\n", " 'Dormé': 165.0,\n", " 'Dooku': 193.0,\n", " 'Bail Prestor Organa': 191.0,\n", " 'Jango Fett': 183.0,\n", " 'Zam Wesell': 168.0,\n", " 'Dexter Jettster': 198.0,\n", " 'Lama Su': 229.0,\n", " 'Taun We': 213.0,\n", " 'Jocasta Nu': 167.0,\n", " 'Ratts Tyerell': 79.0,\n", " 'R4-P17': 96.0,\n", " 'Wat Tambor': 193.0,\n", " 'San Hill': 191.0,\n", " 'Shaak Ti': 178.0,\n", " 'Grievous': 216.0,\n", " 'Tarfful': 234.0,\n", " 'Raymus Antilles': 188.0,\n", " 'Sly Moore': 178.0,\n", " 'Tion Medon': 206.0,\n", " 'Finn': nan,\n", " 'Rey': nan,\n", " 'Poe Dameron': nan,\n", " 'BB8': nan,\n", " 'Captain Phasma': nan,\n", " 'Padmé Amidala': 165.0}" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> pull(f.height, name=f.name)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/ranking.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "interstate-header", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:54.309088Z", "iopub.status.busy": "2021-07-16T22:27:54.308312Z", "iopub.status.idle": "2021-07-16T22:27:56.595695Z", "shell.execute_reply": "2021-07-16T22:27:56.595020Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ row_number
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Get the row number of x\n", "\n", "Note that this function doesn't support piping. \n", "\n", "##### Args:\n", "  `x`: The data to get row number \n", "    Defaults to `Symbolic()` so the whole data is used by default \n", "    when called `row_number()` \n", "\n", "##### Returns:\n", "  The row number \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ min_rank
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Get the min rank of x\n", "\n", "Note that this function doesn't support piping. \n", "\n", "##### Args:\n", "  `x`: The data to get row number \n", "    Defaults to `Symbolic()` so the whole data is used by default \n", "    when called `min_rank()` \n", "\n", "  `na_last`: How NA values are ranked \n", "    - \"keep\": NA values are ranked at the end\n", "\n", "    - \"top\": NA values are ranked at the top\n", "\n", "    - \"bottom\": NA values are ranked at the bottom\n", "\n", "##### Returns:\n", "  The row number \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ dense_rank
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Get the dense rank of x\n", "\n", "Note that this function doesn't support piping. \n", "\n", "##### Args:\n", "  `x`: The data to get row number \n", "    Defaults to `Symbolic()` so the whole data is used by default \n", "    when called `dense_rank()` \n", "\n", "  `na_last`: How NA values are ranked \n", "    - \"keep\": NA values are ranked at the end\n", "\n", "    - \"top\": NA values are ranked at the top\n", "\n", "    - \"bottom\": NA values are ranked at the bottom\n", "\n", "##### Returns:\n", "  The row number \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ percent_rank
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Get the percent rank of x\n", "\n", "Note that this function doesn't support piping. \n", "\n", "##### Args:\n", "  `x`: The data to get row number \n", "    Defaults to `Symbolic()` so the whole data is used by default \n", "    when called `percent_rank()` \n", "\n", "  `na_last`: How NA values are ranked \n", "    - \"keep\": NA values are ranked at the end\n", "\n", "    - \"top\": NA values are ranked at the top\n", "\n", "    - \"bottom\": NA values are ranked at the bottom\n", "\n", "##### Returns:\n", "  The row number \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ cume_dist
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Get the cume_dist of x\n", "\n", "Note that this function doesn't support piping. \n", "\n", "##### Args:\n", "  `x`: The data to get row number \n", "    Defaults to `Symbolic()` so the whole data is used by default \n", "    when called `cume_dist()` \n", "\n", "  `na_last`: How NA values are ranked \n", "    - \"keep\": NA values are ranked at the end\n", "\n", "    - \"top\": NA values are ranked at the top\n", "\n", "    - \"bottom\": NA values are ranked at the bottom\n", "\n", "##### Returns:\n", "  The row number \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ ntile
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### a rough rank, which breaks the input vector into n buckets.\n", "The size of the buckets may differ by up to one, larger buckets \n", "have lower rank. \n", "\n", "Note that this function doesn't support piping. \n", "\n", "##### Args:\n", "  `x`: The data to get rownumber \n", "    Defaults to `Symbolic()` so the whole data is used by default \n", "    when called `ntile(n=...)` \n", "\n", "  `n`: The number of groups to divide the data into \n", "\n", "##### Returns:\n", "  The row number \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/ranking.html\n", "%run nb_helpers.py\n", "\n", "import numpy\n", "\n", "from datar.data import mtcars\n", "from datar.all import *\n", "\n", "nb_header(row_number, min_rank, dense_rank, percent_rank, cume_dist, ntile)" ] }, { "cell_type": "code", "execution_count": 2, "id": "prompt-outline", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:56.613630Z", "iopub.status.busy": "2021-07-16T22:27:56.612780Z", "iopub.status.idle": "2021-07-16T22:27:56.767009Z", "shell.execute_reply": "2021-07-16T22:27:56.767675Z" } }, "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", "
xrow_numbermin_rankdense_rankpercent_rankcume_distntile
<float64><float64><float64><float64><float64><float64><category>
05.01.05.04.01.001.02
11.02.01.01.00.000.21
23.03.04.03.00.750.81
32.04.02.02.00.250.61
42.05.02.02.00.250.61
5NaN6.0NaNNaNNaNNaNNaN
\n", "
\n" ], "text/plain": [ " x row_number min_rank dense_rank percent_rank cume_dist \\\n", " \n", "0 5.0 1.0 5.0 4.0 1.00 1.0 \n", "1 1.0 2.0 1.0 1.0 0.00 0.2 \n", "2 3.0 3.0 4.0 3.0 0.75 0.8 \n", "3 2.0 4.0 2.0 2.0 0.25 0.6 \n", "4 2.0 5.0 2.0 2.0 0.25 0.6 \n", "5 NaN 6.0 NaN NaN NaN NaN \n", "\n", " ntile \n", " \n", "0 2 \n", "1 1 \n", "2 1 \n", "3 1 \n", "4 1 \n", "5 NaN " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x=c(5, 1, 3, 2, 2, numpy.nan))\n", "df >> mutate(\n", " row_number=row_number(),\n", " min_rank=min_rank(f.x), \n", " dense_rank=dense_rank(f.x),\n", " percent_rank=percent_rank(f.x),\n", " cume_dist=cume_dist(f.x),\n", " ntile=ntile(f.x, n=2)\n", ")" ] }, { "cell_type": "code", "execution_count": 3, "id": "composed-macro", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:56.808996Z", "iopub.status.busy": "2021-07-16T22:27:56.808312Z", "iopub.status.idle": "2021-07-16T22:27:56.821087Z", "shell.execute_reply": "2021-07-16T22:27:56.821500Z" } }, "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", "
xntile
<int64><category>
001
111
221
332
442
553
663
773
\n", "
\n" ], "text/plain": [ " x ntile\n", " \n", "0 0 1\n", "1 1 1\n", "2 2 1\n", "3 3 2\n", "4 4 2\n", "5 5 3\n", "6 6 3\n", "7 7 3" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tibble(x=range(8)) >> mutate(ntile=ntile(f.x, n=3))" ] }, { "cell_type": "code", "execution_count": 4, "id": "distinct-means", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:56.870357Z", "iopub.status.busy": "2021-07-16T22:27:56.869814Z", "iopub.status.idle": "2021-07-16T22:27:56.878646Z", "shell.execute_reply": "2021-07-16T22:27:56.877742Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
mpgcyldisphpdratwtqsecvsamgearcarbn
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64><bool>
Mazda RX421.06160.01103.902.62016.460144False
Mazda RX4 Wag21.06160.01103.902.87517.020144False
Datsun 71022.84108.0933.852.32018.611141False
Hornet 4 Drive21.46258.01103.083.21519.441031False
Hornet Sportabout18.78360.01753.153.44017.020032False
Valiant18.16225.01052.763.46020.221031False
Duster 36014.38360.02453.213.57015.840034False
Merc 240D24.44146.7623.693.19020.001042False
Merc 23022.84140.8953.923.15022.901042False
Merc 28019.26167.61233.923.44018.301044False
Merc 280C17.86167.61233.923.44018.901044False
Merc 450SE16.48275.81803.074.07017.400033False
Merc 450SL17.38275.81803.073.73017.600033False
Merc 450SLC15.28275.81803.073.78018.000033False
Cadillac Fleetwood10.48472.02052.935.25017.980034False
Lincoln Continental10.48460.02153.005.42417.820034False
Chrysler Imperial14.78440.02303.235.34517.420034False
Fiat 12832.4478.7664.082.20019.471141False
Honda Civic30.4475.7524.931.61518.521142False
Toyota Corolla33.9471.1654.221.83519.901141False
Toyota Corona21.54120.1973.702.46520.011031False
Dodge Challenger15.58318.01502.763.52016.870032False
AMC Javelin15.28304.01503.153.43517.300032False
Camaro Z2813.38350.02453.733.84015.410034False
Pontiac Firebird19.28400.01753.083.84517.050032False
Fiat X1-927.3479.0664.081.93518.901141False
Porsche 914-226.04120.3914.432.14016.700152False
Lotus Europa30.4495.11133.771.51316.901152False
Ford Pantera L15.88351.02644.223.17014.500154False
Ferrari Dino19.76145.01753.622.77015.500156False
Maserati Bora15.08301.03353.543.57014.600158False
Volvo 142E21.44121.01094.112.78018.601142False
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt \\\n", " \n", "Mazda RX4 21.0 6 160.0 110 3.90 2.620 \n", "Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 \n", "Datsun 710 22.8 4 108.0 93 3.85 2.320 \n", "Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 \n", "Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 \n", "Valiant 18.1 6 225.0 105 2.76 3.460 \n", "Duster 360 14.3 8 360.0 245 3.21 3.570 \n", "Merc 240D 24.4 4 146.7 62 3.69 3.190 \n", "Merc 230 22.8 4 140.8 95 3.92 3.150 \n", "Merc 280 19.2 6 167.6 123 3.92 3.440 \n", "Merc 280C 17.8 6 167.6 123 3.92 3.440 \n", "Merc 450SE 16.4 8 275.8 180 3.07 4.070 \n", "Merc 450SL 17.3 8 275.8 180 3.07 3.730 \n", "Merc 450SLC 15.2 8 275.8 180 3.07 3.780 \n", "Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 \n", "Lincoln Continental 10.4 8 460.0 215 3.00 5.424 \n", "Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 \n", "Fiat 128 32.4 4 78.7 66 4.08 2.200 \n", "Honda Civic 30.4 4 75.7 52 4.93 1.615 \n", "Toyota Corolla 33.9 4 71.1 65 4.22 1.835 \n", "Toyota Corona 21.5 4 120.1 97 3.70 2.465 \n", "Dodge Challenger 15.5 8 318.0 150 2.76 3.520 \n", "AMC Javelin 15.2 8 304.0 150 3.15 3.435 \n", "Camaro Z28 13.3 8 350.0 245 3.73 3.840 \n", "Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 \n", "Fiat X1-9 27.3 4 79.0 66 4.08 1.935 \n", "Porsche 914-2 26.0 4 120.3 91 4.43 2.140 \n", "Lotus Europa 30.4 4 95.1 113 3.77 1.513 \n", "Ford Pantera L 15.8 8 351.0 264 4.22 3.170 \n", "Ferrari Dino 19.7 6 145.0 175 3.62 2.770 \n", "Maserati Bora 15.0 8 301.0 335 3.54 3.570 \n", "Volvo 142E 21.4 4 121.0 109 4.11 2.780 \n", "\n", " qsec vs am gear carb n \n", " \n", "Mazda RX4 16.46 0 1 4 4 False \n", "Mazda RX4 Wag 17.02 0 1 4 4 False \n", "Datsun 710 18.61 1 1 4 1 False \n", "Hornet 4 Drive 19.44 1 0 3 1 False \n", "Hornet Sportabout 17.02 0 0 3 2 False \n", "Valiant 20.22 1 0 3 1 False \n", "Duster 360 15.84 0 0 3 4 False \n", "Merc 240D 20.00 1 0 4 2 False \n", "Merc 230 22.90 1 0 4 2 False \n", "Merc 280 18.30 1 0 4 4 False \n", "Merc 280C 18.90 1 0 4 4 False \n", "Merc 450SE 17.40 0 0 3 3 False \n", "Merc 450SL 17.60 0 0 3 3 False \n", "Merc 450SLC 18.00 0 0 3 3 False \n", "Cadillac Fleetwood 17.98 0 0 3 4 False \n", "Lincoln Continental 17.82 0 0 3 4 False \n", "Chrysler Imperial 17.42 0 0 3 4 False \n", "Fiat 128 19.47 1 1 4 1 False \n", "Honda Civic 18.52 1 1 4 2 False \n", "Toyota Corolla 19.90 1 1 4 1 False \n", "Toyota Corona 20.01 1 0 3 1 False \n", "Dodge Challenger 16.87 0 0 3 2 False \n", "AMC Javelin 17.30 0 0 3 2 False \n", "Camaro Z28 15.41 0 0 3 4 False \n", "Pontiac Firebird 17.05 0 0 3 2 False \n", "Fiat X1-9 18.90 1 1 4 1 False \n", "Porsche 914-2 16.70 0 1 5 2 False \n", "Lotus Europa 16.90 1 1 5 2 False \n", "Ford Pantera L 14.50 0 1 5 4 False \n", "Ferrari Dino 15.50 0 1 5 6 False \n", "Maserati Bora 14.60 0 1 5 8 False \n", "Volvo 142E 18.60 1 1 4 2 False " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> mutate(n=row_number() == 0)" ] }, { "cell_type": "code", "execution_count": 5, "id": "cardiac-handy", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:56.904797Z", "iopub.status.busy": "2021-07-16T22:27:56.904123Z", "iopub.status.idle": "2021-07-16T22:27:56.918970Z", "shell.execute_reply": "2021-07-16T22:27:56.919564Z" } }, "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", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Mazda RX421.06160.01103.902.62016.460144
Mazda RX4 Wag21.06160.01103.902.87517.020144
Datsun 71022.84108.0933.852.32018.611141
Hornet 4 Drive21.46258.01103.083.21519.441031
Hornet Sportabout18.78360.01753.153.44017.020032
Valiant18.16225.01052.763.46020.221031
Duster 36014.38360.02453.213.57015.840034
Merc 240D24.44146.7623.693.19020.001042
Merc 23022.84140.8953.923.15022.901042
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt \\\n", " \n", "Mazda RX4 21.0 6 160.0 110 3.90 2.620 \n", "Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 \n", "Datsun 710 22.8 4 108.0 93 3.85 2.320 \n", "Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 \n", "Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 \n", "Valiant 18.1 6 225.0 105 2.76 3.460 \n", "Duster 360 14.3 8 360.0 245 3.21 3.570 \n", "Merc 240D 24.4 4 146.7 62 3.69 3.190 \n", "Merc 230 22.8 4 140.8 95 3.92 3.150 \n", "\n", " qsec vs am gear carb \n", " \n", "Mazda RX4 16.46 0 1 4 4 \n", "Mazda RX4 Wag 17.02 0 1 4 4 \n", "Datsun 710 18.61 1 1 4 1 \n", "Hornet 4 Drive 19.44 1 0 3 1 \n", "Hornet Sportabout 17.02 0 0 3 2 \n", "Valiant 20.22 1 0 3 1 \n", "Duster 360 15.84 0 0 3 4 \n", "Merc 240D 20.00 1 0 4 2 \n", "Merc 230 22.90 1 0 4 2 " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> filter(0 <= row_number() < 10)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/readme.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "0bf6a031", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:14.064442Z", "iopub.status.busy": "2021-07-16T22:28:14.063864Z", "iopub.status.idle": "2021-07-16T22:28:15.041239Z", "shell.execute_reply": "2021-07-16T22:28:15.040490Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 14:18:09][datar][WARNING] Builtin name \"filter\" has been masked by datar.\n" ] } ], "source": [ "from datar import f\n", "from datar.dplyr import mutate, filter, if_else\n", "from datar.tibble import tibble\n", "# or\n", "# from datar.all import f, mutate, filter, if_else, tibble" ] }, { "cell_type": "code", "execution_count": 2, "id": "58de6152", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:15.051111Z", "iopub.status.busy": "2021-07-16T22:28:15.050493Z", "iopub.status.idle": "2021-07-16T22:28:15.206338Z", "shell.execute_reply": "2021-07-16T22:28:15.206852Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " x y z\n", " \n", "0 0 zero 0\n", "1 1 one 1\n", "2 2 two 2\n", "3 3 three 3\n" ] } ], "source": [ "df = tibble(\n", " x=range(4),\n", " y=['zero', 'one', 'two', 'three']\n", ")\n", "print(df >> mutate(z=f.x))" ] }, { "cell_type": "code", "execution_count": 3, "id": "14e1e1e7", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:15.216846Z", "iopub.status.busy": "2021-07-16T22:28:15.216313Z", "iopub.status.idle": "2021-07-16T22:28:15.233753Z", "shell.execute_reply": "2021-07-16T22:28:15.231626Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " x y z\n", " \n", "0 0 zero 0.0\n", "1 1 one 0.0\n", "2 2 two 1.0\n", "3 3 three 1.0\n" ] } ], "source": [ "print(df >> mutate(z=if_else(f.x>1, 1, 0)))" ] }, { "cell_type": "code", "execution_count": 4, "id": "eeedac45", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:15.242660Z", "iopub.status.busy": "2021-07-16T22:28:15.242045Z", "iopub.status.idle": "2021-07-16T22:28:15.247915Z", "shell.execute_reply": "2021-07-16T22:28:15.247328Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " x y\n", " \n", "2 2 two\n", "3 3 three\n" ] } ], "source": [ "print(df >> filter(f.x>1))" ] }, { "cell_type": "code", "execution_count": 5, "id": "4dbd113a", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:15.267746Z", "iopub.status.busy": "2021-07-16T22:28:15.258642Z", "iopub.status.idle": "2021-07-16T22:28:15.270724Z", "shell.execute_reply": "2021-07-16T22:28:15.271081Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " x y z\n", " \n", "2 2 two 1.0\n", "3 3 three 1.0\n" ] } ], "source": [ "print(df >> mutate(z=if_else(f.x>1, 1, 0)) >> filter(f.z==1))" ] }, { "cell_type": "code", "execution_count": 8, "id": "f0577dbd", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:15.277204Z", "iopub.status.busy": "2021-07-16T22:28:15.276249Z", "iopub.status.idle": "2021-07-16T22:28:20.025132Z", "shell.execute_reply": "2021-07-16T22:28:20.025675Z" } }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAArkAAAGuCAYAAACUZR4KAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAA9hAAAPYQGoP6dpAABTiElEQVR4nO3deXiU1cH+8fuZmezLTDaSAAFcEHGXRS2oLLKvUlCpgkVrq61vXdrXWru4tC5trT+1VSt9bV0QKloXQAFBARcUF0B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gNWcw0ap6s0lkqSaD99XzmVXyOHKsjgVEB28e4pVv25t88Bul3PocGsDdYCpn7XPOz7PnXbiAe//n//5Hx1//PGSpHvuuUfnnHOOTjzxRI0cOVJjx46VJF155ZV67LHHNG/ePP3oRz9SYmKivv76a5WVlSk3N1fnnntuqzJNmzZNf//733XTTTdJkmbPnq0bbrhBkjRz5kxdc801Ov/85gM/xo0bp7POOksLFy7UlVde2arP15aYyQUQ9xILOyv19DObB36/qpZH/1XFQEf59gdESUrvd64cWdkWpolN3bp1C93u3r27vF6viouL1aNHjxaP69Gjh3bt2iVJevnll7V+/Xr17NlT/fv316uvvtqqz/39739fn3/+ub788ktt2rRJGzdu1Pe//31JzUsf/v73v8vlcoV+rVq1Srt3727dH7SNMZMLAJKcw0epfv06SVL18jeUPe5iGQkJFqcCIlugoV7V76wIjZ1h2/Kh7Wzfvr3F7YSEBBUWFmrt2rUtHrd161YNH948k96nTx+99NJL8vv9mjt3rqZMmaLy8vL9PvbhLhBMT0/XxIkT9eyzz8o0TU2cOFHp6emSmsv3r371K915553H+CdsH5RcAJCUetqZSsgvUNPePfJXV6n2o1XKGHDB4Z8IxLHqd9+W6WmQJCUdd7yST+hpcaKOcbBlBe3lscce07hx45Sbm6vf/e53uuyyyzR16lT96U9/0qJFizR8+HA999xz+uKLLzRx4kR5vV7NnTtX48aNU1ZWllwulwzDkN1u3+9j5+fna/PmzYf8/NOmTdPPf/5zSdLf//730P0/+clPNG7cOA0bNkwDBgxQY2OjVq1apZ49e6pr165t+0VoBZYrAICC24mFHfXrXrpIZvDkJgD7MwMBVb0Rvm3YaLYNaydXXnmlJkyYoK5du8put+vhhx/WSSedpOeff1633nqrcnJy9PDDD+u1115Tbm7zKXNz5szRCSecoIyMDN166616/vnnlZycvN/HvvHGGzV//nxlZWXphz/84QE//4gRI1RbW6va2lqNGLHvqOY+ffro6aef1i233KKcnBx1795dDzzwgAKBQPt8IY6SYfKveMiaNWvUt29frV69Wn369LE6DoAOFmio15abrw/NTHX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IQjsnHjRlVWVuq6666TJHm9Xnm9Xl155ZV6/PHH93uHCQiXnp6u3NxcfqBG1KPktqPk5GQNHDhQs2bN0s0336zS0lItWbJEN954o9XRECVmzpypTZs26e6776aY4Iidf/756tOnT2j8zjvvaPny5br99tv5QQlHZMSIEXrttdfUr18/JSUl6cUXX9Q555xjdSzgqFBy29m1116rRx55RDNmzFBKSoomT57M9mE4IiUlJVq4cKESEhJ09dVXh+6fMmWKLr30UguTIdIlJSWF3nKWmq8FsNvtysrKsjAVoskll1yi6upqXX/99bLb7erXr5+uueYaq2MBR8UwTdO0OgQAAADQlrjwDAAAADGHkgsAAICYQ8kFAABAzKHkAgAAIOZQcgEAABBzKLkAAACIOZRcAAAAxBxKLgAAAGIOJRcAAAAxh5ILAACAmEPJBQAAQMyh5AIAACDmUHIBRK3q6mp1795dU6ZMaXH/ddddp5ycHO3evduiZAAAq1FyAUStzMxMPfnkk3rppZc0a9YsSdKiRYs0c+ZMPfbYY+rcubPFCQEAVjFM0zStDgEAx+LGG2/U008/rRUrVmjMmDEaPHiw5syZY3UsAICFKLkAol5DQ4P69OmjLVu2KDc3V+vXr1dWVpbVsQAAFmK5AoCol5KSoosvvliNjY26/PLLKbgAAGZyAUS/Tz/9VP3799epp56qjRs3as2aNerdu7fVsQAAFqLkAohqXq9X/fv3V2Zmpt58800NHDhQkvT+++/L4XBYnA4AYBWWKwCIarfffrs2b96sp556SomJiXrmmWf02Wef6e6777Y6GgDAQpRcAFHrvffe0/33368HHnhAJ5xwgiSpd+/euu+++3TPPffo448/tjghAMAqLFcAAABAzGEmFwAAADGHkgsAAICYQ8kFAABAzKHkAgAAIOZQcgEAABBzKLkAAACIOZRcAAAAxBxKLgAAAGIOJRcAAAAxh5ILAACAmEPJBQAAQMz5/ypYmUL4HD1BAAAAAElFTkSuQmCC", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# works with plotnine\n", "import numpy\n", "from datar.base import sin, pi\n", "from datar.tibble import tibble\n", "from datar.dplyr import mutate, if_else\n", "from plotnine import ggplot, aes, geom_line, theme_classic\n", "\n", "df = tibble(x=numpy.linspace(0, 2 * pi, 500))\n", "(\n", " df\n", " >> mutate(y=sin(f.x), sign=if_else(f.y >= 0, \"positive\", \"negative\"))\n", " >> ggplot(aes(x=\"x\", y=\"y\"))\n", " + theme_classic()\n", " + geom_line(aes(color=\"sign\"), size=1.2)\n", ")" ] }, { "cell_type": "code", "execution_count": 9, "id": "c30cc8e9", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:20.047812Z", "iopub.status.busy": "2021-07-16T22:28:20.047169Z", "iopub.status.idle": "2021-07-16T22:28:20.809510Z", "shell.execute_reply": "2021-07-16T22:28:20.810013Z" } }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAA3wAAACsCAYAAAAgwq6QAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAABckElEQVR4nO3dd1jUV/rw4c+ZQu+oKKJiF1HsXdFYEmOKmmY0zdRNVmN6NqubxHVTTMy+m/ZL31VTNN0eU+xJ1Ng1KHZREVGkt4Fh5rx/DI4gKEVgKM99XaMz59ueGebAPHOa0lojhBBCCCGEEKL+Mbg6ACGEEEIIIYQQ1UMSPiGEEEIIIYSopyThE0IIIYQQQoh6ShI+IYQQQgghhKinJOETQgghhBBCiHrK5OoAKmr06NH6xx9/dHUYQgghhBBCCFGbqNIK61wL37lz51wdghBCCCGEEELUCXUu4RNCCCGEEEIIUT6S8AkhhBBCCCFEPSUJnxBCCCGEEELUU3Vu0hYhhBBCCCFE9bNarcTHx2OxWFwdiijCw8ODsLAwzGZzufavFw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YM/GPpPpbskoXahahK8+bNc/ZAs9lszJs3jz179gBgtVqZN28eMTExAFgsFubNm0dsbCwAOTk5zJs3jwMHDgCQlZVVZXHNnTuX7t270717d7Zt28aYMWPo3r0748ePL7Hv77//zsqVK9m5cycnTpwgKiqKzZs3V1kstVFZXTq9C/+vmf6QldClSxd69uxJVFQUgwYNon///kyYMMGZAALk5eUxZcoUWrVqxccff0xGRgZPPfUUX331FU2bNiUxMZERI0awceNGoqOjeffdd5k2bRobNmygd+/ebNiwgRtvvJHt27fTv39/5s6dy+nTp5k+vWSv1vj4eFq0uLDefFhYGAkJl+5KFB0dTXx8PJGRkXzxhUwKIeq3kyk5vLoyFnc3M/ddFUEj73IvBepSkb36uToEUQ7DR19foszuGeqCSERVqGy9axnszT9u7MrcX48wd9NxYk9n8Ojwdni7143fN0KIirv33nu59957gbK7dG7ZsoVx48bh6ekJwNixY1m7di3du3evoWhr3mV/+2mtPyz8v9ZOe2YwGPj888/Zt28fGzduZMWKFbz77rv89ttvBAY6FmS99dZbGT9+vLOr55YtWzh+/Di33Xab8zxKKY4ePUq/fv24//77yc/P548//mDWrFksXbqU0NBQIiIi8PLycr6hqsKGDRuwWq0899xzzJs3j2nTplXZuYWoTc5mWHj5h1g0Bu4bHkEzv7ozhXrrDjIldV3Qo99AV4cgqtCV1DtPNxOPDO/A6n2JLNp2nOPf/snfrulAeCPvsg8WQlzS5MmTnfeNRmOxx2azudhjDw+PYo+9vLyKPS7v/BpFW+mthcu1XAmTyYTdbnc+ttvtmEz1+wuhcg2cUUq9rpTyU0qZlVKrlVJJRbp71gqdO3fmgQceYNGiRfj6+vLbb785tw0aNIg1a9aQk5MDON44kZGRbNiwwXmLiYmhR48eeHp6EhkZyXfffUdISAhDhgxh69atrF+/nujo6DLjCAsL4+TJk87H8fHxhIZe/htms9nM7bffzldffVXJZy9E7Zaanc9LK2LJttqZPDyCFgF1q6+8JScHS+HvD1F7ZWVkkJVRfNyW/86H8N/5kIsiElfiSuudUoqRkc14Yn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ruPv//97+U+Ztu2bWzYsIHWrVsDsHLlSqZOnco111wDwP/+9z9iYmJYt24d4OiuOX/+fO677z5efPFF/vjjD5o2bUpeXl6J7qOpqam8//77xMbG4unpSWZmJp6engBMmzaNa6+9lmuvvfay8aWkpKC1Jjj4wvo+YWFhnDp1ip49e5bYf+PGjURHR+Pr68tjjz3G1VdfXWx7fn4+3377LYsWLSr3ayTqP601C7acYNnuBCKaB3LrwPYEeNSZql8jks8kAhAc0tTFkYjLORl3FIAW4W2cZek9pDtnXVUf6l1Ui0A6NPVj6c54foo9zZa4VO4bGM6gdsEV6oUkhBBXot5MsD5q1CgWL17M6dOny31Mv379nMleadatW8fEiRNxc3PDzc2NSZMmOZO/6Oho/vrXv/LRRx9x+vRpvLy8ih3r5+dHmzZteOSRR5g/fz7Z2dmYTI78+u233y4z2auoa665hj179rBhwwZeffVVpk2bxoEDB4rts2LFCsLCwujatVY1zgoXyi+w8/bqwyzbncCozk158KqOeLlJsnexTWt+ZNOaH10dhijD1/M/4ev5n7g6DFFF6ku98zAbua1vK565riteHu78e9UhXlqxnzMZFleHJoRoIOpNwvfoo48yceJExo4d60z6TCYTRWchzcvLK3aMt7d3pa/36aefMmPGDHJycrjxxhv55Zdfim03Go38/PPPPPjggyQkJDB8+HD27t172XOuXr3aObHK22+/TVBQEADJycnOfeLj42nevGQXl+DgYGcLYlRUFH379mXHjh3F9vniiy+44447KvV8Rf2TnmvllR9i2XT0HJP6teK+QeEY5BvnUg0YPpoBw0e7OgxRhtvueYDb7nmgWJkhNwFDboKLIhJXor7Vu/BG3jx3QxfG9WnNn6czmfblbj7ddFy6eQohql1Zk7bUKU888QRaa8aOHcuSJUto3bo1e/fuJS8vD6UUS5cuxc/v0oOmfX19ycjIcD4eNmwYCxcuZPz48QAsXLiQG2+8kYKCAk6ePEmvXr3o1asXx44d488//2TUqAsDzDMzM8nOzmbQoEEMGjSIrVu3EhsbS2Rk5CWvP2LECEaMGFGsbOzYscydO9c5aYvFYqF79+4ljk1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4rcr+y5xBCCNGASJdOIYQQdZJSqmNhq9x53YFYoHHhhC4opcxKqcgi+0woLB8MpBe2lvkDpwq3T77CsFYDtyilmhReJ0gp1aqMYzYDNxfev71IeSaO1kchhBCi0iThE0IIUVf54OiKuU8ptQfojGMM3i3Aa0qp3cAuYGCRYyxKqZ3AB8D9hWWvA68Wlle0xWyyUir+/A3IAP4B/FwY0y84Jpe5nMeBJwv3bwekF5bvAWyFk7w8camDhRBCiMtRF3qXCCGEEPWXUmod8LTWepurYylKKeUF5GqttVLqdmCi1nqsq+MSQghRP0jffyGEEMK1egHvKscsL2nAfa4NRwghRH0iLXxCCCHEZSil7gUeu6j4d631FFfEI4QQQlSEJHxCCCGEEEIIUU/JpC1CCCGEEEIIUU9JwieEEEIIIYQQ9ZQkfEIIIYQQQghRT0nCJ4QQQgghhBD11P8Hfko3VxvBB38AAAAASUVORK5CYII=", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "# very easy to integrate with other libraries\n", "# for example: klib\n", "import klib\n", "from pipda import register_verb\n", "from datar import f\n", "from datar.data import iris\n", "from datar.dplyr import pull\n", "\n", "dist_plot = register_verb(func=klib.dist_plot)\n", "iris >> pull(f.Sepal_Length) >> dist_plot()" ] }, { "cell_type": "code", "execution_count": null, "id": "0beb04c3", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/recode.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "material-amount", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:29.632035Z", "iopub.status.busy": "2021-07-16T22:28:29.631390Z", "iopub.status.idle": "2021-07-16T22:28:30.537989Z", "shell.execute_reply": "2021-07-16T22:28:30.538579Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ recode
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Recode a vector, replacing elements in it\n", "\n", "##### Args:\n", "  `x`: A vector to modify \n", "  `*args`: and \n", "  `**kwargs`: replacements \n", "  `_default`: If supplied, all values not otherwise matched will be \n", "    given this value. If not supplied and if the replacements are \n", "    the same type as the original values in series, unmatched values \n", "    are not changed. If not supplied and if the replacements are \n", "    not compatible, unmatched values are replaced with np.nan. \n", "\n", "  `_missing`: If supplied, any missing values in .x will be replaced \n", "    by this value. \n", "\n", "##### Returns:\n", "  The vector with values replaced \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/recode.html\n", "%run nb_helpers.py\n", "\n", "from datar.all import *\n", "\n", "nb_header(recode)" ] }, { "cell_type": "code", "execution_count": 2, "id": "cordless-istanbul", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:30.549605Z", "iopub.status.busy": "2021-07-16T22:28:30.548937Z", "iopub.status.idle": "2021-07-16T22:28:30.552617Z", "shell.execute_reply": "2021-07-16T22:28:30.553026Z" } }, "outputs": [ { "data": { "text/plain": [ "0 Apple\n", "1 c\n", "2 c\n", "3 Apple\n", "4 b\n", "5 Apple\n", "6 b\n", "7 b\n", "8 b\n", "9 c\n", "dtype: object" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "char_vec = sample(c(\"a\", \"b\", \"c\"), 10, replace=True)\n", "recode(char_vec, a=\"Apple\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "talented-insert", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:30.560559Z", "iopub.status.busy": "2021-07-16T22:28:30.559899Z", "iopub.status.idle": "2021-07-16T22:28:30.563572Z", "shell.execute_reply": "2021-07-16T22:28:30.564016Z" } }, "outputs": [ { "data": { "text/plain": [ "0 Apple\n", "1 c\n", "2 c\n", "3 Apple\n", "4 Banana\n", "5 Apple\n", "6 Banana\n", "7 Banana\n", "8 Banana\n", "9 c\n", "dtype: object" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "recode(char_vec, a=\"Apple\", b=\"Banana\")" ] }, { "cell_type": "code", "execution_count": 4, "id": "piano-jordan", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:30.570326Z", "iopub.status.busy": "2021-07-16T22:28:30.569697Z", "iopub.status.idle": "2021-07-16T22:28:30.575258Z", "shell.execute_reply": "2021-07-16T22:28:30.574225Z" } }, "outputs": [ { "data": { "text/plain": [ "0 Apple\n", "1 NaN\n", "2 NaN\n", "3 Apple\n", "4 Banana\n", "5 Apple\n", "6 Banana\n", "7 Banana\n", "8 Banana\n", "9 NaN\n", "dtype: object" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "recode(char_vec, a=\"Apple\", b=\"Banana\", _default = NA)" ] }, { "cell_type": "code", "execution_count": 5, "id": "civilian-aberdeen", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:30.582836Z", "iopub.status.busy": "2021-07-16T22:28:30.581981Z", "iopub.status.idle": "2021-07-16T22:28:30.586613Z", "shell.execute_reply": "2021-07-16T22:28:30.587100Z" } }, "outputs": [ { "data": { "text/plain": [ "0 apple\n", "1 carrot\n", "2 carrot\n", "3 apple\n", "4 banana\n", "5 apple\n", "6 banana\n", "7 banana\n", "8 banana\n", "9 carrot\n", "dtype: object" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "level_key = dict(a=\"apple\", b=\"banana\", c=\"carrot\")\n", "recode(char_vec, **level_key)" ] }, { "cell_type": "code", "execution_count": 6, "id": "perceived-underground", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:30.595687Z", "iopub.status.busy": "2021-07-16T22:28:30.594899Z", "iopub.status.idle": "2021-07-16T22:28:30.600811Z", "shell.execute_reply": "2021-07-16T22:28:30.601267Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 14:19:25][datar][WARNING] Unreplaced values treated as NA as `_x` is not compatible. Please specify replacements exhaustively or supply `_default`\n" ] }, { "data": { "text/plain": [ "0 NaN\n", "1 20\n", "2 NaN\n", "3 40\n", "4 NaN\n", "dtype: object" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "num_vec = c(range(4), NA)\n", "recode(num_vec, {1: 20, 3: 40})" ] }, { "cell_type": "code", "execution_count": 7, "id": "paperback-threshold", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:30.608649Z", "iopub.status.busy": "2021-07-16T22:28:30.606230Z", "iopub.status.idle": "2021-07-16T22:28:30.613872Z", "shell.execute_reply": "2021-07-16T22:28:30.612973Z" } }, "outputs": [ { "data": { "text/plain": [ "0 a\n", "1 b\n", "2 c\n", "3 d\n", "4 NaN\n", "dtype: object" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "recode(num_vec, \"a\", \"b\", \"c\", \"d\")" ] }, { "cell_type": "code", "execution_count": 8, "id": "quick-nicaragua", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:30.621513Z", "iopub.status.busy": "2021-07-16T22:28:30.620815Z", "iopub.status.idle": "2021-07-16T22:28:30.627088Z", "shell.execute_reply": "2021-07-16T22:28:30.627476Z" } }, "outputs": [ { "data": { "text/plain": [ "0 a\n", "1 nothing\n", "2 c\n", "dtype: object" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "recode(c(0,4,2), \"a\", \"b\", \"c\", \"d\", _default=\"nothing\")" ] }, { "cell_type": "code", "execution_count": 9, "id": "sealed-description", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:30.633870Z", "iopub.status.busy": "2021-07-16T22:28:30.632901Z", "iopub.status.idle": "2021-07-16T22:28:30.638719Z", "shell.execute_reply": "2021-07-16T22:28:30.638086Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 14:19:31][datar][WARNING] Unreplaced values treated as NA as `_x` is not compatible. Please specify replacements exhaustively or supply `_default`\n" ] }, { "data": { "text/plain": [ "0 NaN\n", "1 b\n", "2 NaN\n", "3 d\n", "4 NaN\n", "dtype: object" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "recode(num_vec, {1: \"b\", 3: \"d\"})" ] }, { "cell_type": "code", "execution_count": 10, "id": "adjacent-harrison", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:30.646297Z", "iopub.status.busy": "2021-07-16T22:28:30.645533Z", "iopub.status.idle": "2021-07-16T22:28:30.648897Z", "shell.execute_reply": "2021-07-16T22:28:30.649332Z" } }, "outputs": [ { "data": { "text/plain": [ "0 a\n", "1 b\n", "2 c\n", "3 other\n", "4 NaN\n", "dtype: object" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "recode(num_vec, \"a\", \"b\", \"c\", _default=\"other\")" ] }, { "cell_type": "code", "execution_count": 11, "id": "requested-presentation", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:30.655731Z", "iopub.status.busy": "2021-07-16T22:28:30.655058Z", "iopub.status.idle": "2021-07-16T22:28:30.660919Z", "shell.execute_reply": "2021-07-16T22:28:30.661302Z" } }, "outputs": [ { "data": { "text/plain": [ "0 a\n", "1 b\n", "2 c\n", "3 other\n", "4 missing\n", "dtype: object" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "recode(num_vec, \"a\", \"b\", \"c\", _default=\"other\", _missing=\"missing\")" ] }, { "cell_type": "code", "execution_count": 12, "id": "manufactured-tract", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:30.669879Z", "iopub.status.busy": "2021-07-16T22:28:30.669272Z", "iopub.status.idle": "2021-07-16T22:28:30.672942Z", "shell.execute_reply": "2021-07-16T22:28:30.673970Z" } }, "outputs": [ { "data": { "text/plain": [ "['a', 'b', 'c']\n", "Categories (3, object): ['a', 'b', 'c']" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "factor_vec = factor(c(\"a\", \"b\", \"c\"))\n", "factor_vec" ] }, { "cell_type": "code", "execution_count": 13, "id": "chubby-treasurer", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:30.684207Z", "iopub.status.busy": "2021-07-16T22:28:30.683379Z", "iopub.status.idle": "2021-07-16T22:28:30.687502Z", "shell.execute_reply": "2021-07-16T22:28:30.687885Z" } }, "outputs": [ { "data": { "text/plain": [ "0 Apple\n", "1 b\n", "2 c\n", "dtype: category\n", "Categories (3, object): ['Apple', 'b', 'c']" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# categories lost\n", "recode(factor_vec, a=\"Apple\")" ] }, { "cell_type": "code", "execution_count": 14, "id": "molecular-silly", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:30.770892Z", "iopub.status.busy": "2021-07-16T22:28:30.767304Z", "iopub.status.idle": "2021-07-16T22:28:30.784841Z", "shell.execute_reply": "2021-07-16T22:28:30.784148Z" } }, "outputs": [ { "data": { "text/plain": [ "0 Apple\n", "1 b\n", "2 c\n", "dtype: category\n", "Categories (3, object): ['Apple', 'b', 'c']" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "recode_factor(factor_vec, a=\"Apple\")" ] }, { "cell_type": "code", "execution_count": 15, "id": "english-currency", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:30.795152Z", "iopub.status.busy": "2021-07-16T22:28:30.794527Z", "iopub.status.idle": "2021-07-16T22:28:30.811477Z", "shell.execute_reply": "2021-07-16T22:28:30.811930Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 14:19:42][datar][WARNING] Unreplaced values treated as NA as `_x` is not compatible. Please specify replacements exhaustively or supply `_default`\n" ] }, { "data": { "text/plain": [ "0 z\n", "1 y\n", "2 x\n", "3 NaN\n", "4 NaN\n", "dtype: category\n", "Categories (3, object): ['z', 'y', 'x']" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "recode_factor(num_vec, {0: \"z\", 1: \"y\", 2: \"x\"})" ] }, { "cell_type": "code", "execution_count": 16, "id": "guilty-locator", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:30.821569Z", "iopub.status.busy": "2021-07-16T22:28:30.820837Z", "iopub.status.idle": "2021-07-16T22:28:30.829888Z", "shell.execute_reply": "2021-07-16T22:28:30.828676Z" } }, "outputs": [ { "data": { "text/plain": [ "0 z\n", "1 y\n", "2 x\n", "3 D\n", "4 NaN\n", "dtype: category\n", "Categories (4, object): ['z', 'y', 'x', 'D']" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "recode_factor(num_vec, {0: \"z\", 1: \"y\", 2: \"x\"}, _default=\"D\")" ] }, { "cell_type": "code", "execution_count": 17, "id": "opponent-nevada", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:30.838860Z", "iopub.status.busy": "2021-07-16T22:28:30.838050Z", "iopub.status.idle": "2021-07-16T22:28:30.844064Z", "shell.execute_reply": "2021-07-16T22:28:30.843291Z" } }, "outputs": [ { "data": { "text/plain": [ "0 z\n", "1 y\n", "2 x\n", "3 D\n", "4 M\n", "dtype: category\n", "Categories (5, object): ['z', 'y', 'x', 'D', 'M']" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "recode_factor(num_vec, {0: \"z\", 1: \"y\", 2: \"x\"}, _default=\"D\", _missing=\"M\")" ] }, { "cell_type": "code", "execution_count": 18, "id": "horizontal-shade", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:30.852634Z", "iopub.status.busy": "2021-07-16T22:28:30.851853Z", "iopub.status.idle": "2021-07-16T22:28:30.855901Z", "shell.execute_reply": "2021-07-16T22:28:30.856297Z" } }, "outputs": [ { "data": { "text/plain": [ "0 a\n", "1 z\n", "2 y\n", "dtype: category\n", "Categories (3, object): ['z', 'y', 'a']" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "recode_factor(list(letters[:3]), b=\"z\", c=\"y\")" ] }, { "cell_type": "code", "execution_count": 19, "id": "accredited-consortium", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:30.865663Z", "iopub.status.busy": "2021-07-16T22:28:30.864990Z", "iopub.status.idle": "2021-07-16T22:28:30.868476Z", "shell.execute_reply": "2021-07-16T22:28:30.868859Z" } }, "outputs": [ { "data": { "text/plain": [ "0 apple\n", "1 carrot\n", "2 carrot\n", "3 apple\n", "4 banana\n", "5 apple\n", "6 banana\n", "7 banana\n", "8 banana\n", "9 carrot\n", "dtype: category\n", "Categories (3, object): ['apple', 'banana', 'carrot']" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "level_key = dict(a=\"apple\", b=\"banana\", c=\"carrot\")\n", "recode_factor(char_vec, **level_key)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/reframe.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "4ba9dd17", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:30.653194Z", "iopub.status.busy": "2021-07-16T22:27:30.652556Z", "iopub.status.idle": "2021-07-16T22:27:33.410785Z", "shell.execute_reply": "2021-07-16T22:27:33.411264Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ reframe
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Reframe a data frame.\n", "\n", "See original API \n", "https://dplyr.tidyverse.org/reference/reframe.html \n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `*args`: and \n", "  `**kwargs`: Name-value pairs, where value is the reframed \n", "    data for each group \n", "\n", "##### Returns:\n", "  A data frame with the reframed columns \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/summarise.html\n", "%run nb_helpers.py\n", "\n", "from datar.data import starwars\n", "from datar.all import *\n", "\n", "nb_header(reframe)" ] }, { "cell_type": "code", "execution_count": 2, "id": "193d02c5", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:33.468439Z", "iopub.status.busy": "2021-07-16T22:27:33.465218Z", "iopub.status.idle": "2021-07-16T22:27:33.487717Z", "shell.execute_reply": "2021-07-16T22:27:33.490086Z" } }, "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", "
x
<object>
0a
1b
2f
3d
\n", "
\n" ], "text/plain": [ " x\n", " \n", "0 a\n", "1 b\n", "2 f\n", "3 d" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "table = c(\"a\", \"b\", \"d\", \"f\")\n", "\n", "df = tibble(\n", " g = c(1, 1, 1, 2, 2, 2, 2),\n", " x = c(\"e\", \"a\", \"b\", \"c\", \"f\", \"d\", \"a\")\n", ")\n", "\n", "# `reframe()` allows you to apply functions that return\n", "# an arbitrary number of rows\n", "df >> reframe(x = intersect(f.x, table))" ] }, { "cell_type": "code", "execution_count": 3, "id": "847cd875", "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", "
gx
<int64><object>
01e
11a
21b
32c
42f
52d
62a
\n", "
\n", "

TibbleGrouped: g (n=2)" ], "text/plain": [ " g x\n", " \n", "0 1 e\n", "1 1 a\n", "2 1 b\n", "3 2 c\n", "4 2 f\n", "5 2 d\n", "6 2 a\n", "[TibbleGrouped: g (n=2)]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> group_by(f.g)" ] }, { "cell_type": "code", "execution_count": 4, "id": "0f48dddc", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:33.498734Z", "iopub.status.busy": "2021-07-16T22:27:33.497950Z", "iopub.status.idle": "2021-07-16T22:27:33.637631Z", "shell.execute_reply": "2021-07-16T22:27:33.638084Z" } }, "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", "
gx
<Int64><string>
01a
11b
22f
32d
42a
\n", "
\n" ], "text/plain": [ " g x\n", " \n", "0 1 a\n", "1 1 b\n", "2 2 f\n", "3 2 d\n", "4 2 a" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# The output is always ungrouped, even when using `group_by()`\n", "(\n", " df\n", " >> group_by(f.g)\n", " >> reframe(x = intersect(f.x, table))\n", ")" ] }, { "cell_type": "code", "execution_count": 12, "id": "ccd6b9ad", "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", "
valquant
<float64><float64>
011.500.25
113.500.50
215.750.75
\n", "
\n" ], "text/plain": [ " val quant\n", " \n", "0 11.50 0.25\n", "1 13.50 0.50\n", "2 15.75 0.75" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from pandas.core.groupby import SeriesGroupBy\n", "from pipda import register_func\n", "\n", "@register_func\n", "def quantile_df(x, probs=[0.25, 0.5, 0.75]):\n", " return tibble(\n", " val = quantile(x, probs, na_rm=True),\n", " quant = [probs] if isinstance(x, SeriesGroupBy) else probs\n", " )\n", "\n", "\n", "x = [10, 15, 18, 12]\n", "quantile_df(x)" ] }, { "cell_type": "code", "execution_count": 13, "id": "73a64ee0", "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", "
valquant
<float64><float64>
0167.00.25
1180.00.50
2191.00.75
\n", "
\n" ], "text/plain": [ " val quant\n", " \n", "0 167.0 0.25\n", "1 180.0 0.50\n", "2 191.0 0.75" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> reframe(quantile_df(f.height))" ] }, { "cell_type": "code", "execution_count": 14, "id": "a630dcd5", "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", "
homeworldvalquant
<string><Float64><Float64>
0Tatooine165.50.25
1Tatooine175.00.5
2Tatooine183.00.75
3Naboo165.00.25
............
4Naboo183.00.5
142Umbara178.00.5
143Umbara178.00.75
144Utapau206.00.25
145Utapau206.00.5
146Utapau206.00.75
\n", "

147 rows × 3 columns

\n", "
\n" ], "text/plain": [ " homeworld val quant\n", " \n", "0 Tatooine 165.5 0.25\n", "1 Tatooine 175.0 0.5\n", "2 Tatooine 183.0 0.75\n", "3 Naboo 165.0 0.25\n", ".. ... ... ...\n", "4 Naboo 183.0 0.5\n", "142 Umbara 178.0 0.5\n", "143 Umbara 178.0 0.75\n", "144 Utapau 206.0 0.25\n", "145 Utapau 206.0 0.5\n", "146 Utapau 206.0 0.75\n", "\n", "[147 rows x 3 columns]" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(\n", " starwars\n", " >> group_by(f.homeworld)\n", " >> reframe(quantile_df(f.height))\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "99fe1739", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/pwwang/.cache/pypoetry/virtualenvs/datar-TA_GutPO-py3.12/lib/python3.12/site-packages/numpy/lib/_nanfunctions_impl.py:1598: RuntimeWarning: All-NaN slice encountered\n", " return _nanquantile_unchecked(\n" ] }, { "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", "
homeworldheight$valheight$quantmass$valmass$quant
<string><Float64><Float64><Float64><Float64>
0Tatooine165.50.2575.00.25
1Tatooine175.00.580.50.5
2Tatooine183.00.7593.00.75
3Naboo165.00.2550.250.25
..................
4Naboo183.00.570.50.5
142Umbara178.00.548.00.5
143Umbara178.00.7548.00.75
144Utapau206.00.2580.00.25
145Utapau206.00.580.00.5
146Utapau206.00.7580.00.75
\n", "

147 rows × 5 columns

\n", "
\n" ], "text/plain": [ " homeworld height$val height$quant mass$val mass$quant\n", " \n", "0 Tatooine 165.5 0.25 75.0 0.25\n", "1 Tatooine 175.0 0.5 80.5 0.5\n", "2 Tatooine 183.0 0.75 93.0 0.75\n", "3 Naboo 165.0 0.25 50.25 0.25\n", ".. ... ... ... ... ...\n", "4 Naboo 183.0 0.5 70.5 0.5\n", "142 Umbara 178.0 0.5 48.0 0.5\n", "143 Umbara 178.0 0.75 48.0 0.75\n", "144 Utapau 206.0 0.25 80.0 0.25\n", "145 Utapau 206.0 0.5 80.0 0.5\n", "146 Utapau 206.0 0.75 80.0 0.75\n", "\n", "[147 rows x 5 columns]" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(\n", " starwars\n", " >> group_by(f.homeworld)\n", " >> reframe(\n", " across(c(f.height, f.mass), quantile_df)\n", " )\n", ")" ] } ], "metadata": { "kernelspec": { "display_name": "datar-TA_GutPO-py3.12", "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.12.2" } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/relocate.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:21.732360Z", "iopub.status.busy": "2021-07-16T22:28:21.731652Z", "iopub.status.idle": "2021-07-16T22:28:22.625834Z", "shell.execute_reply": "2021-07-16T22:28:22.625374Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ relocate
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### change column positions\n", "\n", "See original API \n", "https://dplyr.tidyverse.org/reference/relocate.html \n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `*args`: and \n", "  `**kwargs`: Columns to rename and move \n", "  `_before`: and \n", "  `_after`: Destination. Supplying neither will move columns to \n", "    the left-hand side; specifying both is an error. \n", "\n", "##### Returns:\n", "  An object of the same type as .data. The output has the following \n", "  properties: \n", "  - Rows are not affected.\n", "  - The same columns appear in the output, but (usually) in a\n", "    different place. \n", "\n", "  - Data frame attributes are preserved.\n", "  - Groups are not affected\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/relocate.html\n", "%run nb_helpers.py\n", "from datar.all import *\n", "\n", "nb_header(relocate)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:22.631741Z", "iopub.status.busy": "2021-07-16T22:28:22.631056Z", "iopub.status.idle": "2021-07-16T22:28:22.790437Z", "shell.execute_reply": "2021-07-16T22:28:22.789722Z" } }, "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", "
abcdef
<int64><int64><int64><object><object><object>
0111aaa
\n", "
\n" ], "text/plain": [ " a b c d e f\n", " \n", "0 1 1 1 a a a" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(a=1, b=1, c=1, d='a', e='a', f='a')\n", "df" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:22.796355Z", "iopub.status.busy": "2021-07-16T22:28:22.795776Z", "iopub.status.idle": "2021-07-16T22:28:22.896513Z", "shell.execute_reply": "2021-07-16T22:28:22.896885Z" } }, "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", "
fabcde
<object><int64><int64><int64><object><object>
0a111aa
\n", "
\n" ], "text/plain": [ " f a b c d e\n", " \n", "0 a 1 1 1 a a" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> relocate(f.f)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:22.910066Z", "iopub.status.busy": "2021-07-16T22:28:22.909405Z", "iopub.status.idle": "2021-07-16T22:28:22.912880Z", "shell.execute_reply": "2021-07-16T22:28:22.912375Z" } }, "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", "
bcadef
<int64><int64><int64><object><object><object>
0111aaa
\n", "
\n" ], "text/plain": [ " b c a d e f\n", " \n", "0 1 1 1 a a a" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> relocate(f.a, _after = f.c)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:22.926072Z", "iopub.status.busy": "2021-07-16T22:28:22.925379Z", "iopub.status.idle": "2021-07-16T22:28:22.928115Z", "shell.execute_reply": "2021-07-16T22:28:22.928506Z" } }, "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", "
afbcde
<int64><object><int64><int64><object><object>
01a11aa
\n", "
\n" ], "text/plain": [ " a f b c d e\n", " \n", "0 1 a 1 1 a a" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> relocate(f.f, _before = f.b)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:22.943207Z", "iopub.status.busy": "2021-07-16T22:28:22.942267Z", "iopub.status.idle": "2021-07-16T22:28:22.946422Z", "shell.execute_reply": "2021-07-16T22:28:22.946819Z" } }, "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", "
bcdefa
<int64><int64><object><object><object><int64>
011aaa1
\n", "
\n" ], "text/plain": [ " b c d e f a\n", " \n", "0 1 1 a a a 1" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> relocate(f.a, _after = last_col())" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:22.955752Z", "iopub.status.busy": "2021-07-16T22:28:22.955048Z", "iopub.status.idle": "2021-07-16T22:28:22.964921Z", "shell.execute_reply": "2021-07-16T22:28:22.964476Z" } }, "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", "
ffabcde
<object><int64><int64><int64><object><object>
0a111aa
\n", "
\n" ], "text/plain": [ " ff a b c d e\n", " \n", "0 a 1 1 1 a a" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> relocate(ff=f.f)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:22.971451Z", "iopub.status.busy": "2021-07-16T22:28:22.970885Z", "iopub.status.idle": "2021-07-16T22:28:23.001622Z", "shell.execute_reply": "2021-07-16T22:28:23.002195Z" } }, "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", "
defabc
<object><object><object><int64><int64><int64>
0aaa111
\n", "
\n" ], "text/plain": [ " d e f a b c\n", " \n", "0 a a a 1 1 1" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> relocate(where(is_character))" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:23.018946Z", "iopub.status.busy": "2021-07-16T22:28:23.017664Z", "iopub.status.idle": "2021-07-16T22:28:23.022865Z", "shell.execute_reply": "2021-07-16T22:28:23.022420Z" } }, "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", "
defabc
<object><object><object><int64><int64><int64>
0aaa111
\n", "
\n" ], "text/plain": [ " d e f a b c\n", " \n", "0 a a a 1 1 1" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> relocate(where(is_numeric), _after = last_col())" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:23.041431Z", "iopub.status.busy": "2021-07-16T22:28:23.040645Z", "iopub.status.idle": "2021-07-16T22:28:23.044616Z", "shell.execute_reply": "2021-07-16T22:28:23.045079Z" } }, "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", "
aebcdf
<int64><object><int64><int64><object><object>
01a11aa
\n", "
\n" ], "text/plain": [ " a e b c d f\n", " \n", "0 1 a 1 1 a a" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> relocate(any_of(c(\"a\", \"e\", \"i\", \"o\", \"u\")))" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:23.049926Z", "iopub.status.busy": "2021-07-16T22:28:23.049342Z", "iopub.status.idle": "2021-07-16T22:28:23.072350Z", "shell.execute_reply": "2021-07-16T22:28:23.072760Z" } }, "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", "
abcd
<int64><object><int64><object>
01a1a
\n", "
\n" ], "text/plain": [ " a b c d\n", " \n", "0 1 a 1 a" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df2 = tibble(a=1, b='a', c=1, d='a')\n", "df2" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:23.090464Z", "iopub.status.busy": "2021-07-16T22:28:23.089707Z", "iopub.status.idle": "2021-07-16T22:28:23.094341Z", "shell.execute_reply": "2021-07-16T22:28:23.093807Z" } }, "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", "
bdac
<object><object><int64><int64>
0aa11
\n", "
\n" ], "text/plain": [ " b d a c\n", " \n", "0 a a 1 1" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df2 >> relocate(where(is_numeric), _after = where(is_character))" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:23.110338Z", "iopub.status.busy": "2021-07-16T22:28:23.109601Z", "iopub.status.idle": "2021-07-16T22:28:23.113543Z", "shell.execute_reply": "2021-07-16T22:28:23.112915Z" } }, "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", "
acbd
<int64><int64><object><object>
011aa
\n", "
\n" ], "text/plain": [ " a c b d\n", " \n", "0 1 1 a a" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df2 >> relocate(where(is_numeric), _before = where(is_character))" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:23.127291Z", "iopub.status.busy": "2021-07-16T22:28:23.126686Z", "iopub.status.idle": "2021-07-16T22:28:23.129514Z", "shell.execute_reply": "2021-07-16T22:28:23.130106Z" } }, "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", "
abdc
<int64><object><object><int64>
01aa1
\n", "
\n" ], "text/plain": [ " a b d c\n", " \n", "0 1 a a 1" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df2 >> relocate(f.d, _after=1)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 4 } ================================================ FILE: docs/notebooks/rename.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "1dec8f90", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:06.479313Z", "iopub.status.busy": "2021-07-16T22:28:06.478179Z", "iopub.status.idle": "2021-07-16T22:28:07.420124Z", "shell.execute_reply": "2021-07-16T22:28:07.420518Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ rename
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Rename columns\n", "\n", "See original API \n", "https://dplyr.tidyverse.org/reference/rename.html \n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `**kwargs`: Columns to rename \n", "\n", "##### Returns:\n", "  The dataframe with new names \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ rename_with
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Rename columns with a function\n", "\n", "See original API \n", "https://dplyr.tidyverse.org/reference/rename.html \n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `_fn`: A function to apply to column names \n", "  `*args`: the columns to rename and non-keyword arguments for the `_fn`. \n", "    If `*args` is not provided, then assuming all columns, and \n", "    no non-keyword arguments are allowed to pass to the function, use \n", "    keyword arguments instead. \n", "\n", "  `**kwargs`: keyword arguments for `_fn` \n", "\n", "##### Returns:\n", "  The dataframe with new names \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/rename.html\n", "%run nb_helpers.py\n", "\n", "from datar.data import iris\n", "from datar.all import *\n", "\n", "nb_header(rename, rename_with)" ] }, { "cell_type": "code", "execution_count": 2, "id": "36bdaa38", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:07.526873Z", "iopub.status.busy": "2021-07-16T22:28:07.526038Z", "iopub.status.idle": "2021-07-16T22:28:07.575744Z", "shell.execute_reply": "2021-07-16T22:28:07.576170Z" } }, "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", "
Sepal_LengthSepal_Widthpetal_lengthPetal_WidthSpecies
<float64><float64><float64><float64><object>
05.13.51.40.2setosa
14.93.01.40.2setosa
24.73.21.30.2setosa
34.63.11.50.2setosa
..................
45.03.61.40.2setosa
1456.73.05.22.3virginica
1466.32.55.01.9virginica
1476.53.05.22.0virginica
1486.23.45.42.3virginica
1495.93.05.11.8virginica
\n", "

150 rows × 5 columns

\n", "
\n" ], "text/plain": [ " Sepal_Length Sepal_Width petal_length Petal_Width Species\n", " \n", "0 5.1 3.5 1.4 0.2 setosa\n", "1 4.9 3.0 1.4 0.2 setosa\n", "2 4.7 3.2 1.3 0.2 setosa\n", "3 4.6 3.1 1.5 0.2 setosa\n", ".. ... ... ... ... ...\n", "4 5.0 3.6 1.4 0.2 setosa\n", "145 6.7 3.0 5.2 2.3 virginica\n", "146 6.3 2.5 5.0 1.9 virginica\n", "147 6.5 3.0 5.2 2.0 virginica\n", "148 6.2 3.4 5.4 2.3 virginica\n", "149 5.9 3.0 5.1 1.8 virginica\n", "\n", "[150 rows x 5 columns]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rename(iris, petal_length='Petal_Length')" ] }, { "cell_type": "code", "execution_count": 3, "id": "a176778e", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:07.621858Z", "iopub.status.busy": "2021-07-16T22:28:07.620916Z", "iopub.status.idle": "2021-07-16T22:28:07.637453Z", "shell.execute_reply": "2021-07-16T22:28:07.637898Z" } }, "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", "
SEPAL_LENGTHSEPAL_WIDTHPETAL_LENGTHPETAL_WIDTHSPECIES
<float64><float64><float64><float64><object>
05.13.51.40.2setosa
14.93.01.40.2setosa
24.73.21.30.2setosa
34.63.11.50.2setosa
..................
45.03.61.40.2setosa
1456.73.05.22.3virginica
1466.32.55.01.9virginica
1476.53.05.22.0virginica
1486.23.45.42.3virginica
1495.93.05.11.8virginica
\n", "

150 rows × 5 columns

\n", "
\n" ], "text/plain": [ " SEPAL_LENGTH SEPAL_WIDTH PETAL_LENGTH PETAL_WIDTH SPECIES\n", " \n", "0 5.1 3.5 1.4 0.2 setosa\n", "1 4.9 3.0 1.4 0.2 setosa\n", "2 4.7 3.2 1.3 0.2 setosa\n", "3 4.6 3.1 1.5 0.2 setosa\n", ".. ... ... ... ... ...\n", "4 5.0 3.6 1.4 0.2 setosa\n", "145 6.7 3.0 5.2 2.3 virginica\n", "146 6.3 2.5 5.0 1.9 virginica\n", "147 6.5 3.0 5.2 2.0 virginica\n", "148 6.2 3.4 5.4 2.3 virginica\n", "149 5.9 3.0 5.1 1.8 virginica\n", "\n", "[150 rows x 5 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rename_with(iris, str.upper)" ] }, { "cell_type": "code", "execution_count": 4, "id": "e61348e4", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:07.675212Z", "iopub.status.busy": "2021-07-16T22:28:07.673704Z", "iopub.status.idle": "2021-07-16T22:28:07.686307Z", "shell.execute_reply": "2021-07-16T22:28:07.686788Z" } }, "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", "
Sepal_LengthSepal_WidthPETAL_LENGTHPETAL_WIDTHSpecies
<float64><float64><float64><float64><object>
05.13.51.40.2setosa
14.93.01.40.2setosa
24.73.21.30.2setosa
34.63.11.50.2setosa
..................
45.03.61.40.2setosa
1456.73.05.22.3virginica
1466.32.55.01.9virginica
1476.53.05.22.0virginica
1486.23.45.42.3virginica
1495.93.05.11.8virginica
\n", "

150 rows × 5 columns

\n", "
\n" ], "text/plain": [ " Sepal_Length Sepal_Width PETAL_LENGTH PETAL_WIDTH Species\n", " \n", "0 5.1 3.5 1.4 0.2 setosa\n", "1 4.9 3.0 1.4 0.2 setosa\n", "2 4.7 3.2 1.3 0.2 setosa\n", "3 4.6 3.1 1.5 0.2 setosa\n", ".. ... ... ... ... ...\n", "4 5.0 3.6 1.4 0.2 setosa\n", "145 6.7 3.0 5.2 2.3 virginica\n", "146 6.3 2.5 5.0 1.9 virginica\n", "147 6.5 3.0 5.2 2.0 virginica\n", "148 6.2 3.4 5.4 2.3 virginica\n", "149 5.9 3.0 5.1 1.8 virginica\n", "\n", "[150 rows x 5 columns]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> rename_with(str.upper, starts_with(\"Petal\"))" ] }, { "cell_type": "code", "execution_count": 5, "id": "57f026b4", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:07.717434Z", "iopub.status.busy": "2021-07-16T22:28:07.716756Z", "iopub.status.idle": "2021-07-16T22:28:07.726286Z", "shell.execute_reply": "2021-07-16T22:28:07.726840Z" } }, "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", "
sepal.lengthsepal.widthpetal.lengthpetal.widthspecies
<float64><float64><float64><float64><object>
05.13.51.40.2setosa
14.93.01.40.2setosa
24.73.21.30.2setosa
34.63.11.50.2setosa
..................
45.03.61.40.2setosa
1456.73.05.22.3virginica
1466.32.55.01.9virginica
1476.53.05.22.0virginica
1486.23.45.42.3virginica
1495.93.05.11.8virginica
\n", "

150 rows × 5 columns

\n", "
\n" ], "text/plain": [ " sepal.length sepal.width petal.length petal.width species\n", " \n", "0 5.1 3.5 1.4 0.2 setosa\n", "1 4.9 3.0 1.4 0.2 setosa\n", "2 4.7 3.2 1.3 0.2 setosa\n", "3 4.6 3.1 1.5 0.2 setosa\n", ".. ... ... ... ... ...\n", "4 5.0 3.6 1.4 0.2 setosa\n", "145 6.7 3.0 5.2 2.3 virginica\n", "146 6.3 2.5 5.0 1.9 virginica\n", "147 6.5 3.0 5.2 2.0 virginica\n", "148 6.2 3.4 5.4 2.3 virginica\n", "149 5.9 3.0 5.1 1.8 virginica\n", "\n", "[150 rows x 5 columns]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> rename_with(lambda x: x.replace('_', '.').lower())" ] }, { "cell_type": "code", "execution_count": 6, "id": "f9cee963", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:07.750098Z", "iopub.status.busy": "2021-07-16T22:28:07.749436Z", "iopub.status.idle": "2021-07-16T22:28:07.766596Z", "shell.execute_reply": "2021-07-16T22:28:07.767206Z" } }, "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", "
Sepal_LengthSepal_WidthPetal_LengthPetal_WidthSp
<float64><float64><float64><float64><object>
05.13.51.40.2setosa
14.93.01.40.2setosa
24.73.21.30.2setosa
34.63.11.50.2setosa
..................
45.03.61.40.2setosa
1456.73.05.22.3virginica
1466.32.55.01.9virginica
1476.53.05.22.0virginica
1486.23.45.42.3virginica
1495.93.05.11.8virginica
\n", "

150 rows × 5 columns

\n", "
\n" ], "text/plain": [ " Sepal_Length Sepal_Width Petal_Length Petal_Width Sp\n", " \n", "0 5.1 3.5 1.4 0.2 setosa\n", "1 4.9 3.0 1.4 0.2 setosa\n", "2 4.7 3.2 1.3 0.2 setosa\n", "3 4.6 3.1 1.5 0.2 setosa\n", ".. ... ... ... ... ...\n", "4 5.0 3.6 1.4 0.2 setosa\n", "145 6.7 3.0 5.2 2.3 virginica\n", "146 6.3 2.5 5.0 1.9 virginica\n", "147 6.5 3.0 5.2 2.0 virginica\n", "148 6.2 3.4 5.4 2.3 virginica\n", "149 5.9 3.0 5.1 1.8 virginica\n", "\n", "[150 rows x 5 columns]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# names can be selected by indexes\n", "iris >> rename(Sp=4)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/replace_na.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "82eadf3d", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:37.957391Z", "iopub.status.busy": "2021-07-16T22:27:37.956741Z", "iopub.status.idle": "2021-07-16T22:27:38.779988Z", "shell.execute_reply": "2021-07-16T22:27:38.780414Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ replace_na
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Replace NA with a value\n", "\n", "This function can be also used not as a verb. As a function called as \n", "an argument in a verb, data is passed implicitly. Then one could \n", "pass data_or_replace as the data to replace. \n", "\n", "##### Args:\n", "  `data`: The data piped in \n", "  `data_or_replace`: When called as argument of a verb, this is the \n", "    data to replace. Otherwise this is the replacement. \n", "\n", "  `replace`: The value to replace with \n", "    Can only be a scalar or dict for data frame. \n", "    So replace NA with a list is not supported yet. \n", "\n", "##### Returns:\n", "  Corresponding data with NAs replaced \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://tidyr.tidyverse.org/reference/replace_na.html\n", "%run nb_helpers.py\n", "\n", "from datar.all import *\n", "\n", "nb_header(replace_na)" ] }, { "cell_type": "code", "execution_count": 2, "id": "4579e780", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:38.790243Z", "iopub.status.busy": "2021-07-16T22:27:38.789604Z", "iopub.status.idle": "2021-07-16T22:27:38.927028Z", "shell.execute_reply": "2021-07-16T22:27:38.927430Z" } }, "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", "
xy
<float64><object>
01.0a
12.0unknown
20.0b
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 1.0 a\n", "1 2.0 unknown\n", "2 0.0 b" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x = c(1, 2, NA), y = c(\"a\", NA, \"b\"))\n", "df >> replace_na(dict(x = 0, y = \"unknown\"))" ] }, { "cell_type": "code", "execution_count": 3, "id": "93218909", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:38.958579Z", "iopub.status.busy": "2021-07-16T22:27:38.937640Z", "iopub.status.idle": "2021-07-16T22:27:38.961801Z", "shell.execute_reply": "2021-07-16T22:27:38.962293Z" } }, "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", "
xy
<float64><object>
01.0a
12.0NaN
20.0b
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 1.0 a\n", "1 2.0 NaN\n", "2 0.0 b" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> mutate(x = replace_na(f.x, 0))" ] }, { "cell_type": "code", "execution_count": 4, "id": "1c89dd6f", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:38.972568Z", "iopub.status.busy": "2021-07-16T22:27:38.971323Z", "iopub.status.idle": "2021-07-16T22:27:38.978260Z", "shell.execute_reply": "2021-07-16T22:27:38.977575Z" } }, "outputs": [ { "data": { "text/plain": [ "0 1.0\n", "1 2.0\n", "2 0.0\n", "Name: x, dtype: float64" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.x >> replace_na(0)" ] }, { "cell_type": "code", "execution_count": 5, "id": "1a09cddb", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:38.985981Z", "iopub.status.busy": "2021-07-16T22:27:38.985058Z", "iopub.status.idle": "2021-07-16T22:27:38.992882Z", "shell.execute_reply": "2021-07-16T22:27:38.993383Z" } }, "outputs": [ { "data": { "text/plain": [ "0 a\n", "1 unknown\n", "2 b\n", "Name: y, dtype: object" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.y >> replace_na(\"unknown\")" ] }, { "cell_type": "code", "execution_count": 6, "id": "e31ed3fa", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:39.001429Z", "iopub.status.busy": "2021-07-16T22:27:39.000841Z", "iopub.status.idle": "2021-07-16T22:27:39.022168Z", "shell.execute_reply": "2021-07-16T22:27:39.021142Z" } }, "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", "
z
<object>
0[1, 2, 3, 4, 5]
15
2[10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
\n", "
\n" ], "text/plain": [ " z\n", " \n", "0 [1, 2, 3, 4, 5]\n", "1 5\n", "2 [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_list = tibble(z = [seq(1,5), NULL, seq(10,20)])\n", "df_list >> replace_na({'z': 5}) # replace with a list not supported yet" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/rownames.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:24.723831Z", "iopub.status.busy": "2021-07-16T22:27:24.723166Z", "iopub.status.idle": "2021-07-16T22:27:27.091401Z", "shell.execute_reply": "2021-07-16T22:27:27.091877Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ has_rownames
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Detect if a data frame has row names\n", "\n", "Aliases `has_index` \n", "\n", "##### Args:\n", "  `_data`: The data frame to check \n", "\n", "##### Returns:\n", "  True if the data frame has index otherwise False. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ remove_rownames
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Remove the index/rownames of a data frame\n", "\n", "Aliases `remove_index`, `drop_index`, `remove_rownames` \n", "\n", "##### Args:\n", "  `_data`: The data frame \n", "\n", "##### Returns:\n", "  The data frame with index removed \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ rownames_to_column
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Add rownames as a column\n", "\n", "Aliases `index_to_column` \n", "\n", "##### Args:\n", "  `_data`: The data frame \n", "  `var`: The name of the column \n", "\n", "##### Returns:\n", "  The data frame with rownames added as one column. Note that the \n", "  original index is removed. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ rowid_to_column
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Add rownames as a column\n", "\n", "##### Args:\n", "  `_data`: The data frame \n", "  `var`: The name of the column \n", "\n", "##### Returns:\n", "  The data frame with row ids added as one column. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ column_to_rownames
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Set rownames/index with one column, and remove it\n", "\n", "Aliases `column_to_index` \n", "\n", "##### Args:\n", "  `_data`: The data frame \n", "  `var`: The column to conver to the rownames \n", "\n", "##### Returns:\n", "  The data frame with the column converted to rownames \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://tibble.tidyverse.org/reference/add_row.html\n", "%run nb_helpers.py\n", "\n", "from datar.tibble import *\n", "from datar.base import head\n", "from datar.data import mtcars, iris\n", "\n", "nb_header(has_rownames, remove_rownames, rownames_to_column, rowid_to_column, column_to_rownames, book='rownames')" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:27.100163Z", "iopub.status.busy": "2021-07-16T22:27:27.099438Z", "iopub.status.idle": "2021-07-16T22:27:27.104815Z", "shell.execute_reply": "2021-07-16T22:27:27.105311Z" } }, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "has_rownames(mtcars)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:27.111548Z", "iopub.status.busy": "2021-07-16T22:27:27.110098Z", "iopub.status.idle": "2021-07-16T22:27:27.116011Z", "shell.execute_reply": "2021-07-16T22:27:27.116393Z" } }, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "has_rownames(iris)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:27.125381Z", "iopub.status.busy": "2021-07-16T22:27:27.124718Z", "iopub.status.idle": "2021-07-16T22:27:27.130194Z", "shell.execute_reply": "2021-07-16T22:27:27.129526Z" } }, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "remove_rownames(mtcars) >> has_rownames()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:27.135636Z", "iopub.status.busy": "2021-07-16T22:27:27.135017Z", "iopub.status.idle": "2021-07-16T22:27:27.340681Z", "shell.execute_reply": "2021-07-16T22:27:27.341035Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
mpgcarcyldisphpdratwtqsecvsamgearcarb
<float64><object><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
021.0Mazda RX46160.01103.902.62016.460144
121.0Mazda RX4 Wag6160.01103.902.87517.020144
222.8Datsun 7104108.0933.852.32018.611141
321.4Hornet 4 Drive6258.01103.083.21519.441031
418.7Hornet Sportabout8360.01753.153.44017.020032
518.1Valiant6225.01052.763.46020.221031
614.3Duster 3608360.02453.213.57015.840034
724.4Merc 240D4146.7623.693.19020.001042
822.8Merc 2304140.8953.923.15022.901042
919.2Merc 2806167.61233.923.44018.301044
1017.8Merc 280C6167.61233.923.44018.901044
1116.4Merc 450SE8275.81803.074.07017.400033
1217.3Merc 450SL8275.81803.073.73017.600033
1315.2Merc 450SLC8275.81803.073.78018.000033
1410.4Cadillac Fleetwood8472.02052.935.25017.980034
1510.4Lincoln Continental8460.02153.005.42417.820034
1614.7Chrysler Imperial8440.02303.235.34517.420034
1732.4Fiat 128478.7664.082.20019.471141
1830.4Honda Civic475.7524.931.61518.521142
1933.9Toyota Corolla471.1654.221.83519.901141
2021.5Toyota Corona4120.1973.702.46520.011031
2115.5Dodge Challenger8318.01502.763.52016.870032
2215.2AMC Javelin8304.01503.153.43517.300032
2313.3Camaro Z288350.02453.733.84015.410034
2419.2Pontiac Firebird8400.01753.083.84517.050032
2527.3Fiat X1-9479.0664.081.93518.901141
2626.0Porsche 914-24120.3914.432.14016.700152
2730.4Lotus Europa495.11133.771.51316.901152
2815.8Ford Pantera L8351.02644.223.17014.500154
2919.7Ferrari Dino6145.01753.622.77015.500156
3015.0Maserati Bora8301.03353.543.57014.600158
3121.4Volvo 142E4121.01094.112.78018.601142
\n", "
\n" ], "text/plain": [ " mpg car cyl disp hp drat \\\n", " \n", "0 21.0 Mazda RX4 6 160.0 110 3.90 \n", "1 21.0 Mazda RX4 Wag 6 160.0 110 3.90 \n", "2 22.8 Datsun 710 4 108.0 93 3.85 \n", "3 21.4 Hornet 4 Drive 6 258.0 110 3.08 \n", "4 18.7 Hornet Sportabout 8 360.0 175 3.15 \n", "5 18.1 Valiant 6 225.0 105 2.76 \n", "6 14.3 Duster 360 8 360.0 245 3.21 \n", "7 24.4 Merc 240D 4 146.7 62 3.69 \n", "8 22.8 Merc 230 4 140.8 95 3.92 \n", "9 19.2 Merc 280 6 167.6 123 3.92 \n", "10 17.8 Merc 280C 6 167.6 123 3.92 \n", "11 16.4 Merc 450SE 8 275.8 180 3.07 \n", "12 17.3 Merc 450SL 8 275.8 180 3.07 \n", "13 15.2 Merc 450SLC 8 275.8 180 3.07 \n", "14 10.4 Cadillac Fleetwood 8 472.0 205 2.93 \n", "15 10.4 Lincoln Continental 8 460.0 215 3.00 \n", "16 14.7 Chrysler Imperial 8 440.0 230 3.23 \n", "17 32.4 Fiat 128 4 78.7 66 4.08 \n", "18 30.4 Honda Civic 4 75.7 52 4.93 \n", "19 33.9 Toyota Corolla 4 71.1 65 4.22 \n", "20 21.5 Toyota Corona 4 120.1 97 3.70 \n", "21 15.5 Dodge Challenger 8 318.0 150 2.76 \n", "22 15.2 AMC Javelin 8 304.0 150 3.15 \n", "23 13.3 Camaro Z28 8 350.0 245 3.73 \n", "24 19.2 Pontiac Firebird 8 400.0 175 3.08 \n", "25 27.3 Fiat X1-9 4 79.0 66 4.08 \n", "26 26.0 Porsche 914-2 4 120.3 91 4.43 \n", "27 30.4 Lotus Europa 4 95.1 113 3.77 \n", "28 15.8 Ford Pantera L 8 351.0 264 4.22 \n", "29 19.7 Ferrari Dino 6 145.0 175 3.62 \n", "30 15.0 Maserati Bora 8 301.0 335 3.54 \n", "31 21.4 Volvo 142E 4 121.0 109 4.11 \n", "\n", " wt qsec vs am gear carb \n", " \n", "0 2.620 16.46 0 1 4 4 \n", "1 2.875 17.02 0 1 4 4 \n", "2 2.320 18.61 1 1 4 1 \n", "3 3.215 19.44 1 0 3 1 \n", "4 3.440 17.02 0 0 3 2 \n", "5 3.460 20.22 1 0 3 1 \n", "6 3.570 15.84 0 0 3 4 \n", "7 3.190 20.00 1 0 4 2 \n", "8 3.150 22.90 1 0 4 2 \n", "9 3.440 18.30 1 0 4 4 \n", "10 3.440 18.90 1 0 4 4 \n", "11 4.070 17.40 0 0 3 3 \n", "12 3.730 17.60 0 0 3 3 \n", "13 3.780 18.00 0 0 3 3 \n", "14 5.250 17.98 0 0 3 4 \n", "15 5.424 17.82 0 0 3 4 \n", "16 5.345 17.42 0 0 3 4 \n", "17 2.200 19.47 1 1 4 1 \n", "18 1.615 18.52 1 1 4 2 \n", "19 1.835 19.90 1 1 4 1 \n", "20 2.465 20.01 1 0 3 1 \n", "21 3.520 16.87 0 0 3 2 \n", "22 3.435 17.30 0 0 3 2 \n", "23 3.840 15.41 0 0 3 4 \n", "24 3.845 17.05 0 0 3 2 \n", "25 1.935 18.90 1 1 4 1 \n", "26 2.140 16.70 0 1 5 2 \n", "27 1.513 16.90 1 1 5 2 \n", "28 3.170 14.50 0 1 5 4 \n", "29 2.770 15.50 0 1 5 6 \n", "30 3.570 14.60 0 1 5 8 \n", "31 2.780 18.60 1 1 4 2 " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars_tbl = rownames_to_column(mtcars, var=\"car\") \n", "mtcars_tbl" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:27.372381Z", "iopub.status.busy": "2021-07-16T22:27:27.371864Z", "iopub.status.idle": "2021-07-16T22:27:27.377366Z", "shell.execute_reply": "2021-07-16T22:27:27.379492Z" } }, "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", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Mazda RX421.06160.01103.902.62016.460144
Mazda RX4 Wag21.06160.01103.902.87517.020144
Datsun 71022.84108.0933.852.32018.611141
Hornet 4 Drive21.46258.01103.083.21519.441031
Hornet Sportabout18.78360.01753.153.44017.020032
Valiant18.16225.01052.763.46020.221031
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt \\\n", " \n", "Mazda RX4 21.0 6 160.0 110 3.90 2.620 \n", "Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 \n", "Datsun 710 22.8 4 108.0 93 3.85 2.320 \n", "Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 \n", "Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 \n", "Valiant 18.1 6 225.0 105 2.76 3.460 \n", "\n", " qsec vs am gear carb \n", " \n", "Mazda RX4 16.46 0 1 4 4 \n", "Mazda RX4 Wag 17.02 0 1 4 4 \n", "Datsun 710 18.61 1 1 4 1 \n", "Hornet 4 Drive 19.44 1 0 3 1 \n", "Hornet Sportabout 17.02 0 0 3 2 \n", "Valiant 20.22 1 0 3 1 " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "column_to_rownames(mtcars_tbl, var = \"car\") >> head()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:27.415514Z", "iopub.status.busy": "2021-07-16T22:27:27.414987Z", "iopub.status.idle": "2021-07-16T22:27:27.421179Z", "shell.execute_reply": "2021-07-16T22:27:27.421552Z" } }, "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", "
Sepal_LengthrowidSepal_WidthPetal_LengthPetal_WidthSpecies
<float64><int64><float64><float64><float64><object>
05.103.51.40.2setosa
14.913.01.40.2setosa
24.723.21.30.2setosa
34.633.11.50.2setosa
45.043.61.40.2setosa
55.453.91.70.4setosa
\n", "
\n" ], "text/plain": [ " Sepal_Length rowid Sepal_Width Petal_Length Petal_Width Species\n", " \n", "0 5.1 0 3.5 1.4 0.2 setosa\n", "1 4.9 1 3.0 1.4 0.2 setosa\n", "2 4.7 2 3.2 1.3 0.2 setosa\n", "3 4.6 3 3.1 1.5 0.2 setosa\n", "4 5.0 4 3.6 1.4 0.2 setosa\n", "5 5.4 5 3.9 1.7 0.4 setosa" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Adding rowid as a column --------------------------------------------\n", "rowid_to_column(iris) >> head()" ] } ], "metadata": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" }, "kernelspec": { "display_name": "Python 3.7.8 64-bit ('base': conda)", "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.9.5" } }, "nbformat": 4, "nbformat_minor": 2 } ================================================ FILE: docs/notebooks/rows.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:10.915581Z", "iopub.status.busy": "2021-07-16T22:28:10.913314Z", "iopub.status.idle": "2021-07-16T22:28:11.982697Z", "shell.execute_reply": "2021-07-16T22:28:11.983123Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ rows_insert
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Insert rows from y into x\n", "\n", "See original API \n", "https://dplyr.tidyverse.org/reference/rows.html \n", "\n", "##### Args:\n", "  `x`: A data frame \n", "  `y`: A data frame \n", "  `by`: An unnamed character vector giving the key columns. \n", "    The key columns must exist in both x and y. \n", "    Keys typically uniquely identify each row, but this is only \n", "    enforced for the key values of y \n", "    By default, we use the first column in y, since the first column is \n", "    a reasonable place to put an identifier variable. \n", "\n", "  `conflict`: How to handle conflicts \n", "    - \"error\": Throw an error\n", "\n", "    - \"ignore\": Ignore conflicts\n", "\n", "  `copy`: If x and y are not from the same data source, and copy is TRUE, \n", "    then y will be copied into the same src as x. \n", "    This allows you to join tables across srcs, but it is a potentially \n", "    expensive operation so you must opt into it. \n", "\n", "  `in_place`: Should x be modified in place? \n", "    This may not be supported, depending on the backend implementation. \n", "\n", "##### Returns:\n", "  A data frame with all existing rows and potentially new rows \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ rows_update
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Update rows in x with values from y\n", "\n", "See original API \n", "https://dplyr.tidyverse.org/reference/rows.html \n", "\n", "##### Args:\n", "  `x`: A data frame \n", "  `y`: A data frame \n", "  `by`: An unnamed character vector giving the key columns. \n", "    The key columns must exist in both x and y. \n", "    Keys typically uniquely identify each row, but this is only \n", "    enforced for the key values of y \n", "    By default, we use the first column in y, since the first column is \n", "    a reasonable place to put an identifier variable. \n", "\n", "  `unmatched`: how should keys in y that are unmatched by the keys \n", "    in x be handled? \n", "    One of - \n", "    \"error\", the default, will error if there are any keys in y that \n", "    are unmatched by the keys in x. \n", "    \"ignore\" will ignore rows in y with keys that are unmatched \n", "    by the keys in x. \n", "\n", "  `copy`: If x and y are not from the same data source, and copy is TRUE, \n", "    then y will be copied into the same src as x. \n", "    This allows you to join tables across srcs, but it is a potentially \n", "    expensive operation so you must opt into it. \n", "\n", "  `in_place`: Should x be modified in place? \n", "    This may not be supported, depending on the backend implementation. \n", "\n", "##### Returns:\n", "  A data frame with all existing rows and potentially new rows \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ rows_patch
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Patch rows in x with values from y\n", "\n", "See original API \n", "https://dplyr.tidyverse.org/reference/rows.html \n", "\n", "##### Args:\n", "  `x`: A data frame \n", "  `y`: A data frame \n", "  `by`: An unnamed character vector giving the key columns. \n", "    The key columns must exist in both x and y. \n", "    Keys typically uniquely identify each row, but this is only \n", "    enforced for the key values of y \n", "    By default, we use the first column in y, since the first column is \n", "    a reasonable place to put an identifier variable. \n", "\n", "  `unmatched`: how should keys in y that are unmatched by the keys \n", "    in x be handled? \n", "    One of - \n", "    \"error\", the default, will error if there are any keys in y that \n", "    are unmatched by the keys in x. \n", "    \"ignore\" will ignore rows in y with keys that are unmatched \n", "    by the keys in x. \n", "\n", "  `copy`: If x and y are not from the same data source, and copy is TRUE, \n", "    then y will be copied into the same src as x. \n", "    This allows you to join tables across srcs, but it is a potentially \n", "    expensive operation so you must opt into it. \n", "\n", "  `in_place`: Should x be modified in place? \n", "    This may not be supported, depending on the backend implementation. \n", "\n", "##### Returns:\n", "  A data frame with NA values overwritten and the number of rows preserved \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ rows_upsert
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Upsert rows in x with values from y\n", "\n", "See original API \n", "https://dplyr.tidyverse.org/reference/rows.html \n", "\n", "##### Args:\n", "  `x`: A data frame \n", "  `y`: A data frame \n", "  `by`: An unnamed character vector giving the key columns. \n", "    The key columns must exist in both x and y. \n", "    Keys typically uniquely identify each row, but this is only \n", "    enforced for the key values of y \n", "    By default, we use the first column in y, since the first column is \n", "    a reasonable place to put an identifier variable. \n", "\n", "  `copy`: If x and y are not from the same data source, and copy is TRUE, \n", "    then y will be copied into the same src as x. \n", "    This allows you to join tables across srcs, but it is a potentially \n", "    expensive operation so you must opt into it. \n", "\n", "  `in_place`: Should x be modified in place? \n", "    This may not be supported, depending on the backend implementation. \n", "\n", "##### Returns:\n", "  A data frame with inserted or updated depending on whether or not \n", "  the key value in y already exists in x. Key values in y must be unique. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ rows_delete
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Delete rows in x that match keys in y\n", "\n", "See original API \n", "https://dplyr.tidyverse.org/reference/rows.html \n", "\n", "##### Args:\n", "  `x`: A data frame \n", "  `y`: A data frame \n", "  `by`: An unnamed character vector giving the key columns. \n", "    The key columns must exist in both x and y. \n", "    Keys typically uniquely identify each row, but this is only \n", "    enforced for the key values of y \n", "    By default, we use the first column in y, since the first column is \n", "    a reasonable place to put an identifier variable. \n", "\n", "  `unmatched`: how should keys in y that are unmatched by the keys \n", "    in x be handled? \n", "    One of - \n", "    \"error\", the default, will error if there are any keys in y that \n", "    are unmatched by the keys in x. \n", "    \"ignore\" will ignore rows in y with keys that are unmatched \n", "    by the keys in x. \n", "\n", "  `copy`: If x and y are not from the same data source, and copy is TRUE, \n", "    then y will be copied into the same src as x. \n", "    This allows you to join tables across srcs, but it is a potentially \n", "    expensive operation so you must opt into it. \n", "\n", "  `in_place`: Should x be modified in place? \n", "    This may not be supported, depending on the backend implementation. \n", "\n", "##### Returns:\n", "  A data frame with rows deleted \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%run nb_helpers.py\n", "from datar.all import *\n", "\n", "nb_header(\n", " rows_insert, \n", " rows_update, \n", " rows_patch, \n", " rows_upsert, \n", " rows_delete, \n", " book='rows'\n", ")" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:11.999613Z", "iopub.status.busy": "2021-07-16T22:28:11.998991Z", "iopub.status.idle": "2021-07-16T22:28:12.347691Z", "shell.execute_reply": "2021-07-16T22:28:12.348096Z" } }, "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", "
abc
<int64><object><float64>
01a0.5
12b1.5
23NaN2.5
\n", "
\n" ], "text/plain": [ " a b c\n", " \n", "0 1 a 0.5\n", "1 2 b 1.5\n", "2 3 NaN 2.5" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = tibble(a = seq(1, 3), b = c(letters[[0, 1]], NA), c = [.5, 1.5, 2.5])\n", "data" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:12.450878Z", "iopub.status.busy": "2021-07-16T22:28:12.449990Z", "iopub.status.idle": "2021-07-16T22:28:12.756575Z", "shell.execute_reply": "2021-07-16T22:28:12.757071Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 14:22:14][datar][ INFO] Matching, by='a'\n" ] }, { "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", "
abc
<int64><object><float64>
01a0.5
12b1.5
23NaN2.5
34zNaN
\n", "
\n" ], "text/plain": [ " a b c\n", " \n", "0 1 a 0.5\n", "1 2 b 1.5\n", "2 3 NaN 2.5\n", "3 4 z NaN" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rows_insert(data, tibble(a = 4, b = \"z\"))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:12.778078Z", "iopub.status.busy": "2021-07-16T22:28:12.776324Z", "iopub.status.idle": "2021-07-16T22:28:12.809105Z", "shell.execute_reply": "2021-07-16T22:28:12.809525Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 14:22:14][datar][ INFO] Matching, by='a'\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "[ValueError] Attempting to insert duplicate rows.\n" ] } ], "source": [ "with try_catch():\n", " rows_insert(data, tibble(a = 3, b = \"z\"))" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:12.849701Z", "iopub.status.busy": "2021-07-16T22:28:12.849124Z", "iopub.status.idle": "2021-07-16T22:28:12.882173Z", "shell.execute_reply": "2021-07-16T22:28:12.882617Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 14:22:15][datar][ INFO] Matching, by='a'\n" ] }, { "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", "
abc
<int64><object><float64>
01a0.5
12z1.5
23z2.5
\n", "
\n" ], "text/plain": [ " a b c\n", " \n", "0 1 a 0.5\n", "1 2 z 1.5\n", "2 3 z 2.5" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rows_update(data, tibble(a = [2,3], b = \"z\"))" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:12.939586Z", "iopub.status.busy": "2021-07-16T22:28:12.939002Z", "iopub.status.idle": "2021-07-16T22:28:12.954290Z", "shell.execute_reply": "2021-07-16T22:28:12.954712Z" } }, "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", "
abc
<int64><object><float64>
01a0.5
12z1.5
23z2.5
\n", "
\n" ], "text/plain": [ " a b c\n", " \n", "0 1 a 0.5\n", "1 2 z 1.5\n", "2 3 z 2.5" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rows_update(data, tibble(b = \"z\", a = [2,3]), by = \"a\")" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:12.990975Z", "iopub.status.busy": "2021-07-16T22:28:12.990382Z", "iopub.status.idle": "2021-07-16T22:28:13.079359Z", "shell.execute_reply": "2021-07-16T22:28:13.080018Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 14:22:17][datar][ INFO] Matching, by='a'\n" ] }, { "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", "
abc
<int64><object><float64>
01a0.5
12b1.5
23z2.5
\n", "
\n" ], "text/plain": [ " a b c\n", " \n", "0 1 a 0.5\n", "1 2 b 1.5\n", "2 3 z 2.5" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rows_patch(data, tibble(a = [2,3], b = \"z\"))" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:13.145161Z", "iopub.status.busy": "2021-07-16T22:28:13.143281Z", "iopub.status.idle": "2021-07-16T22:28:13.158501Z", "shell.execute_reply": "2021-07-16T22:28:13.158888Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 14:22:18][datar][ INFO] Matching, by='a'\n" ] }, { "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", "
abc
<int64><object><float64>
01a0.5
12z1.5
23z2.5
34zNaN
\n", "
\n" ], "text/plain": [ " a b c\n", " \n", "0 1 a 0.5\n", "1 2 z 1.5\n", "2 3 z 2.5\n", "3 4 z NaN" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rows_upsert(data, tibble(a = seq(2, 4), b = \"z\"))" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:13.181744Z", "iopub.status.busy": "2021-07-16T22:28:13.181046Z", "iopub.status.idle": "2021-07-16T22:28:13.219352Z", "shell.execute_reply": "2021-07-16T22:28:13.219753Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 14:22:18][datar][ INFO] Matching, by='a'\n" ] }, { "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", "
abc
<int64><object><float64>
01a0.5
\n", "
\n" ], "text/plain": [ " a b c\n", " \n", "0 1 a 0.5" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rows_delete(data, tibble(a = [2, 3]))" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:13.247095Z", "iopub.status.busy": "2021-07-16T22:28:13.246408Z", "iopub.status.idle": "2021-07-16T22:28:13.280047Z", "shell.execute_reply": "2021-07-16T22:28:13.280487Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 14:22:19][datar][ INFO] Matching, by='a'\n", "[2022-12-02 14:22:19][datar][ INFO] Ignoring extra columns: ['b']\n" ] }, { "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", "
abc
<int64><object><float64>
01a0.5
\n", "
\n" ], "text/plain": [ " a b c\n", " \n", "0 1 a 0.5" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rows_delete(data, tibble(a = [2, 3], b = \"b\"))" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:13.349257Z", "iopub.status.busy": "2021-07-16T22:28:13.348629Z", "iopub.status.idle": "2021-07-16T22:28:13.366160Z", "shell.execute_reply": "2021-07-16T22:28:13.366676Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[ValueError] Attempting to delete missing rows.\n" ] } ], "source": [ "with try_catch():\n", " rows_delete(data, tibble(a = [2,3], b = \"b\"), by = c(\"a\", \"b\"))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 2 } ================================================ FILE: docs/notebooks/rowwise.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:08.630104Z", "iopub.status.busy": "2021-07-16T22:28:08.629477Z", "iopub.status.idle": "2021-07-16T22:28:09.661020Z", "shell.execute_reply": "2021-07-16T22:28:09.658387Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ rowwise
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Create a rowwise frame\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/rowwise.html \n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `*cols`: Columns to make rowwise. \n", "\n", "##### Returns:\n", "  A rowwise frame \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/rowwise.html\n", "%run nb_helpers.py\n", "\n", "from datar.all import *\n", "\n", "nb_header(rowwise)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:09.684543Z", "iopub.status.busy": "2021-07-16T22:28:09.683910Z", "iopub.status.idle": "2021-07-16T22:28:09.995217Z", "shell.execute_reply": "2021-07-16T22:28:09.995615Z" } }, "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", "
xyzm
<float64><float64><float64><float64>
00.7404270.7220620.7964420.752977
10.4202910.0169880.6816900.372989
20.9839080.5072270.5086630.666599
30.0596620.4839420.0470450.196883
40.2880830.7354850.8689330.630834
50.1841380.5025970.4247340.370489
\n", "
\n", "

TibbleRowwise: (n=6)" ], "text/plain": [ " x y z m\n", " \n", "0 0.740427 0.722062 0.796442 0.752977\n", "1 0.420291 0.016988 0.681690 0.372989\n", "2 0.983908 0.507227 0.508663 0.666599\n", "3 0.059662 0.483942 0.047045 0.196883\n", "4 0.288083 0.735485 0.868933 0.630834\n", "5 0.184138 0.502597 0.424734 0.370489\n", "[TibbleRowwise: (n=6)]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x=runif(6), y=runif(6), z=runif(6))\n", "\n", "df >> rowwise() >> mutate(m=mean(c_across(c(f.x, f.y, f.z)))) " ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:10.067015Z", "iopub.status.busy": "2021-07-16T22:28:10.066388Z", "iopub.status.idle": "2021-07-16T22:28:10.080326Z", "shell.execute_reply": "2021-07-16T22:28:10.080713Z" } }, "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", "
xyzm
<float64><float64><float64><float64>
00.7404270.7220620.7964420.752977
10.4202910.0169880.6816900.372989
20.9839080.5072270.5086630.666599
30.0596620.4839420.0470450.196883
40.2880830.7354850.8689330.630834
50.1841380.5025970.4247340.370489
\n", "
\n", "

TibbleRowwise: (n=6)" ], "text/plain": [ " x y z m\n", " \n", "0 0.740427 0.722062 0.796442 0.752977\n", "1 0.420291 0.016988 0.681690 0.372989\n", "2 0.983908 0.507227 0.508663 0.666599\n", "3 0.059662 0.483942 0.047045 0.196883\n", "4 0.288083 0.735485 0.868933 0.630834\n", "5 0.184138 0.502597 0.424734 0.370489\n", "[TibbleRowwise: (n=6)]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> rowwise() >> mutate(m=mean(c_across(f[f.x:])))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:10.157870Z", "iopub.status.busy": "2021-07-16T22:28:10.157301Z", "iopub.status.idle": "2021-07-16T22:28:10.167496Z", "shell.execute_reply": "2021-07-16T22:28:10.167879Z" } }, "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", "
xyzm
<float64><float64><float64><float64>
00.7404270.7220620.7964420.722062
10.4202910.0169880.6816900.016988
20.9839080.5072270.5086630.507227
30.0596620.4839420.0470450.047045
40.2880830.7354850.8689330.288083
50.1841380.5025970.4247340.184138
\n", "
\n", "

TibbleRowwise: (n=6)" ], "text/plain": [ " x y z m\n", " \n", "0 0.740427 0.722062 0.796442 0.722062\n", "1 0.420291 0.016988 0.681690 0.016988\n", "2 0.983908 0.507227 0.508663 0.507227\n", "3 0.059662 0.483942 0.047045 0.047045\n", "4 0.288083 0.735485 0.868933 0.288083\n", "5 0.184138 0.502597 0.424734 0.184138\n", "[TibbleRowwise: (n=6)]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> rowwise() >> mutate(m=min(c_across([f.x, f.y, f.z]))) " ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:10.231704Z", "iopub.status.busy": "2021-07-16T22:28:10.230994Z", "iopub.status.idle": "2021-07-16T22:28:10.235604Z", "shell.execute_reply": "2021-07-16T22:28:10.234881Z" } }, "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", "
xyzm
<float64><float64><float64><float64>
00.7404270.7220620.7964420.722062
10.4202910.0169880.6816900.016988
20.9839080.5072270.5086630.507227
30.0596620.4839420.0470450.047045
40.2880830.7354850.8689330.288083
50.1841380.5025970.4247340.184138
\n", "
\n", "

TibbleRowwise: (n=6)" ], "text/plain": [ " x y z m\n", " \n", "0 0.740427 0.722062 0.796442 0.722062\n", "1 0.420291 0.016988 0.681690 0.016988\n", "2 0.983908 0.507227 0.508663 0.507227\n", "3 0.059662 0.483942 0.047045 0.047045\n", "4 0.288083 0.735485 0.868933 0.288083\n", "5 0.184138 0.502597 0.424734 0.184138\n", "[TibbleRowwise: (n=6)]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> rowwise() >> mutate(m=min(c_across(f[f.x:]))) " ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:10.245426Z", "iopub.status.busy": "2021-07-16T22:28:10.244596Z", "iopub.status.idle": "2021-07-16T22:28:10.286588Z", "shell.execute_reply": "2021-07-16T22:28:10.287010Z" } }, "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", "
xyzm
<float64><float64><float64><float64>
00.7404270.7220620.7964420.722062
10.4202910.0169880.6816900.016988
20.9839080.5072270.5086630.507227
30.0596620.4839420.0470450.047045
40.2880830.7354850.8689330.288083
50.1841380.5025970.4247340.184138
\n", "
\n" ], "text/plain": [ " x y z m\n", " \n", "0 0.740427 0.722062 0.796442 0.722062\n", "1 0.420291 0.016988 0.681690 0.016988\n", "2 0.983908 0.507227 0.508663 0.507227\n", "3 0.059662 0.483942 0.047045 0.047045\n", "4 0.288083 0.735485 0.868933 0.288083\n", "5 0.184138 0.502597 0.424734 0.184138" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> mutate(m = pmin(f.x, f.y, f.z))" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:10.296858Z", "iopub.status.busy": "2021-07-16T22:28:10.296263Z", "iopub.status.idle": "2021-07-16T22:28:10.347572Z", "shell.execute_reply": "2021-07-16T22:28:10.348035Z" } }, "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", "
simnmeansdz
<int64><int64><int64><int64><object>
01111[1.8805605045050253]
12224[-2.39100601732882, 2.6882535131773917]
23312[-0.8909366235397611, 2.2500642263497337, 4.00...
\n", "
\n", "

TibbleRowwise: sim (n=3)" ], "text/plain": [ " sim n mean sd \\\n", " \n", "0 1 1 1 1 \n", "1 2 2 2 4 \n", "2 3 3 1 2 \n", "\n", " z \n", " \n", "0 [1.8805605045050253] \n", "1 [-2.39100601732882, 2.6882535131773917] \n", "2 [-0.8909366235397611, 2.2500642263497337, 4.00... \n", "[TibbleRowwise: sim (n=3)]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "params = tibble(\n", " sim=[1, 2, 3],\n", " n=[1, 2, 3],\n", " mean=[1, 2, 1],\n", " sd=[1, 4, 2]\n", ")\n", "\n", "params >> rowwise(f.sim) >> mutate(z=rnorm(f.n, f.mean, f.sd)) " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 4 } ================================================ FILE: docs/notebooks/select.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:13.675066Z", "iopub.status.busy": "2021-07-16T22:27:13.674338Z", "iopub.status.idle": "2021-07-16T22:27:14.751873Z", "shell.execute_reply": "2021-07-16T22:27:14.752267Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ select
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Select columns from a data frame.\n", "\n", "See original API \n", "https://dplyr.tidyverse.org/reference/select.html \n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `*args`: A list of columns to select \n", "  `**kwargs`: A list of columns to select \n", "\n", "##### Returns:\n", "  A data frame with only the selected columns \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/select.html\n", "%run nb_helpers.py\n", "\n", "from datar.data import starwars, iris\n", "from datar.all import *\n", "\n", "nb_header(select)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:14.847610Z", "iopub.status.busy": "2021-07-16T22:27:14.847059Z", "iopub.status.idle": "2021-07-16T22:27:14.867059Z", "shell.execute_reply": "2021-07-16T22:27:14.867449Z" } }, "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", "
height
<float64>
0172.0
1167.0
296.0
3202.0
......
4150.0
82NaN
83NaN
84NaN
85NaN
86165.0
\n", "

87 rows × 1 columns

\n", "
\n" ], "text/plain": [ " height\n", " \n", "0 172.0\n", "1 167.0\n", "2 96.0\n", "3 202.0\n", ".. ...\n", "4 150.0\n", "82 NaN\n", "83 NaN\n", "84 NaN\n", "85 NaN\n", "86 165.0\n", "\n", "[87 rows x 1 columns]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> select(f.height)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:14.982599Z", "iopub.status.busy": "2021-07-16T22:27:14.982076Z", "iopub.status.idle": "2021-07-16T22:27:15.028171Z", "shell.execute_reply": "2021-07-16T22:27:15.026645Z" } }, "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", "
Petal_LengthPetal_WidthSepal_WidthSpeciesnamevalue
<float64><float64><float64><object><object><float64>
01.40.23.5setosaSepal_Length5.1
11.40.23.0setosaSepal_Length4.9
21.30.23.2setosaSepal_Length4.7
31.50.23.1setosaSepal_Length4.6
.....................
41.40.23.6setosaSepal_Length5.0
1455.22.33.0virginicaSepal_Length6.7
1465.01.92.5virginicaSepal_Length6.3
1475.22.03.0virginicaSepal_Length6.5
1485.42.33.4virginicaSepal_Length6.2
1495.11.83.0virginicaSepal_Length5.9
\n", "

150 rows × 6 columns

\n", "
\n" ], "text/plain": [ " Petal_Length Petal_Width Sepal_Width Species name value\n", " \n", "0 1.4 0.2 3.5 setosa Sepal_Length 5.1\n", "1 1.4 0.2 3.0 setosa Sepal_Length 4.9\n", "2 1.3 0.2 3.2 setosa Sepal_Length 4.7\n", "3 1.5 0.2 3.1 setosa Sepal_Length 4.6\n", ".. ... ... ... ... ... ...\n", "4 1.4 0.2 3.6 setosa Sepal_Length 5.0\n", "145 5.2 2.3 3.0 virginica Sepal_Length 6.7\n", "146 5.0 1.9 2.5 virginica Sepal_Length 6.3\n", "147 5.2 2.0 3.0 virginica Sepal_Length 6.5\n", "148 5.4 2.3 3.4 virginica Sepal_Length 6.2\n", "149 5.1 1.8 3.0 virginica Sepal_Length 5.9\n", "\n", "[150 rows x 6 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> pivot_longer(f['Sepal_Length'])" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.052612Z", "iopub.status.busy": "2021-07-16T22:27:15.051434Z", "iopub.status.idle": "2021-07-16T22:27:15.068570Z", "shell.execute_reply": "2021-07-16T22:27:15.068973Z" } }, "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", "
homeworldheightmass
<object><float64><float64>
0Tatooine172.077.0
1Tatooine167.075.0
2Naboo96.032.0
3Tatooine202.0136.0
............
4Alderaan150.049.0
82NaNNaNNaN
83NaNNaNNaN
84NaNNaNNaN
85NaNNaNNaN
86Naboo165.045.0
\n", "

87 rows × 3 columns

\n", "
\n" ], "text/plain": [ " homeworld height mass\n", " \n", "0 Tatooine 172.0 77.0\n", "1 Tatooine 167.0 75.0\n", "2 Naboo 96.0 32.0\n", "3 Tatooine 202.0 136.0\n", ".. ... ... ...\n", "4 Alderaan 150.0 49.0\n", "82 NaN NaN NaN\n", "83 NaN NaN NaN\n", "84 NaN NaN NaN\n", "85 NaN NaN NaN\n", "86 Naboo 165.0 45.0\n", "\n", "[87 rows x 3 columns]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> select(f.homeworld, f.height, f.mass)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.113979Z", "iopub.status.busy": "2021-07-16T22:27:15.112741Z", "iopub.status.idle": "2021-07-16T22:27:15.136746Z", "shell.execute_reply": "2021-07-16T22:27:15.137480Z" } }, "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", "
Petal_WidthSepal_WidthSpeciesnamevalue
<float64><float64><object><object><float64>
00.23.5setosaSepal_Length5.1
10.23.0setosaSepal_Length4.9
20.23.2setosaSepal_Length4.7
30.23.1setosaSepal_Length4.6
..................
40.23.6setosaSepal_Length5.0
2952.33.0virginicaPetal_Length5.2
2961.92.5virginicaPetal_Length5.0
2972.03.0virginicaPetal_Length5.2
2982.33.4virginicaPetal_Length5.4
2991.83.0virginicaPetal_Length5.1
\n", "

300 rows × 5 columns

\n", "
\n" ], "text/plain": [ " Petal_Width Sepal_Width Species name value\n", " \n", "0 0.2 3.5 setosa Sepal_Length 5.1\n", "1 0.2 3.0 setosa Sepal_Length 4.9\n", "2 0.2 3.2 setosa Sepal_Length 4.7\n", "3 0.2 3.1 setosa Sepal_Length 4.6\n", ".. ... ... ... ... ...\n", "4 0.2 3.6 setosa Sepal_Length 5.0\n", "295 2.3 3.0 virginica Petal_Length 5.2\n", "296 1.9 2.5 virginica Petal_Length 5.0\n", "297 2.0 3.0 virginica Petal_Length 5.2\n", "298 2.3 3.4 virginica Petal_Length 5.4\n", "299 1.8 3.0 virginica Petal_Length 5.1\n", "\n", "[300 rows x 5 columns]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> pivot_longer(c(f['Sepal_Length'], f['Petal_Length']))" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.166669Z", "iopub.status.busy": "2021-07-16T22:27:15.166140Z", "iopub.status.idle": "2021-07-16T22:27:15.244625Z", "shell.execute_reply": "2021-07-16T22:27:15.245072Z" } }, "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", "
nameheight
<object><float64>
0Luke Skywalker172.0
1C-3PO167.0
2R2-D296.0
3Darth Vader202.0
.........
4Leia Organa150.0
82ReyNaN
83Poe DameronNaN
84BB8NaN
85Captain PhasmaNaN
86Padmé Amidala165.0
\n", "

87 rows × 2 columns

\n", "
\n" ], "text/plain": [ " name height\n", " \n", "0 Luke Skywalker 172.0\n", "1 C-3PO 167.0\n", "2 R2-D2 96.0\n", "3 Darth Vader 202.0\n", ".. ... ...\n", "4 Leia Organa 150.0\n", "82 Rey NaN\n", "83 Poe Dameron NaN\n", "84 BB8 NaN\n", "85 Captain Phasma NaN\n", "86 Padmé Amidala 165.0\n", "\n", "[87 rows x 2 columns]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> select(c[f.name:f.mass])" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.289785Z", "iopub.status.busy": "2021-07-16T22:27:15.287507Z", "iopub.status.idle": "2021-07-16T22:27:15.399299Z", "shell.execute_reply": "2021-07-16T22:27:15.400062Z" } }, "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", "
masshair_colorskin_coloreye_colorbirth_yearsexgenderhomeworldspecies
<float64><object><object><object><float64><object><object><object><object>
077.0blondfairblue19.0malemasculineTatooineHuman
175.0NaNgoldyellow112.0nonemasculineTatooineDroid
232.0NaNwhite, bluered33.0nonemasculineNabooDroid
3136.0nonewhiteyellow41.9malemasculineTatooineHuman
..............................
449.0brownlightbrown19.0femalefeminineAlderaanHuman
82NaNbrownlighthazelNaNfemalefeminineNaNHuman
83NaNbrownlightbrownNaNmalemasculineNaNHuman
84NaNnonenoneblackNaNnonemasculineNaNDroid
85NaNunknownunknownunknownNaNNaNNaNNaNNaN
8645.0brownlightbrown46.0femalefeminineNabooHuman
\n", "

87 rows × 9 columns

\n", "
\n" ], "text/plain": [ " mass hair_color skin_color eye_color birth_year sex \\\n", " \n", "0 77.0 blond fair blue 19.0 male \n", "1 75.0 NaN gold yellow 112.0 none \n", "2 32.0 NaN white, blue red 33.0 none \n", "3 136.0 none white yellow 41.9 male \n", ".. ... ... ... ... ... ... \n", "4 49.0 brown light brown 19.0 female \n", "82 NaN brown light hazel NaN female \n", "83 NaN brown light brown NaN male \n", "84 NaN none none black NaN none \n", "85 NaN unknown unknown unknown NaN NaN \n", "86 45.0 brown light brown 46.0 female \n", "\n", " gender homeworld species \n", " \n", "0 masculine Tatooine Human \n", "1 masculine Tatooine Droid \n", "2 masculine Naboo Droid \n", "3 masculine Tatooine Human \n", ".. ... ... ... \n", "4 feminine Alderaan Human \n", "82 feminine NaN Human \n", "83 masculine NaN Human \n", "84 masculine NaN Droid \n", "85 NaN NaN NaN \n", "86 feminine Naboo Human \n", "\n", "[87 rows x 9 columns]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starwars >> select(~c[f.name:f.mass])" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.457346Z", "iopub.status.busy": "2021-07-16T22:27:15.452299Z", "iopub.status.idle": "2021-07-16T22:27:15.501476Z", "shell.execute_reply": "2021-07-16T22:27:15.502130Z" } }, "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", "
Sepal_WidthPetal_WidthSpecies
<float64><float64><object>
03.50.2setosa
13.00.2setosa
23.20.2setosa
33.10.2setosa
............
43.60.2setosa
1453.02.3virginica
1462.51.9virginica
1473.02.0virginica
1483.42.3virginica
1493.01.8virginica
\n", "

150 rows × 3 columns

\n", "
\n" ], "text/plain": [ " Sepal_Width Petal_Width Species\n", " \n", "0 3.5 0.2 setosa\n", "1 3.0 0.2 setosa\n", "2 3.2 0.2 setosa\n", "3 3.1 0.2 setosa\n", ".. ... ... ...\n", "4 3.6 0.2 setosa\n", "145 3.0 2.3 virginica\n", "146 2.5 1.9 virginica\n", "147 3.0 2.0 virginica\n", "148 3.4 2.3 virginica\n", "149 3.0 1.8 virginica\n", "\n", "[150 rows x 3 columns]" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> select(~c(f['Sepal_Length'], f['Petal_Length']))" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.541552Z", "iopub.status.busy": "2021-07-16T22:27:15.540955Z", "iopub.status.idle": "2021-07-16T22:27:15.610956Z", "shell.execute_reply": "2021-07-16T22:27:15.611531Z" } }, "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", "
Sepal_LengthPetal_LengthSpecies
<float64><float64><object>
05.11.4setosa
14.91.4setosa
24.71.3setosa
34.61.5setosa
............
45.01.4setosa
1456.75.2virginica
1466.35.0virginica
1476.55.2virginica
1486.25.4virginica
1495.95.1virginica
\n", "

150 rows × 3 columns

\n", "
\n" ], "text/plain": [ " Sepal_Length Petal_Length Species\n", " \n", "0 5.1 1.4 setosa\n", "1 4.9 1.4 setosa\n", "2 4.7 1.3 setosa\n", "3 4.6 1.5 setosa\n", ".. ... ... ...\n", "4 5.0 1.4 setosa\n", "145 6.7 5.2 virginica\n", "146 6.3 5.0 virginica\n", "147 6.5 5.2 virginica\n", "148 6.2 5.4 virginica\n", "149 5.9 5.1 virginica\n", "\n", "[150 rows x 3 columns]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> select(~ends_with(\"Width\"))" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.634079Z", "iopub.status.busy": "2021-07-16T22:27:15.633392Z", "iopub.status.idle": "2021-07-16T22:27:15.656679Z", "shell.execute_reply": "2021-07-16T22:27:15.657084Z" } }, "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", "
Petal_Width
<float64>
00.2
10.2
20.2
30.2
......
40.2
1452.3
1461.9
1472.0
1482.3
1491.8
\n", "

150 rows × 1 columns

\n", "
\n" ], "text/plain": [ " Petal_Width\n", " \n", "0 0.2\n", "1 0.2\n", "2 0.2\n", "3 0.2\n", ".. ...\n", "4 0.2\n", "145 2.3\n", "146 1.9\n", "147 2.0\n", "148 2.3\n", "149 1.8\n", "\n", "[150 rows x 1 columns]" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> select(starts_with(\"Petal\") & ends_with(\"Width\"))" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.683400Z", "iopub.status.busy": "2021-07-16T22:27:15.681889Z", "iopub.status.idle": "2021-07-16T22:27:15.707227Z", "shell.execute_reply": "2021-07-16T22:27:15.707622Z" } }, "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", "
Petal_LengthPetal_WidthSepal_Width
<float64><float64><float64>
01.40.23.5
11.40.23.0
21.30.23.2
31.50.23.1
............
41.40.23.6
1455.22.33.0
1465.01.92.5
1475.22.03.0
1485.42.33.4
1495.11.83.0
\n", "

150 rows × 3 columns

\n", "
\n" ], "text/plain": [ " Petal_Length Petal_Width Sepal_Width\n", " \n", "0 1.4 0.2 3.5\n", "1 1.4 0.2 3.0\n", "2 1.3 0.2 3.2\n", "3 1.5 0.2 3.1\n", ".. ... ... ...\n", "4 1.4 0.2 3.6\n", "145 5.2 2.3 3.0\n", "146 5.0 1.9 2.5\n", "147 5.2 2.0 3.0\n", "148 5.4 2.3 3.4\n", "149 5.1 1.8 3.0\n", "\n", "[150 rows x 3 columns]" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> select(starts_with(\"Petal\") | ends_with(\"Width\"))" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.732248Z", "iopub.status.busy": "2021-07-16T22:27:15.731652Z", "iopub.status.idle": "2021-07-16T22:27:15.743883Z", "shell.execute_reply": "2021-07-16T22:27:15.744324Z" } }, "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", "
Petal_Length
<float64>
01.4
11.4
21.3
31.5
......
41.4
1455.2
1465.0
1475.2
1485.4
1495.1
\n", "

150 rows × 1 columns

\n", "
\n" ], "text/plain": [ " Petal_Length\n", " \n", "0 1.4\n", "1 1.4\n", "2 1.3\n", "3 1.5\n", ".. ...\n", "4 1.4\n", "145 5.2\n", "146 5.0\n", "147 5.2\n", "148 5.4\n", "149 5.1\n", "\n", "[150 rows x 1 columns]" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> select(starts_with(\"Petal\") & ~ends_with(\"Width\"))" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.761579Z", "iopub.status.busy": "2021-07-16T22:27:15.760973Z", "iopub.status.idle": "2021-07-16T22:27:15.783958Z", "shell.execute_reply": "2021-07-16T22:27:15.784373Z" } }, "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", "
Species
<object>
0setosa
1setosa
2setosa
3setosa
......
4setosa
145virginica
146virginica
147virginica
148virginica
149virginica
\n", "

150 rows × 1 columns

\n", "
\n" ], "text/plain": [ " Species\n", " \n", "0 setosa\n", "1 setosa\n", "2 setosa\n", "3 setosa\n", ".. ...\n", "4 setosa\n", "145 virginica\n", "146 virginica\n", "147 virginica\n", "148 virginica\n", "149 virginica\n", "\n", "[150 rows x 1 columns]" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# select last column\n", "iris >> select(-1)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.807075Z", "iopub.status.busy": "2021-07-16T22:27:15.806477Z", "iopub.status.idle": "2021-07-16T22:27:15.826834Z", "shell.execute_reply": "2021-07-16T22:27:15.827230Z" } }, "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", "
Sepal_WidthPetal_Length
<float64><float64>
03.51.4
13.01.4
23.21.3
33.11.5
.........
43.61.4
1453.05.2
1462.55.0
1473.05.2
1483.45.4
1493.05.1
\n", "

150 rows × 2 columns

\n", "
\n" ], "text/plain": [ " Sepal_Width Petal_Length\n", " \n", "0 3.5 1.4\n", "1 3.0 1.4\n", "2 3.2 1.3\n", "3 3.1 1.5\n", ".. ... ...\n", "4 3.6 1.4\n", "145 3.0 5.2\n", "146 2.5 5.0\n", "147 3.0 5.2\n", "148 3.4 5.4\n", "149 3.0 5.1\n", "\n", "[150 rows x 2 columns]" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris >> select(c[1:3])" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:15.890597Z", "iopub.status.busy": "2021-07-16T22:27:15.889991Z", "iopub.status.idle": "2021-07-16T22:27:15.902226Z", "shell.execute_reply": "2021-07-16T22:27:15.904342Z" } }, "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", "
Sepal_LengthSepal_WidthPetal_LengthPetal_Width
<float64><float64><float64><float64>
05.13.51.40.2
14.93.01.40.2
24.73.21.30.2
34.63.11.50.2
...............
45.03.61.40.2
1456.73.05.22.3
1466.32.55.01.9
1476.53.05.22.0
1486.23.45.42.3
1495.93.05.11.8
\n", "

150 rows × 4 columns

\n", "
\n" ], "text/plain": [ " Sepal_Length Sepal_Width Petal_Length Petal_Width\n", " \n", "0 5.1 3.5 1.4 0.2\n", "1 4.9 3.0 1.4 0.2\n", "2 4.7 3.2 1.3 0.2\n", "3 4.6 3.1 1.5 0.2\n", ".. ... ... ... ...\n", "4 5.0 3.6 1.4 0.2\n", "145 6.7 3.0 5.2 2.3\n", "146 6.3 2.5 5.0 1.9\n", "147 6.5 3.0 5.2 2.0\n", "148 6.2 3.4 5.4 2.3\n", "149 5.9 3.0 5.1 1.8\n", "\n", "[150 rows x 4 columns]" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# drop last column\n", "iris >> select(~c(-1))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 4 } ================================================ FILE: docs/notebooks/separate.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "005da05e", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:18.766343Z", "iopub.status.busy": "2021-07-16T22:27:18.765294Z", "iopub.status.idle": "2021-07-16T22:27:19.764916Z", "shell.execute_reply": "2021-07-16T22:27:19.765324Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ separate
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Given either a regular expression or a vector of character positions,\n", "turns a single character column into multiple columns. \n", "\n", "##### Args:\n", "  `data`: The dataframe \n", "  `col`: Column name or position. \n", "  `into`: Names of new variables to create as character vector. \n", "    Use `None`/`NA`/`NULL` to omit the variable in the output. \n", "\n", "  `sep`: Separator between columns. \n", "    If str, `sep` is interpreted as a regular expression. \n", "    The default value is a regular expression that matches \n", "    any sequence of non-alphanumeric values. \n", "    If int, `sep` is interpreted as character positions to split at. \n", "\n", "  `remove`: If TRUE, remove input column from output data frame. \n", "  `convert`: The universal type for the extracted columns or a dict for \n", "    individual ones \n", "    Note that when given `TRUE`, `DataFrame.convert_dtypes()` is called, \n", "    but it will not convert `str` to other types \n", "    (For example, `'1'` to `1`). You have to specify the dtype yourself. \n", "\n", "  `extra`: If sep is a character vector, this controls what happens when \n", "    there are too many pieces. There are three valid options: \n", "\n", "    - \"warn\" (the default): emit a warning and drop extra values.\n", "\n", "    - \"drop\": drop any extra values without a warning.\n", "\n", "    - \"merge\": only splits at most length(into) times\n", "\n", "  `fill`: If sep is a character vector, this controls what happens when \n", "    there are not enough pieces. There are three valid options: \n", "\n", "    - \"warn\" (the default): emit a warning and fill from the right\n", "\n", "    - \"right\": fill with missing values on the right\n", "\n", "    - \"left\": fill with missing values on the left\n", "\n", "##### Returns:\n", "  Dataframe with separated columns. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ separate_rows
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Separates the values and places each one in its own row.\n", "\n", "##### Args:\n", "  `data`: The dataframe \n", "  `*columns`: The columns to separate on \n", "  `sep`: Separator between columns. \n", "  `convert`: The universal type for the extracted columns or a dict for \n", "    individual ones \n", "\n", "##### Returns:\n", "  Dataframe with rows separated and repeated. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://tidyr.tidyverse.org/reference/separate.html\n", "%run nb_helpers.py\n", "\n", "from datar.all import *\n", "\n", "nb_header(separate, separate_rows)" ] }, { "cell_type": "code", "execution_count": 2, "id": "753fe6bf", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:19.778843Z", "iopub.status.busy": "2021-07-16T22:27:19.778209Z", "iopub.status.idle": "2021-07-16T22:27:20.040544Z", "shell.execute_reply": "2021-07-16T22:27:20.041222Z" } }, "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", "
AB
<object><object>
0NaNNaN
1xy
2xz
3yz
\n", "
\n" ], "text/plain": [ " A B\n", " \n", "0 NaN NaN\n", "1 x y\n", "2 x z\n", "3 y z" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x=c(NA, \"x.y\", \"x.z\", \"y.z\"))\n", "df >> separate(f.x, c(\"A\", \"B\"))" ] }, { "cell_type": "code", "execution_count": 3, "id": "1e4c018c", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:20.062417Z", "iopub.status.busy": "2021-07-16T22:27:20.061661Z", "iopub.status.idle": "2021-07-16T22:27:20.068845Z", "shell.execute_reply": "2021-07-16T22:27:20.069252Z" } }, "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", "
B
<object>
0NaN
1y
2z
3z
\n", "
\n" ], "text/plain": [ " B\n", " \n", "0 NaN\n", "1 y\n", "2 z\n", "3 z" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> separate(f.x, c(NA, \"B\"))" ] }, { "cell_type": "code", "execution_count": 4, "id": "053b5044", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:20.080729Z", "iopub.status.busy": "2021-07-16T22:27:20.080030Z", "iopub.status.idle": "2021-07-16T22:27:20.118557Z", "shell.execute_reply": "2021-07-16T22:27:20.118982Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 14:25:28][datar][WARNING] Expected 2 pieces. Additional pieces discarded in 1 rows ['x y z'].\n", "[2022-12-02 14:25:28][datar][WARNING] Expected 2 pieces. Missing pieces filled with `NA` in 1 rows ['x'].\n" ] }, { "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", "
ab
<object><object>
0xNaN
1xy
2xy
3NaNNaN
\n", "
\n" ], "text/plain": [ " a b\n", " \n", "0 x NaN\n", "1 x y\n", "2 x y\n", "3 NaN NaN" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x=c(\"x\", \"x y\", \"x y z\", NA))\n", "df >> separate(f.x, c(\"a\", \"b\"))" ] }, { "cell_type": "code", "execution_count": 5, "id": "d7541e84", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:20.141111Z", "iopub.status.busy": "2021-07-16T22:27:20.140187Z", "iopub.status.idle": "2021-07-16T22:27:20.147100Z", "shell.execute_reply": "2021-07-16T22:27:20.147500Z" } }, "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", "
ab
<object><object>
0xNaN
1xy
2xy
3NaNNaN
\n", "
\n" ], "text/plain": [ " a b\n", " \n", "0 x NaN\n", "1 x y\n", "2 x y\n", "3 NaN NaN" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> separate(f.x, c(\"a\", \"b\"), extra=\"drop\", fill=\"right\")" ] }, { "cell_type": "code", "execution_count": 6, "id": "fb7a4e8c", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:20.169036Z", "iopub.status.busy": "2021-07-16T22:27:20.168275Z", "iopub.status.idle": "2021-07-16T22:27:20.177192Z", "shell.execute_reply": "2021-07-16T22:27:20.177742Z" } }, "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", "
ab
<object><object>
0NaNx
1xy
2xy z
3NaNNaN
\n", "
\n" ], "text/plain": [ " a b\n", " \n", "0 NaN x\n", "1 x y\n", "2 x y z\n", "3 NaN NaN" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> separate(f.x, c(\"a\", \"b\"), extra=\"merge\", fill=\"left\")" ] }, { "cell_type": "code", "execution_count": 7, "id": "204809bd", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:20.188461Z", "iopub.status.busy": "2021-07-16T22:27:20.187899Z", "iopub.status.idle": "2021-07-16T22:27:20.228915Z", "shell.execute_reply": "2021-07-16T22:27:20.229494Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 14:25:32][datar][WARNING] Expected 3 pieces. Missing pieces filled with `NA` in 2 rows ['x', 'x y'].\n" ] }, { "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", "
abc
<object><object><object>
0xNaNNaN
1xyNaN
2xyz
3NaNNaNNaN
\n", "
\n" ], "text/plain": [ " a b c\n", " \n", "0 x NaN NaN\n", "1 x y NaN\n", "2 x y z\n", "3 NaN NaN NaN" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> separate(f.x, c(\"a\", \"b\", \"c\"))" ] }, { "cell_type": "code", "execution_count": 8, "id": "38bddf96", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:20.254775Z", "iopub.status.busy": "2021-07-16T22:27:20.254144Z", "iopub.status.idle": "2021-07-16T22:27:20.285273Z", "shell.execute_reply": "2021-07-16T22:27:20.285782Z" } }, "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", "
keyvalue
<object><object>
0x123
1yerror: 7
\n", "
\n" ], "text/plain": [ " key value\n", " \n", "0 x 123\n", "1 y error: 7" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x=c(\"x: 123\", \"y: error: 7\"))\n", "df >> separate(f.x, c(\"key\", \"value\"), \": \", extra=\"merge\")" ] }, { "cell_type": "code", "execution_count": 9, "id": "b147f21e", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:20.312361Z", "iopub.status.busy": "2021-07-16T22:27:20.311692Z", "iopub.status.idle": "2021-07-16T22:27:20.351764Z", "shell.execute_reply": "2021-07-16T22:27:20.352356Z" } }, "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", "
AB
<object><object>
0NaNNaN
1xy
2xz
3yz
\n", "
\n" ], "text/plain": [ " A B\n", " \n", "0 NaN NaN\n", "1 x y\n", "2 x z\n", "3 y z" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x=c(NA, \"x?y\", \"x.z\", \"y:z\"))\n", "df >> separate(f.x, c(\"A\",\"B\"), sep=r\"[.?:]\")" ] }, { "cell_type": "code", "execution_count": 10, "id": "d029d623", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:20.385969Z", "iopub.status.busy": "2021-07-16T22:27:20.384572Z", "iopub.status.idle": "2021-07-16T22:27:20.435868Z", "shell.execute_reply": "2021-07-16T22:27:20.436346Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 14:25:35][datar][WARNING] Expected 2 pieces. Missing pieces filled with `NA` in 1 rows ['z'].\n" ] }, { "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", "
keyvalue
<object><object>
0x1
1x2
2y4
3zNaN
4NaNNaN
\n", "
\n" ], "text/plain": [ " key value\n", " \n", "0 x 1\n", "1 x 2\n", "2 y 4\n", "3 z NaN\n", "4 NaN NaN" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x=c(\"x:1\", \"x:2\", \"y:4\", \"z\", NA))\n", "df >> separate(f.x, c(\"key\",\"value\"), \":\")" ] }, { "cell_type": "code", "execution_count": 11, "id": "f1a9ec03", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:20.446982Z", "iopub.status.busy": "2021-07-16T22:27:20.446323Z", "iopub.status.idle": "2021-07-16T22:27:20.472635Z", "shell.execute_reply": "2021-07-16T22:27:20.473105Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 14:25:36][datar][WARNING] Expected 2 pieces. Missing pieces filled with `NA` in 1 rows ['z'].\n" ] }, { "data": { "text/plain": [ "key object\n", "value float64\n", "dtype: object" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "out = df >> separate(f.x, c(\"key\",\"value\"), \":\", convert={'value': float}) \n", "out.dtypes" ] }, { "cell_type": "code", "execution_count": 12, "id": "c7af94b8", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:20.496700Z", "iopub.status.busy": "2021-07-16T22:27:20.496152Z", "iopub.status.idle": "2021-07-16T22:27:20.518813Z", "shell.execute_reply": "2021-07-16T22:27:20.519189Z" } }, "outputs": [], "source": [ "df = tibble(\n", " x=[1,2,3],\n", " y=c(\"a\", \"d,e,f\", \"g,h\"),\n", " z=c(\"1\", \"2,3,4\", \"5,6\")\n", ")" ] }, { "cell_type": "code", "execution_count": 13, "id": "47243faf", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:20.556179Z", "iopub.status.busy": "2021-07-16T22:27:20.555559Z", "iopub.status.idle": "2021-07-16T22:27:20.567301Z", "shell.execute_reply": "2021-07-16T22:27:20.567719Z" } }, "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", "
xyz
<int64><object><int64>
01a1
12d2
22e3
32f4
43g5
53h6
\n", "
\n" ], "text/plain": [ " x y z\n", " \n", "0 1 a 1\n", "1 2 d 2\n", "2 2 e 3\n", "3 2 f 4\n", "4 3 g 5\n", "5 3 h 6" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> separate_rows(f.y, f.z, convert={'z': int})" ] }, { "cell_type": "code", "execution_count": null, "id": "f63ac06e", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/setops.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "f197471c", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:41.766049Z", "iopub.status.busy": "2021-07-16T22:27:41.765225Z", "iopub.status.idle": "2021-07-16T22:27:42.847260Z", "shell.execute_reply": "2021-07-16T22:27:42.847679Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ intersect
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Get the intersection of two vectors\n", "\n", "##### Args:\n", "  `x`: the first vector \n", "  `y`: the second vector \n", "\n", "##### Returns:\n", "  The intersection of the two vectors \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ union
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Get the union of two vectors\n", "\n", "##### Args:\n", "  `x`: the first vector \n", "  `y`: the second vector \n", "\n", "##### Returns:\n", "  The union of the two vectors \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ setdiff
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Get the difference of two vectors\n", "\n", "##### Args:\n", "  `x`: the first vector \n", "  `y`: the second vector \n", "\n", "##### Returns:\n", "  The difference of the two vectors \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ union_all
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Combine two data frames together.\n", "\n", "See original API \n", "https://dplyr.tidyverse.org/reference/setops.html \n", "\n", "##### Args:\n", "  `x`: A data frame \n", "  `y`: A data frame \n", "\n", "##### Returns:\n", "  A data frame with rows from x and y \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ setequal
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Check if two vectors are equal\n", "\n", "##### Args:\n", "  `x`: the first vector \n", "  `y`: the second vector \n", "\n", "##### Returns:\n", "  Whether the two vectors are equal \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/setops.html\n", "%run nb_helpers.py\n", "\n", "from datar.data import mtcars\n", "from datar.all import *\n", "\n", "nb_header(intersect, union, setdiff, union_all, setequal, book='setops')" ] }, { "cell_type": "code", "execution_count": 2, "id": "dca8c05c", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:42.871867Z", "iopub.status.busy": "2021-07-16T22:27:42.871186Z", "iopub.status.idle": "2021-07-16T22:27:42.955932Z", "shell.execute_reply": "2021-07-16T22:27:42.956665Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
019.26167.61233.923.44018.301044
117.86167.61233.923.44018.901044
216.48275.81803.074.07017.400033
317.38275.81803.073.73017.600033
415.28275.81803.073.78018.000033
510.48472.02052.935.25017.980034
610.48460.02153.005.42417.820034
714.78440.02303.235.34517.420034
832.4478.7664.082.20019.471141
930.4475.7524.931.61518.521142
1033.9471.1654.221.83519.901141
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt qsec vs \\\n", " \n", "0 19.2 6 167.6 123 3.92 3.440 18.30 1 \n", "1 17.8 6 167.6 123 3.92 3.440 18.90 1 \n", "2 16.4 8 275.8 180 3.07 4.070 17.40 0 \n", "3 17.3 8 275.8 180 3.07 3.730 17.60 0 \n", "4 15.2 8 275.8 180 3.07 3.780 18.00 0 \n", "5 10.4 8 472.0 205 2.93 5.250 17.98 0 \n", "6 10.4 8 460.0 215 3.00 5.424 17.82 0 \n", "7 14.7 8 440.0 230 3.23 5.345 17.42 0 \n", "8 32.4 4 78.7 66 4.08 2.200 19.47 1 \n", "9 30.4 4 75.7 52 4.93 1.615 18.52 1 \n", "10 33.9 4 71.1 65 4.22 1.835 19.90 1 \n", "\n", " am gear carb \n", " \n", "0 0 4 4 \n", "1 0 4 4 \n", "2 0 3 3 \n", "3 0 3 3 \n", "4 0 3 3 \n", "5 0 3 4 \n", "6 0 3 4 \n", "7 0 3 4 \n", "8 1 4 1 \n", "9 1 4 2 \n", "10 1 4 1 " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "first = mtcars >> slice(c[:20])\n", "second = mtcars >> slice(c[9:33])\n", "\n", "intersect(first, second) # or first >> intersect(second)" ] }, { "cell_type": "code", "execution_count": 3, "id": "20d8b3b9", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:43.011717Z", "iopub.status.busy": "2021-07-16T22:27:42.965221Z", "iopub.status.idle": "2021-07-16T22:27:43.034491Z", "shell.execute_reply": "2021-07-16T22:27:43.035343Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
021.06160.01103.902.62016.460144
121.06160.01103.902.87517.020144
222.84108.0933.852.32018.611141
321.46258.01103.083.21519.441031
418.78360.01753.153.44017.020032
518.16225.01052.763.46020.221031
614.38360.02453.213.57015.840034
724.44146.7623.693.19020.001042
822.84140.8953.923.15022.901042
919.26167.61233.923.44018.301044
1017.86167.61233.923.44018.901044
1116.48275.81803.074.07017.400033
1217.38275.81803.073.73017.600033
1315.28275.81803.073.78018.000033
1410.48472.02052.935.25017.980034
1510.48460.02153.005.42417.820034
1614.78440.02303.235.34517.420034
1732.4478.7664.082.20019.471141
1830.4475.7524.931.61518.521142
1933.9471.1654.221.83519.901141
2021.54120.1973.702.46520.011031
2115.58318.01502.763.52016.870032
2215.28304.01503.153.43517.300032
2313.38350.02453.733.84015.410034
2419.28400.01753.083.84517.050032
2527.3479.0664.081.93518.901141
2626.04120.3914.432.14016.700152
2730.4495.11133.771.51316.901152
2815.88351.02644.223.17014.500154
2919.76145.01753.622.77015.500156
3015.08301.03353.543.57014.600158
3121.44121.01094.112.78018.601142
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt qsec vs \\\n", " \n", "0 21.0 6 160.0 110 3.90 2.620 16.46 0 \n", "1 21.0 6 160.0 110 3.90 2.875 17.02 0 \n", "2 22.8 4 108.0 93 3.85 2.320 18.61 1 \n", "3 21.4 6 258.0 110 3.08 3.215 19.44 1 \n", "4 18.7 8 360.0 175 3.15 3.440 17.02 0 \n", "5 18.1 6 225.0 105 2.76 3.460 20.22 1 \n", "6 14.3 8 360.0 245 3.21 3.570 15.84 0 \n", "7 24.4 4 146.7 62 3.69 3.190 20.00 1 \n", "8 22.8 4 140.8 95 3.92 3.150 22.90 1 \n", "9 19.2 6 167.6 123 3.92 3.440 18.30 1 \n", "10 17.8 6 167.6 123 3.92 3.440 18.90 1 \n", "11 16.4 8 275.8 180 3.07 4.070 17.40 0 \n", "12 17.3 8 275.8 180 3.07 3.730 17.60 0 \n", "13 15.2 8 275.8 180 3.07 3.780 18.00 0 \n", "14 10.4 8 472.0 205 2.93 5.250 17.98 0 \n", "15 10.4 8 460.0 215 3.00 5.424 17.82 0 \n", "16 14.7 8 440.0 230 3.23 5.345 17.42 0 \n", "17 32.4 4 78.7 66 4.08 2.200 19.47 1 \n", "18 30.4 4 75.7 52 4.93 1.615 18.52 1 \n", "19 33.9 4 71.1 65 4.22 1.835 19.90 1 \n", "20 21.5 4 120.1 97 3.70 2.465 20.01 1 \n", "21 15.5 8 318.0 150 2.76 3.520 16.87 0 \n", "22 15.2 8 304.0 150 3.15 3.435 17.30 0 \n", "23 13.3 8 350.0 245 3.73 3.840 15.41 0 \n", "24 19.2 8 400.0 175 3.08 3.845 17.05 0 \n", "25 27.3 4 79.0 66 4.08 1.935 18.90 1 \n", "26 26.0 4 120.3 91 4.43 2.140 16.70 0 \n", "27 30.4 4 95.1 113 3.77 1.513 16.90 1 \n", "28 15.8 8 351.0 264 4.22 3.170 14.50 0 \n", "29 19.7 6 145.0 175 3.62 2.770 15.50 0 \n", "30 15.0 8 301.0 335 3.54 3.570 14.60 0 \n", "31 21.4 4 121.0 109 4.11 2.780 18.60 1 \n", "\n", " am gear carb \n", " \n", "0 1 4 4 \n", "1 1 4 4 \n", "2 1 4 1 \n", "3 0 3 1 \n", "4 0 3 2 \n", "5 0 3 1 \n", "6 0 3 4 \n", "7 0 4 2 \n", "8 0 4 2 \n", "9 0 4 4 \n", "10 0 4 4 \n", "11 0 3 3 \n", "12 0 3 3 \n", "13 0 3 3 \n", "14 0 3 4 \n", "15 0 3 4 \n", "16 0 3 4 \n", "17 1 4 1 \n", "18 1 4 2 \n", "19 1 4 1 \n", "20 0 3 1 \n", "21 0 3 2 \n", "22 0 3 2 \n", "23 0 3 4 \n", "24 0 3 2 \n", "25 1 4 1 \n", "26 1 5 2 \n", "27 1 5 2 \n", "28 1 5 4 \n", "29 1 5 6 \n", "30 1 5 8 \n", "31 1 4 2 " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "union(first, second)" ] }, { "cell_type": "code", "execution_count": 4, "id": "04ec7aa8", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:43.167209Z", "iopub.status.busy": "2021-07-16T22:27:43.166202Z", "iopub.status.idle": "2021-07-16T22:27:43.220783Z", "shell.execute_reply": "2021-07-16T22:27:43.221350Z" } }, "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", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
021.06160.01103.902.62016.460144
121.06160.01103.902.87517.020144
222.84108.0933.852.32018.611141
321.46258.01103.083.21519.441031
418.78360.01753.153.44017.020032
518.16225.01052.763.46020.221031
614.38360.02453.213.57015.840034
724.44146.7623.693.19020.001042
822.84140.8953.923.15022.901042
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt qsec vs \\\n", " \n", "0 21.0 6 160.0 110 3.90 2.620 16.46 0 \n", "1 21.0 6 160.0 110 3.90 2.875 17.02 0 \n", "2 22.8 4 108.0 93 3.85 2.320 18.61 1 \n", "3 21.4 6 258.0 110 3.08 3.215 19.44 1 \n", "4 18.7 8 360.0 175 3.15 3.440 17.02 0 \n", "5 18.1 6 225.0 105 2.76 3.460 20.22 1 \n", "6 14.3 8 360.0 245 3.21 3.570 15.84 0 \n", "7 24.4 4 146.7 62 3.69 3.190 20.00 1 \n", "8 22.8 4 140.8 95 3.92 3.150 22.90 1 \n", "\n", " am gear carb \n", " \n", "0 1 4 4 \n", "1 1 4 4 \n", "2 1 4 1 \n", "3 0 3 1 \n", "4 0 3 2 \n", "5 0 3 1 \n", "6 0 3 4 \n", "7 0 4 2 \n", "8 0 4 2 " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "setdiff(first, second)" ] }, { "cell_type": "code", "execution_count": 5, "id": "e8e9a2a5", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:43.319268Z", "iopub.status.busy": "2021-07-16T22:27:43.318453Z", "iopub.status.idle": "2021-07-16T22:27:43.343000Z", "shell.execute_reply": "2021-07-16T22:27:43.345072Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
021.54120.1973.702.46520.011031
115.58318.01502.763.52016.870032
215.28304.01503.153.43517.300032
313.38350.02453.733.84015.410034
419.28400.01753.083.84517.050032
527.3479.0664.081.93518.901141
626.04120.3914.432.14016.700152
730.4495.11133.771.51316.901152
815.88351.02644.223.17014.500154
919.76145.01753.622.77015.500156
1015.08301.03353.543.57014.600158
1121.44121.01094.112.78018.601142
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt qsec vs \\\n", " \n", "0 21.5 4 120.1 97 3.70 2.465 20.01 1 \n", "1 15.5 8 318.0 150 2.76 3.520 16.87 0 \n", "2 15.2 8 304.0 150 3.15 3.435 17.30 0 \n", "3 13.3 8 350.0 245 3.73 3.840 15.41 0 \n", "4 19.2 8 400.0 175 3.08 3.845 17.05 0 \n", "5 27.3 4 79.0 66 4.08 1.935 18.90 1 \n", "6 26.0 4 120.3 91 4.43 2.140 16.70 0 \n", "7 30.4 4 95.1 113 3.77 1.513 16.90 1 \n", "8 15.8 8 351.0 264 4.22 3.170 14.50 0 \n", "9 19.7 6 145.0 175 3.62 2.770 15.50 0 \n", "10 15.0 8 301.0 335 3.54 3.570 14.60 0 \n", "11 21.4 4 121.0 109 4.11 2.780 18.60 1 \n", "\n", " am gear carb \n", " \n", "0 0 3 1 \n", "1 0 3 2 \n", "2 0 3 2 \n", "3 0 3 4 \n", "4 0 3 2 \n", "5 1 4 1 \n", "6 1 5 2 \n", "7 1 5 2 \n", "8 1 5 4 \n", "9 1 5 6 \n", "10 1 5 8 \n", "11 1 4 2 " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "setdiff(second, first)" ] }, { "cell_type": "code", "execution_count": 6, "id": "eab63ddf", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:43.434740Z", "iopub.status.busy": "2021-07-16T22:27:43.433913Z", "iopub.status.idle": "2021-07-16T22:27:43.450917Z", "shell.execute_reply": "2021-07-16T22:27:43.451363Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
021.06160.01103.902.62016.460144
121.06160.01103.902.87517.020144
222.84108.0933.852.32018.611141
321.46258.01103.083.21519.441031
418.78360.01753.153.44017.020032
518.16225.01052.763.46020.221031
614.38360.02453.213.57015.840034
724.44146.7623.693.19020.001042
822.84140.8953.923.15022.901042
919.26167.61233.923.44018.301044
1017.86167.61233.923.44018.901044
1116.48275.81803.074.07017.400033
1217.38275.81803.073.73017.600033
1315.28275.81803.073.78018.000033
1410.48472.02052.935.25017.980034
1510.48460.02153.005.42417.820034
1614.78440.02303.235.34517.420034
1732.4478.7664.082.20019.471141
1830.4475.7524.931.61518.521142
1933.9471.1654.221.83519.901141
2019.26167.61233.923.44018.301044
2117.86167.61233.923.44018.901044
2216.48275.81803.074.07017.400033
2317.38275.81803.073.73017.600033
2415.28275.81803.073.78018.000033
2510.48472.02052.935.25017.980034
2610.48460.02153.005.42417.820034
2714.78440.02303.235.34517.420034
2832.4478.7664.082.20019.471141
2930.4475.7524.931.61518.521142
3033.9471.1654.221.83519.901141
3121.54120.1973.702.46520.011031
3215.58318.01502.763.52016.870032
3315.28304.01503.153.43517.300032
3413.38350.02453.733.84015.410034
3519.28400.01753.083.84517.050032
3627.3479.0664.081.93518.901141
3726.04120.3914.432.14016.700152
3830.4495.11133.771.51316.901152
3915.88351.02644.223.17014.500154
4019.76145.01753.622.77015.500156
4115.08301.03353.543.57014.600158
4221.44121.01094.112.78018.601142
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt qsec vs \\\n", " \n", "0 21.0 6 160.0 110 3.90 2.620 16.46 0 \n", "1 21.0 6 160.0 110 3.90 2.875 17.02 0 \n", "2 22.8 4 108.0 93 3.85 2.320 18.61 1 \n", "3 21.4 6 258.0 110 3.08 3.215 19.44 1 \n", "4 18.7 8 360.0 175 3.15 3.440 17.02 0 \n", "5 18.1 6 225.0 105 2.76 3.460 20.22 1 \n", "6 14.3 8 360.0 245 3.21 3.570 15.84 0 \n", "7 24.4 4 146.7 62 3.69 3.190 20.00 1 \n", "8 22.8 4 140.8 95 3.92 3.150 22.90 1 \n", "9 19.2 6 167.6 123 3.92 3.440 18.30 1 \n", "10 17.8 6 167.6 123 3.92 3.440 18.90 1 \n", "11 16.4 8 275.8 180 3.07 4.070 17.40 0 \n", "12 17.3 8 275.8 180 3.07 3.730 17.60 0 \n", "13 15.2 8 275.8 180 3.07 3.780 18.00 0 \n", "14 10.4 8 472.0 205 2.93 5.250 17.98 0 \n", "15 10.4 8 460.0 215 3.00 5.424 17.82 0 \n", "16 14.7 8 440.0 230 3.23 5.345 17.42 0 \n", "17 32.4 4 78.7 66 4.08 2.200 19.47 1 \n", "18 30.4 4 75.7 52 4.93 1.615 18.52 1 \n", "19 33.9 4 71.1 65 4.22 1.835 19.90 1 \n", "20 19.2 6 167.6 123 3.92 3.440 18.30 1 \n", "21 17.8 6 167.6 123 3.92 3.440 18.90 1 \n", "22 16.4 8 275.8 180 3.07 4.070 17.40 0 \n", "23 17.3 8 275.8 180 3.07 3.730 17.60 0 \n", "24 15.2 8 275.8 180 3.07 3.780 18.00 0 \n", "25 10.4 8 472.0 205 2.93 5.250 17.98 0 \n", "26 10.4 8 460.0 215 3.00 5.424 17.82 0 \n", "27 14.7 8 440.0 230 3.23 5.345 17.42 0 \n", "28 32.4 4 78.7 66 4.08 2.200 19.47 1 \n", "29 30.4 4 75.7 52 4.93 1.615 18.52 1 \n", "30 33.9 4 71.1 65 4.22 1.835 19.90 1 \n", "31 21.5 4 120.1 97 3.70 2.465 20.01 1 \n", "32 15.5 8 318.0 150 2.76 3.520 16.87 0 \n", "33 15.2 8 304.0 150 3.15 3.435 17.30 0 \n", "34 13.3 8 350.0 245 3.73 3.840 15.41 0 \n", "35 19.2 8 400.0 175 3.08 3.845 17.05 0 \n", "36 27.3 4 79.0 66 4.08 1.935 18.90 1 \n", "37 26.0 4 120.3 91 4.43 2.140 16.70 0 \n", "38 30.4 4 95.1 113 3.77 1.513 16.90 1 \n", "39 15.8 8 351.0 264 4.22 3.170 14.50 0 \n", "40 19.7 6 145.0 175 3.62 2.770 15.50 0 \n", "41 15.0 8 301.0 335 3.54 3.570 14.60 0 \n", "42 21.4 4 121.0 109 4.11 2.780 18.60 1 \n", "\n", " am gear carb \n", " \n", "0 1 4 4 \n", "1 1 4 4 \n", "2 1 4 1 \n", "3 0 3 1 \n", "4 0 3 2 \n", "5 0 3 1 \n", "6 0 3 4 \n", "7 0 4 2 \n", "8 0 4 2 \n", "9 0 4 4 \n", "10 0 4 4 \n", "11 0 3 3 \n", "12 0 3 3 \n", "13 0 3 3 \n", "14 0 3 4 \n", "15 0 3 4 \n", "16 0 3 4 \n", "17 1 4 1 \n", "18 1 4 2 \n", "19 1 4 1 \n", "20 0 4 4 \n", "21 0 4 4 \n", "22 0 3 3 \n", "23 0 3 3 \n", "24 0 3 3 \n", "25 0 3 4 \n", "26 0 3 4 \n", "27 0 3 4 \n", "28 1 4 1 \n", "29 1 4 2 \n", "30 1 4 1 \n", "31 0 3 1 \n", "32 0 3 2 \n", "33 0 3 2 \n", "34 0 3 4 \n", "35 0 3 2 \n", "36 1 4 1 \n", "37 1 5 2 \n", "38 1 5 2 \n", "39 1 5 4 \n", "40 1 5 6 \n", "41 1 5 8 \n", "42 1 4 2 " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "union_all(first, second)" ] }, { "cell_type": "code", "execution_count": 7, "id": "8bd44bc8", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:43.464440Z", "iopub.status.busy": "2021-07-16T22:27:43.461787Z", "iopub.status.idle": "2021-07-16T22:27:43.474479Z", "shell.execute_reply": "2021-07-16T22:27:43.472717Z" } }, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "setequal(mtcars, mtcars >> slice(c[::-1]))" ] }, { "cell_type": "code", "execution_count": 8, "id": "e11d56ab", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:43.481956Z", "iopub.status.busy": "2021-07-16T22:27:43.480828Z", "iopub.status.idle": "2021-07-16T22:27:43.654906Z", "shell.execute_reply": "2021-07-16T22:27:43.655357Z" } }, "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", "
column
<int64>
00
11
22
33
44
55
\n", "
\n" ], "text/plain": [ " column\n", " \n", "0 0\n", "1 1\n", "2 2\n", "3 3\n", "4 4\n", "5 5" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = tibble(column=c(*range(11), 10))\n", "b = tibble(column=c(*range(6), 5))\n", "intersect(a, b)" ] }, { "cell_type": "code", "execution_count": 9, "id": "7328ac81", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:43.671067Z", "iopub.status.busy": "2021-07-16T22:27:43.670499Z", "iopub.status.idle": "2021-07-16T22:27:43.681412Z", "shell.execute_reply": "2021-07-16T22:27:43.680573Z" } }, "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", "
column
<int64>
00
11
22
33
44
55
66
77
88
99
1010
\n", "
\n" ], "text/plain": [ " column\n", " \n", "0 0\n", "1 1\n", "2 2\n", "3 3\n", "4 4\n", "5 5\n", "6 6\n", "7 7\n", "8 8\n", "9 9\n", "10 10" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "union(a, b)" ] }, { "cell_type": "code", "execution_count": 10, "id": "d6f95d6e", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:43.703712Z", "iopub.status.busy": "2021-07-16T22:27:43.702882Z", "iopub.status.idle": "2021-07-16T22:27:43.713924Z", "shell.execute_reply": "2021-07-16T22:27:43.714338Z" } }, "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", "
column
<int64>
06
17
28
39
410
\n", "
\n" ], "text/plain": [ " column\n", " \n", "0 6\n", "1 7\n", "2 8\n", "3 9\n", "4 10" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "setdiff(a, b)" ] }, { "cell_type": "code", "execution_count": 11, "id": "9834a5a5", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:43.728734Z", "iopub.status.busy": "2021-07-16T22:27:43.728183Z", "iopub.status.idle": "2021-07-16T22:27:43.737284Z", "shell.execute_reply": "2021-07-16T22:27:43.737663Z" } }, "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", "
column
<int64>
00
11
22
33
44
55
66
77
88
99
1010
1110
120
131
142
153
164
175
185
\n", "
\n" ], "text/plain": [ " column\n", " \n", "0 0\n", "1 1\n", "2 2\n", "3 3\n", "4 4\n", "5 5\n", "6 6\n", "7 7\n", "8 8\n", "9 9\n", "10 10\n", "11 10\n", "12 0\n", "13 1\n", "14 2\n", "15 3\n", "16 4\n", "17 5\n", "18 5" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "union_all(a, b)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/slice.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "687000ba", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:51.388660Z", "iopub.status.busy": "2021-07-16T22:27:51.387866Z", "iopub.status.idle": "2021-07-16T22:27:52.848711Z", "shell.execute_reply": "2021-07-16T22:27:52.849303Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ slice_
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Extract rows by their position\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/slice.html \n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `*args`: Positions to extract. \n", "  `_preserve`: If `True`, keep grouping variables even if they are not used. \n", "\n", "##### Returns:\n", "  The subset dataframe \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ slice_head
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Extract the first rows\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/slice.html \n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `n`: Number of rows to extract. \n", "  `prop`: Proportion of rows to extract. \n", "\n", "##### Returns:\n", "  The subset dataframe \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ slice_max
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Extract rows with the maximum value\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/slice.html \n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `order_by`: A variable or function of variables to order by. \n", "  `n`: Number of rows to extract. \n", "  `prop`: Proportion of rows to extract. \n", "  `with_ties`: If `True`, extract all rows with the maximum value. \n", "    If \"first\", extract the first row with the maximum value. \n", "    If \"last\", extract the last row with the maximum value. \n", "\n", "##### Returns:\n", "  The subset dataframe \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ slice_min
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Extract rows with the minimum value\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/slice.html \n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `order_by`: A variable or function of variables to order by. \n", "  `n`: Number of rows to extract. \n", "  `prop`: Proportion of rows to extract. \n", "  `with_ties`: If `True`, extract all rows with the minimum value. \n", "    If \"first\", extract the first row with the minimum value. \n", "    If \"last\", extract the last row with the minimum value. \n", "\n", "##### Returns:\n", "  The subset dataframe \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ slice_sample
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Extract rows by sampling\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/slice.html \n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `n`: Number of rows to extract. \n", "  `prop`: Proportion of rows to extract. \n", "  `weight_by`: A variable or function of variables to weight by. \n", "  `replace`: If `True`, sample with replacement. \n", "\n", "##### Returns:\n", "  The subset dataframe \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ slice_tail
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Extract the last rows\n", "\n", "The original API: \n", "https://dplyr.tidyverse.org/reference/slice.html \n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `n`: Number of rows to extract. \n", "  `prop`: Proportion of rows to extract. \n", "\n", "##### Returns:\n", "  The subset dataframe \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/slice.html\n", "%run nb_helpers.py\n", "\n", "from datar.data import mtcars\n", "from datar.all import *\n", "\n", "nb_header(slice, slice_head, slice_max, slice_min, slice_sample, slice_tail)" ] }, { "cell_type": "code", "execution_count": 4, "id": "6f4525fc", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:52.855019Z", "iopub.status.busy": "2021-07-16T22:27:52.854440Z", "iopub.status.idle": "2021-07-16T22:27:52.894377Z", "shell.execute_reply": "2021-07-16T22:27:52.892941Z" } }, "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", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Mazda RX421.06160.01103.92.6216.460144
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt qsec \\\n", " \n", "Mazda RX4 21.0 6 160.0 110 3.9 2.62 16.46 \n", "\n", " vs am gear carb \n", " \n", "Mazda RX4 0 1 4 4 " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> slice(0) # 0-based by default" ] }, { "cell_type": "code", "execution_count": 3, "id": "93030877", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:52.918646Z", "iopub.status.busy": "2021-07-16T22:27:52.917763Z", "iopub.status.idle": "2021-07-16T22:27:52.923511Z", "shell.execute_reply": "2021-07-16T22:27:52.924091Z" } }, "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", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Volvo 142E21.44121.01094.112.7818.61142
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt qsec \\\n", " \n", "Volvo 142E 21.4 4 121.0 109 4.11 2.78 18.6 \n", "\n", " vs am gear carb \n", " \n", "Volvo 142E 1 1 4 2 " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> slice(n()-1) # last row" ] }, { "cell_type": "code", "execution_count": 5, "id": "3e1c0360", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:52.943903Z", "iopub.status.busy": "2021-07-16T22:27:52.943084Z", "iopub.status.idle": "2021-07-16T22:27:52.966057Z", "shell.execute_reply": "2021-07-16T22:27:52.967443Z" } }, "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", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Volvo 142E21.44121.01094.112.7818.61142
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt qsec \\\n", " \n", "Volvo 142E 21.4 4 121.0 109 4.11 2.78 18.6 \n", "\n", " vs am gear carb \n", " \n", "Volvo 142E 1 1 4 2 " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# or\n", "mtcars >> slice(-1) " ] }, { "cell_type": "code", "execution_count": 6, "id": "2bed6c2b", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.009902Z", "iopub.status.busy": "2021-07-16T22:27:53.008520Z", "iopub.status.idle": "2021-07-16T22:27:53.019440Z", "shell.execute_reply": "2021-07-16T22:27:53.018355Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Valiant18.16225.01052.763.46020.221031
Duster 36014.38360.02453.213.57015.840034
Merc 240D24.44146.7623.693.19020.001042
Merc 23022.84140.8953.923.15022.901042
Merc 28019.26167.61233.923.44018.301044
Merc 280C17.86167.61233.923.44018.901044
Merc 450SE16.48275.81803.074.07017.400033
Merc 450SL17.38275.81803.073.73017.600033
Merc 450SLC15.28275.81803.073.78018.000033
Cadillac Fleetwood10.48472.02052.935.25017.980034
Lincoln Continental10.48460.02153.005.42417.820034
Chrysler Imperial14.78440.02303.235.34517.420034
Fiat 12832.4478.7664.082.20019.471141
Honda Civic30.4475.7524.931.61518.521142
Toyota Corolla33.9471.1654.221.83519.901141
Toyota Corona21.54120.1973.702.46520.011031
Dodge Challenger15.58318.01502.763.52016.870032
AMC Javelin15.28304.01503.153.43517.300032
Camaro Z2813.38350.02453.733.84015.410034
Pontiac Firebird19.28400.01753.083.84517.050032
Fiat X1-927.3479.0664.081.93518.901141
Porsche 914-226.04120.3914.432.14016.700152
Lotus Europa30.4495.11133.771.51316.901152
Ford Pantera L15.88351.02644.223.17014.500154
Ferrari Dino19.76145.01753.622.77015.500156
Maserati Bora15.08301.03353.543.57014.600158
Volvo 142E21.44121.01094.112.78018.601142
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt \\\n", " \n", "Valiant 18.1 6 225.0 105 2.76 3.460 \n", "Duster 360 14.3 8 360.0 245 3.21 3.570 \n", "Merc 240D 24.4 4 146.7 62 3.69 3.190 \n", "Merc 230 22.8 4 140.8 95 3.92 3.150 \n", "Merc 280 19.2 6 167.6 123 3.92 3.440 \n", "Merc 280C 17.8 6 167.6 123 3.92 3.440 \n", "Merc 450SE 16.4 8 275.8 180 3.07 4.070 \n", "Merc 450SL 17.3 8 275.8 180 3.07 3.730 \n", "Merc 450SLC 15.2 8 275.8 180 3.07 3.780 \n", "Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 \n", "Lincoln Continental 10.4 8 460.0 215 3.00 5.424 \n", "Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 \n", "Fiat 128 32.4 4 78.7 66 4.08 2.200 \n", "Honda Civic 30.4 4 75.7 52 4.93 1.615 \n", "Toyota Corolla 33.9 4 71.1 65 4.22 1.835 \n", "Toyota Corona 21.5 4 120.1 97 3.70 2.465 \n", "Dodge Challenger 15.5 8 318.0 150 2.76 3.520 \n", "AMC Javelin 15.2 8 304.0 150 3.15 3.435 \n", "Camaro Z28 13.3 8 350.0 245 3.73 3.840 \n", "Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 \n", "Fiat X1-9 27.3 4 79.0 66 4.08 1.935 \n", "Porsche 914-2 26.0 4 120.3 91 4.43 2.140 \n", "Lotus Europa 30.4 4 95.1 113 3.77 1.513 \n", "Ford Pantera L 15.8 8 351.0 264 4.22 3.170 \n", "Ferrari Dino 19.7 6 145.0 175 3.62 2.770 \n", "Maserati Bora 15.0 8 301.0 335 3.54 3.570 \n", "Volvo 142E 21.4 4 121.0 109 4.11 2.780 \n", "\n", " qsec vs am gear carb \n", " \n", "Valiant 20.22 1 0 3 1 \n", "Duster 360 15.84 0 0 3 4 \n", "Merc 240D 20.00 1 0 4 2 \n", "Merc 230 22.90 1 0 4 2 \n", "Merc 280 18.30 1 0 4 4 \n", "Merc 280C 18.90 1 0 4 4 \n", "Merc 450SE 17.40 0 0 3 3 \n", "Merc 450SL 17.60 0 0 3 3 \n", "Merc 450SLC 18.00 0 0 3 3 \n", "Cadillac Fleetwood 17.98 0 0 3 4 \n", "Lincoln Continental 17.82 0 0 3 4 \n", "Chrysler Imperial 17.42 0 0 3 4 \n", "Fiat 128 19.47 1 1 4 1 \n", "Honda Civic 18.52 1 1 4 2 \n", "Toyota Corolla 19.90 1 1 4 1 \n", "Toyota Corona 20.01 1 0 3 1 \n", "Dodge Challenger 16.87 0 0 3 2 \n", "AMC Javelin 17.30 0 0 3 2 \n", "Camaro Z28 15.41 0 0 3 4 \n", "Pontiac Firebird 17.05 0 0 3 2 \n", "Fiat X1-9 18.90 1 1 4 1 \n", "Porsche 914-2 16.70 0 1 5 2 \n", "Lotus Europa 16.90 1 1 5 2 \n", "Ford Pantera L 14.50 0 1 5 4 \n", "Ferrari Dino 15.50 0 1 5 6 \n", "Maserati Bora 14.60 0 1 5 8 \n", "Volvo 142E 18.60 1 1 4 2 " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> slice(c[5:])" ] }, { "cell_type": "code", "execution_count": 7, "id": "c07b2866", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.057816Z", "iopub.status.busy": "2021-07-16T22:27:53.057023Z", "iopub.status.idle": "2021-07-16T22:27:53.061578Z", "shell.execute_reply": "2021-07-16T22:27:53.061006Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Hornet Sportabout18.78360.01753.153.44017.020032
Valiant18.16225.01052.763.46020.221031
Duster 36014.38360.02453.213.57015.840034
Merc 240D24.44146.7623.693.19020.001042
Merc 23022.84140.8953.923.15022.901042
Merc 28019.26167.61233.923.44018.301044
Merc 280C17.86167.61233.923.44018.901044
Merc 450SE16.48275.81803.074.07017.400033
Merc 450SL17.38275.81803.073.73017.600033
Merc 450SLC15.28275.81803.073.78018.000033
Cadillac Fleetwood10.48472.02052.935.25017.980034
Lincoln Continental10.48460.02153.005.42417.820034
Chrysler Imperial14.78440.02303.235.34517.420034
Fiat 12832.4478.7664.082.20019.471141
Honda Civic30.4475.7524.931.61518.521142
Toyota Corolla33.9471.1654.221.83519.901141
Toyota Corona21.54120.1973.702.46520.011031
Dodge Challenger15.58318.01502.763.52016.870032
AMC Javelin15.28304.01503.153.43517.300032
Camaro Z2813.38350.02453.733.84015.410034
Pontiac Firebird19.28400.01753.083.84517.050032
Fiat X1-927.3479.0664.081.93518.901141
Porsche 914-226.04120.3914.432.14016.700152
Lotus Europa30.4495.11133.771.51316.901152
Ford Pantera L15.88351.02644.223.17014.500154
Ferrari Dino19.76145.01753.622.77015.500156
Maserati Bora15.08301.03353.543.57014.600158
Volvo 142E21.44121.01094.112.78018.601142
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt \\\n", " \n", "Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 \n", "Valiant 18.1 6 225.0 105 2.76 3.460 \n", "Duster 360 14.3 8 360.0 245 3.21 3.570 \n", "Merc 240D 24.4 4 146.7 62 3.69 3.190 \n", "Merc 230 22.8 4 140.8 95 3.92 3.150 \n", "Merc 280 19.2 6 167.6 123 3.92 3.440 \n", "Merc 280C 17.8 6 167.6 123 3.92 3.440 \n", "Merc 450SE 16.4 8 275.8 180 3.07 4.070 \n", "Merc 450SL 17.3 8 275.8 180 3.07 3.730 \n", "Merc 450SLC 15.2 8 275.8 180 3.07 3.780 \n", "Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 \n", "Lincoln Continental 10.4 8 460.0 215 3.00 5.424 \n", "Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 \n", "Fiat 128 32.4 4 78.7 66 4.08 2.200 \n", "Honda Civic 30.4 4 75.7 52 4.93 1.615 \n", "Toyota Corolla 33.9 4 71.1 65 4.22 1.835 \n", "Toyota Corona 21.5 4 120.1 97 3.70 2.465 \n", "Dodge Challenger 15.5 8 318.0 150 2.76 3.520 \n", "AMC Javelin 15.2 8 304.0 150 3.15 3.435 \n", "Camaro Z28 13.3 8 350.0 245 3.73 3.840 \n", "Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 \n", "Fiat X1-9 27.3 4 79.0 66 4.08 1.935 \n", "Porsche 914-2 26.0 4 120.3 91 4.43 2.140 \n", "Lotus Europa 30.4 4 95.1 113 3.77 1.513 \n", "Ford Pantera L 15.8 8 351.0 264 4.22 3.170 \n", "Ferrari Dino 19.7 6 145.0 175 3.62 2.770 \n", "Maserati Bora 15.0 8 301.0 335 3.54 3.570 \n", "Volvo 142E 21.4 4 121.0 109 4.11 2.780 \n", "\n", " qsec vs am gear carb \n", " \n", "Hornet Sportabout 17.02 0 0 3 2 \n", "Valiant 20.22 1 0 3 1 \n", "Duster 360 15.84 0 0 3 4 \n", "Merc 240D 20.00 1 0 4 2 \n", "Merc 230 22.90 1 0 4 2 \n", "Merc 280 18.30 1 0 4 4 \n", "Merc 280C 18.90 1 0 4 4 \n", "Merc 450SE 17.40 0 0 3 3 \n", "Merc 450SL 17.60 0 0 3 3 \n", "Merc 450SLC 18.00 0 0 3 3 \n", "Cadillac Fleetwood 17.98 0 0 3 4 \n", "Lincoln Continental 17.82 0 0 3 4 \n", "Chrysler Imperial 17.42 0 0 3 4 \n", "Fiat 128 19.47 1 1 4 1 \n", "Honda Civic 18.52 1 1 4 2 \n", "Toyota Corolla 19.90 1 1 4 1 \n", "Toyota Corona 20.01 1 0 3 1 \n", "Dodge Challenger 16.87 0 0 3 2 \n", "AMC Javelin 17.30 0 0 3 2 \n", "Camaro Z28 15.41 0 0 3 4 \n", "Pontiac Firebird 17.05 0 0 3 2 \n", "Fiat X1-9 18.90 1 1 4 1 \n", "Porsche 914-2 16.70 0 1 5 2 \n", "Lotus Europa 16.90 1 1 5 2 \n", "Ford Pantera L 14.50 0 1 5 4 \n", "Ferrari Dino 15.50 0 1 5 6 \n", "Maserati Bora 14.60 0 1 5 8 \n", "Volvo 142E 18.60 1 1 4 2 " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# or\n", "mtcars >> slice(~c[:4])" ] }, { "cell_type": "code", "execution_count": 8, "id": "49170752", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.080629Z", "iopub.status.busy": "2021-07-16T22:27:53.079627Z", "iopub.status.idle": "2021-07-16T22:27:53.086627Z", "shell.execute_reply": "2021-07-16T22:27:53.087171Z" } }, "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", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Ford Pantera L15.88351.02644.223.1714.50154
Volvo 142E21.44121.01094.112.7818.61142
Maserati Bora15.08301.03353.543.5714.60158
Ferrari Dino19.76145.01753.622.7715.50156
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt \\\n", " \n", "Ford Pantera L 15.8 8 351.0 264 4.22 3.17 \n", "Volvo 142E 21.4 4 121.0 109 4.11 2.78 \n", "Maserati Bora 15.0 8 301.0 335 3.54 3.57 \n", "Ferrari Dino 19.7 6 145.0 175 3.62 2.77 \n", "\n", " qsec vs am gear carb \n", " \n", "Ford Pantera L 14.5 0 1 5 4 \n", "Volvo 142E 18.6 1 1 4 2 \n", "Maserati Bora 14.6 0 1 5 8 \n", "Ferrari Dino 15.5 0 1 5 6 " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> slice(-c[:4]) " ] }, { "cell_type": "code", "execution_count": 9, "id": "cd55594c", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.110800Z", "iopub.status.busy": "2021-07-16T22:27:53.110245Z", "iopub.status.idle": "2021-07-16T22:27:53.117621Z", "shell.execute_reply": "2021-07-16T22:27:53.116993Z" } }, "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", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Mazda RX421.06160.01103.902.62016.460144
Mazda RX4 Wag21.06160.01103.902.87517.020144
Datsun 71022.84108.0933.852.32018.611141
Hornet 4 Drive21.46258.01103.083.21519.441031
Hornet Sportabout18.78360.01753.153.44017.020032
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt \\\n", " \n", "Mazda RX4 21.0 6 160.0 110 3.90 2.620 \n", "Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 \n", "Datsun 710 22.8 4 108.0 93 3.85 2.320 \n", "Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 \n", "Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 \n", "\n", " qsec vs am gear carb \n", " \n", "Mazda RX4 16.46 0 1 4 4 \n", "Mazda RX4 Wag 17.02 0 1 4 4 \n", "Datsun 710 18.61 1 1 4 1 \n", "Hornet 4 Drive 19.44 1 0 3 1 \n", "Hornet Sportabout 17.02 0 0 3 2 " ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> slice_head(n=5)" ] }, { "cell_type": "code", "execution_count": 10, "id": "1cef8a7e", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.141804Z", "iopub.status.busy": "2021-07-16T22:27:53.141219Z", "iopub.status.idle": "2021-07-16T22:27:53.145330Z", "shell.execute_reply": "2021-07-16T22:27:53.145692Z" } }, "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", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Lotus Europa30.4495.11133.771.51316.91152
Ford Pantera L15.88351.02644.223.17014.50154
Ferrari Dino19.76145.01753.622.77015.50156
Maserati Bora15.08301.03353.543.57014.60158
Volvo 142E21.44121.01094.112.78018.61142
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt \\\n", " \n", "Lotus Europa 30.4 4 95.1 113 3.77 1.513 \n", "Ford Pantera L 15.8 8 351.0 264 4.22 3.170 \n", "Ferrari Dino 19.7 6 145.0 175 3.62 2.770 \n", "Maserati Bora 15.0 8 301.0 335 3.54 3.570 \n", "Volvo 142E 21.4 4 121.0 109 4.11 2.780 \n", "\n", " qsec vs am gear carb \n", " \n", "Lotus Europa 16.9 1 1 5 2 \n", "Ford Pantera L 14.5 0 1 5 4 \n", "Ferrari Dino 15.5 0 1 5 6 \n", "Maserati Bora 14.6 0 1 5 8 \n", "Volvo 142E 18.6 1 1 4 2 " ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> slice_tail(n=5)" ] }, { "cell_type": "code", "execution_count": 11, "id": "4412e0a9", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.155355Z", "iopub.status.busy": "2021-07-16T22:27:53.154742Z", "iopub.status.idle": "2021-07-16T22:27:53.171005Z", "shell.execute_reply": "2021-07-16T22:27:53.171382Z" } }, "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", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Cadillac Fleetwood10.48472.02052.935.25017.980034
Lincoln Continental10.48460.02153.005.42417.820034
Camaro Z2813.38350.02453.733.84015.410034
Duster 36014.38360.02453.213.57015.840034
Chrysler Imperial14.78440.02303.235.34517.420034
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt \\\n", " \n", "Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 \n", "Lincoln Continental 10.4 8 460.0 215 3.00 5.424 \n", "Camaro Z28 13.3 8 350.0 245 3.73 3.840 \n", "Duster 360 14.3 8 360.0 245 3.21 3.570 \n", "Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 \n", "\n", " qsec vs am gear carb \n", " \n", "Cadillac Fleetwood 17.98 0 0 3 4 \n", "Lincoln Continental 17.82 0 0 3 4 \n", "Camaro Z28 15.41 0 0 3 4 \n", "Duster 360 15.84 0 0 3 4 \n", "Chrysler Imperial 17.42 0 0 3 4 " ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> slice_min(f.mpg, n=5)" ] }, { "cell_type": "code", "execution_count": 12, "id": "ebf401e8", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.191479Z", "iopub.status.busy": "2021-07-16T22:27:53.190665Z", "iopub.status.idle": "2021-07-16T22:27:53.195085Z", "shell.execute_reply": "2021-07-16T22:27:53.195476Z" } }, "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", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Toyota Corolla33.9471.1654.221.83519.901141
Fiat 12832.4478.7664.082.20019.471141
Honda Civic30.4475.7524.931.61518.521142
Lotus Europa30.4495.11133.771.51316.901152
Fiat X1-927.3479.0664.081.93518.901141
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt \\\n", " \n", "Toyota Corolla 33.9 4 71.1 65 4.22 1.835 \n", "Fiat 128 32.4 4 78.7 66 4.08 2.200 \n", "Honda Civic 30.4 4 75.7 52 4.93 1.615 \n", "Lotus Europa 30.4 4 95.1 113 3.77 1.513 \n", "Fiat X1-9 27.3 4 79.0 66 4.08 1.935 \n", "\n", " qsec vs am gear carb \n", " \n", "Toyota Corolla 19.90 1 1 4 1 \n", "Fiat 128 19.47 1 1 4 1 \n", "Honda Civic 18.52 1 1 4 2 \n", "Lotus Europa 16.90 1 1 5 2 \n", "Fiat X1-9 18.90 1 1 4 1 " ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> slice_max(f.mpg, n=5)" ] }, { "cell_type": "code", "execution_count": 13, "id": "b3497c2f", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.221883Z", "iopub.status.busy": "2021-07-16T22:27:53.221344Z", "iopub.status.idle": "2021-07-16T22:27:53.225645Z", "shell.execute_reply": "2021-07-16T22:27:53.225082Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Datsun 71022.84108.0933.852.32018.611141
Merc 240D24.44146.7623.693.19020.001042
Merc 23022.84140.8953.923.15022.901042
Fiat 12832.4478.7664.082.20019.471141
Honda Civic30.4475.7524.931.61518.521142
Toyota Corolla33.9471.1654.221.83519.901141
Toyota Corona21.54120.1973.702.46520.011031
Fiat X1-927.3479.0664.081.93518.901141
Porsche 914-226.04120.3914.432.14016.700152
Lotus Europa30.4495.11133.771.51316.901152
Volvo 142E21.44121.01094.112.78018.601142
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt \\\n", " \n", "Datsun 710 22.8 4 108.0 93 3.85 2.320 \n", "Merc 240D 24.4 4 146.7 62 3.69 3.190 \n", "Merc 230 22.8 4 140.8 95 3.92 3.150 \n", "Fiat 128 32.4 4 78.7 66 4.08 2.200 \n", "Honda Civic 30.4 4 75.7 52 4.93 1.615 \n", "Toyota Corolla 33.9 4 71.1 65 4.22 1.835 \n", "Toyota Corona 21.5 4 120.1 97 3.70 2.465 \n", "Fiat X1-9 27.3 4 79.0 66 4.08 1.935 \n", "Porsche 914-2 26.0 4 120.3 91 4.43 2.140 \n", "Lotus Europa 30.4 4 95.1 113 3.77 1.513 \n", "Volvo 142E 21.4 4 121.0 109 4.11 2.780 \n", "\n", " qsec vs am gear carb \n", " \n", "Datsun 710 18.61 1 1 4 1 \n", "Merc 240D 20.00 1 0 4 2 \n", "Merc 230 22.90 1 0 4 2 \n", "Fiat 128 19.47 1 1 4 1 \n", "Honda Civic 18.52 1 1 4 2 \n", "Toyota Corolla 19.90 1 1 4 1 \n", "Toyota Corona 20.01 1 0 3 1 \n", "Fiat X1-9 18.90 1 1 4 1 \n", "Porsche 914-2 16.70 0 1 5 2 \n", "Lotus Europa 16.90 1 1 5 2 \n", "Volvo 142E 18.60 1 1 4 2 " ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> slice_min(f.cyl, n=1)" ] }, { "cell_type": "code", "execution_count": 14, "id": "7615035a", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.243252Z", "iopub.status.busy": "2021-07-16T22:27:53.242636Z", "iopub.status.idle": "2021-07-16T22:27:53.247446Z", "shell.execute_reply": "2021-07-16T22:27:53.248035Z" } }, "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", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Datsun 71022.84108.0933.852.3218.611141
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt qsec \\\n", " \n", "Datsun 710 22.8 4 108.0 93 3.85 2.32 18.61 \n", "\n", " vs am gear carb \n", " \n", "Datsun 710 1 1 4 1 " ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> slice_min(f.cyl, n=1, with_ties=False)" ] }, { "cell_type": "code", "execution_count": 15, "id": "412dbdf8", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.255281Z", "iopub.status.busy": "2021-07-16T22:27:53.254666Z", "iopub.status.idle": "2021-07-16T22:27:53.269028Z", "shell.execute_reply": "2021-07-16T22:27:53.269431Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Datsun 71022.84108.0933.852.32018.611141
Merc 240D24.44146.7623.693.19020.001042
Merc 23022.84140.8953.923.15022.901042
Fiat 12832.4478.7664.082.20019.471141
Honda Civic30.4475.7524.931.61518.521142
Toyota Corolla33.9471.1654.221.83519.901141
Toyota Corona21.54120.1973.702.46520.011031
Fiat X1-927.3479.0664.081.93518.901141
Porsche 914-226.04120.3914.432.14016.700152
Lotus Europa30.4495.11133.771.51316.901152
Volvo 142E21.44121.01094.112.78018.601142
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt \\\n", " \n", "Datsun 710 22.8 4 108.0 93 3.85 2.320 \n", "Merc 240D 24.4 4 146.7 62 3.69 3.190 \n", "Merc 230 22.8 4 140.8 95 3.92 3.150 \n", "Fiat 128 32.4 4 78.7 66 4.08 2.200 \n", "Honda Civic 30.4 4 75.7 52 4.93 1.615 \n", "Toyota Corolla 33.9 4 71.1 65 4.22 1.835 \n", "Toyota Corona 21.5 4 120.1 97 3.70 2.465 \n", "Fiat X1-9 27.3 4 79.0 66 4.08 1.935 \n", "Porsche 914-2 26.0 4 120.3 91 4.43 2.140 \n", "Lotus Europa 30.4 4 95.1 113 3.77 1.513 \n", "Volvo 142E 21.4 4 121.0 109 4.11 2.780 \n", "\n", " qsec vs am gear carb \n", " \n", "Datsun 710 18.61 1 1 4 1 \n", "Merc 240D 20.00 1 0 4 2 \n", "Merc 230 22.90 1 0 4 2 \n", "Fiat 128 19.47 1 1 4 1 \n", "Honda Civic 18.52 1 1 4 2 \n", "Toyota Corolla 19.90 1 1 4 1 \n", "Toyota Corona 20.01 1 0 3 1 \n", "Fiat X1-9 18.90 1 1 4 1 \n", "Porsche 914-2 16.70 0 1 5 2 \n", "Lotus Europa 16.90 1 1 5 2 \n", "Volvo 142E 18.60 1 1 4 2 " ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> slice_min(f.cyl, n=1, with_ties='last')" ] }, { "cell_type": "code", "execution_count": 16, "id": "f31f199b", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.286560Z", "iopub.status.busy": "2021-07-16T22:27:53.285952Z", "iopub.status.idle": "2021-07-16T22:27:53.290159Z", "shell.execute_reply": "2021-07-16T22:27:53.290729Z" } }, "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", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Merc 240D24.44146.7623.693.19020.001042
Fiat X1-927.3479.0664.081.93518.901141
Datsun 71022.84108.0933.852.32018.611141
Chrysler Imperial14.78440.02303.235.34517.420034
Merc 23022.84140.8953.923.15022.901042
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt \\\n", " \n", "Merc 240D 24.4 4 146.7 62 3.69 3.190 \n", "Fiat X1-9 27.3 4 79.0 66 4.08 1.935 \n", "Datsun 710 22.8 4 108.0 93 3.85 2.320 \n", "Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 \n", "Merc 230 22.8 4 140.8 95 3.92 3.150 \n", "\n", " qsec vs am gear carb \n", " \n", "Merc 240D 20.00 1 0 4 2 \n", "Fiat X1-9 18.90 1 1 4 1 \n", "Datsun 710 18.61 1 1 4 1 \n", "Chrysler Imperial 17.42 0 0 3 4 \n", "Merc 230 22.90 1 0 4 2 " ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> slice_sample(n=5)" ] }, { "cell_type": "code", "execution_count": 17, "id": "04e1ef2a", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.308662Z", "iopub.status.busy": "2021-07-16T22:27:53.295781Z", "iopub.status.idle": "2021-07-16T22:27:53.312132Z", "shell.execute_reply": "2021-07-16T22:27:53.312505Z" } }, "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", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Lotus Europa30.4495.11133.771.51316.91152
Merc 450SL17.38275.81803.073.73017.60033
Porsche 914-226.04120.3914.432.14016.70152
Merc 23022.84140.8953.923.15022.91042
Merc 240D24.44146.7623.693.19020.01042
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt \\\n", " \n", "Lotus Europa 30.4 4 95.1 113 3.77 1.513 \n", "Merc 450SL 17.3 8 275.8 180 3.07 3.730 \n", "Porsche 914-2 26.0 4 120.3 91 4.43 2.140 \n", "Merc 230 22.8 4 140.8 95 3.92 3.150 \n", "Merc 240D 24.4 4 146.7 62 3.69 3.190 \n", "\n", " qsec vs am gear carb \n", " \n", "Lotus Europa 16.9 1 1 5 2 \n", "Merc 450SL 17.6 0 0 3 3 \n", "Porsche 914-2 16.7 0 1 5 2 \n", "Merc 230 22.9 1 0 4 2 \n", "Merc 240D 20.0 1 0 4 2 " ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> slice_sample(n=5, random_state=8525)" ] }, { "cell_type": "code", "execution_count": 18, "id": "46787805", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.329053Z", "iopub.status.busy": "2021-07-16T22:27:53.319160Z", "iopub.status.idle": "2021-07-16T22:27:53.335440Z", "shell.execute_reply": "2021-07-16T22:27:53.334746Z" } }, "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", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Lotus Europa30.4495.11133.771.51316.91152
Merc 450SL17.38275.81803.073.73017.60033
Porsche 914-226.04120.3914.432.14016.70152
Merc 23022.84140.8953.923.15022.91042
Merc 240D24.44146.7623.693.19020.01042
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt \\\n", " \n", "Lotus Europa 30.4 4 95.1 113 3.77 1.513 \n", "Merc 450SL 17.3 8 275.8 180 3.07 3.730 \n", "Porsche 914-2 26.0 4 120.3 91 4.43 2.140 \n", "Merc 230 22.8 4 140.8 95 3.92 3.150 \n", "Merc 240D 24.4 4 146.7 62 3.69 3.190 \n", "\n", " qsec vs am gear carb \n", " \n", "Lotus Europa 16.9 1 1 5 2 \n", "Merc 450SL 17.6 0 0 3 3 \n", "Porsche 914-2 16.7 0 1 5 2 \n", "Merc 230 22.9 1 0 4 2 \n", "Merc 240D 20.0 1 0 4 2 " ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> slice_sample(n=5, random_state=8525)" ] }, { "cell_type": "code", "execution_count": 19, "id": "05b6295f", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.352998Z", "iopub.status.busy": "2021-07-16T22:27:53.352231Z", "iopub.status.idle": "2021-07-16T22:27:53.356989Z", "shell.execute_reply": "2021-07-16T22:27:53.356410Z" } }, "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", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Dodge Challenger15.58318.01502.763.52016.870032
Merc 280C17.86167.61233.923.44018.901044
Dodge Challenger15.58318.01502.763.52016.870032
Chrysler Imperial14.78440.02303.235.34517.420034
Duster 36014.38360.02453.213.57015.840034
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt \\\n", " \n", "Dodge Challenger 15.5 8 318.0 150 2.76 3.520 \n", "Merc 280C 17.8 6 167.6 123 3.92 3.440 \n", "Dodge Challenger 15.5 8 318.0 150 2.76 3.520 \n", "Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 \n", "Duster 360 14.3 8 360.0 245 3.21 3.570 \n", "\n", " qsec vs am gear carb \n", " \n", "Dodge Challenger 16.87 0 0 3 2 \n", "Merc 280C 18.90 1 0 4 4 \n", "Dodge Challenger 16.87 0 0 3 2 \n", "Chrysler Imperial 17.42 0 0 3 4 \n", "Duster 360 15.84 0 0 3 4 " ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> slice_sample(n=5, random_state=8525, replace=True)" ] }, { "cell_type": "code", "execution_count": 20, "id": "15e0a2ec", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.366103Z", "iopub.status.busy": "2021-07-16T22:27:53.363135Z", "iopub.status.idle": "2021-07-16T22:27:53.379310Z", "shell.execute_reply": "2021-07-16T22:27:53.379718Z" } }, "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", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Volvo 142E21.44121.01094.112.78018.601142
Cadillac Fleetwood10.48472.02052.935.25017.980034
Merc 240D24.44146.7623.693.19020.001042
Fiat X1-927.3479.0664.081.93518.901141
Merc 23022.84140.8953.923.15022.901042
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt \\\n", " \n", "Volvo 142E 21.4 4 121.0 109 4.11 2.780 \n", "Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 \n", "Merc 240D 24.4 4 146.7 62 3.69 3.190 \n", "Fiat X1-9 27.3 4 79.0 66 4.08 1.935 \n", "Merc 230 22.8 4 140.8 95 3.92 3.150 \n", "\n", " qsec vs am gear carb \n", " \n", "Volvo 142E 18.60 1 1 4 2 \n", "Cadillac Fleetwood 17.98 0 0 3 4 \n", "Merc 240D 20.00 1 0 4 2 \n", "Fiat X1-9 18.90 1 1 4 1 \n", "Merc 230 22.90 1 0 4 2 " ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> slice_sample(weight_by=f.wt, n=5)" ] }, { "cell_type": "code", "execution_count": 21, "id": "4c70672b", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.388656Z", "iopub.status.busy": "2021-07-16T22:27:53.388004Z", "iopub.status.idle": "2021-07-16T22:27:53.667152Z", "shell.execute_reply": "2021-07-16T22:27:53.667667Z" } }, "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", "
groupx
<object><float64>
0a0.993287
1b0.969380
2b0.450665
3c0.710398
4c0.029497
\n", "
\n", "

TibbleGrouped: group (n=3)" ], "text/plain": [ " group x\n", " \n", "0 a 0.993287\n", "1 b 0.969380\n", "2 b 0.450665\n", "3 c 0.710398\n", "4 c 0.029497\n", "[TibbleGrouped: group (n=3)]" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(\n", " group=['a'] + ['b']*2 + ['c']*4,\n", " x=runif(7)\n", ")\n", "df >> group_by(f.group) >> slice_head(n=2) " ] }, { "cell_type": "code", "execution_count": 22, "id": "28c330c1", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.680330Z", "iopub.status.busy": "2021-07-16T22:27:53.679658Z", "iopub.status.idle": "2021-07-16T22:27:53.705573Z", "shell.execute_reply": "2021-07-16T22:27:53.706286Z" } }, "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", "
groupx
<object><float64>
0b0.969380
1c0.710398
2c0.029497
\n", "
\n", "

TibbleGrouped: group (n=2)" ], "text/plain": [ " group x\n", " \n", "0 b 0.969380\n", "1 c 0.710398\n", "2 c 0.029497\n", "[TibbleGrouped: group (n=2)]" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> group_by(f.group) >> slice_head(prop = 0.5)" ] }, { "cell_type": "code", "execution_count": 23, "id": "3914da22", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.745218Z", "iopub.status.busy": "2021-07-16T22:27:53.744300Z", "iopub.status.idle": "2021-07-16T22:27:53.752877Z", "shell.execute_reply": "2021-07-16T22:27:53.753355Z" } }, "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", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Mazda RX421.06160.01103.92.6216.460144
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt qsec \\\n", " \n", "Mazda RX4 21.0 6 160.0 110 3.9 2.62 16.46 \n", "\n", " vs am gear carb \n", " \n", "Mazda RX4 0 1 4 4 " ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# row_number() is 1-based by default\n", "mtcars >> filter(row_number() == 1) " ] }, { "cell_type": "code", "execution_count": 24, "id": "0e7fd99c", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.774853Z", "iopub.status.busy": "2021-07-16T22:27:53.774008Z", "iopub.status.idle": "2021-07-16T22:27:53.779099Z", "shell.execute_reply": "2021-07-16T22:27:53.779512Z" } }, "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", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Volvo 142E21.44121.01094.112.7818.61142
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt qsec \\\n", " \n", "Volvo 142E 21.4 4 121.0 109 4.11 2.78 18.6 \n", "\n", " vs am gear carb \n", " \n", "Volvo 142E 1 1 4 2 " ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> filter(row_number() == n() )" ] }, { "cell_type": "code", "execution_count": 25, "id": "58792c4c", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.821139Z", "iopub.status.busy": "2021-07-16T22:27:53.820390Z", "iopub.status.idle": "2021-07-16T22:27:53.825821Z", "shell.execute_reply": "2021-07-16T22:27:53.826297Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Mazda RX421.06160.01103.902.62016.460144
Mazda RX4 Wag21.06160.01103.902.87517.020144
Datsun 71022.84108.0933.852.32018.611141
Hornet 4 Drive21.46258.01103.083.21519.441031
Hornet Sportabout18.78360.01753.153.44017.020032
Valiant18.16225.01052.763.46020.221031
Duster 36014.38360.02453.213.57015.840034
Merc 240D24.44146.7623.693.19020.001042
Merc 23022.84140.8953.923.15022.901042
Merc 28019.26167.61233.923.44018.301044
Merc 280C17.86167.61233.923.44018.901044
Merc 450SE16.48275.81803.074.07017.400033
Merc 450SL17.38275.81803.073.73017.600033
Merc 450SLC15.28275.81803.073.78018.000033
Cadillac Fleetwood10.48472.02052.935.25017.980034
Lincoln Continental10.48460.02153.005.42417.820034
Chrysler Imperial14.78440.02303.235.34517.420034
Fiat 12832.4478.7664.082.20019.471141
Honda Civic30.4475.7524.931.61518.521142
Toyota Corolla33.9471.1654.221.83519.901141
Toyota Corona21.54120.1973.702.46520.011031
Dodge Challenger15.58318.01502.763.52016.870032
AMC Javelin15.28304.01503.153.43517.300032
Camaro Z2813.38350.02453.733.84015.410034
Pontiac Firebird19.28400.01753.083.84517.050032
Fiat X1-927.3479.0664.081.93518.901141
Porsche 914-226.04120.3914.432.14016.700152
Lotus Europa30.4495.11133.771.51316.901152
Ford Pantera L15.88351.02644.223.17014.500154
Ferrari Dino19.76145.01753.622.77015.500156
Maserati Bora15.08301.03353.543.57014.600158
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt \\\n", " \n", "Mazda RX4 21.0 6 160.0 110 3.90 2.620 \n", "Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 \n", "Datsun 710 22.8 4 108.0 93 3.85 2.320 \n", "Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 \n", "Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 \n", "Valiant 18.1 6 225.0 105 2.76 3.460 \n", "Duster 360 14.3 8 360.0 245 3.21 3.570 \n", "Merc 240D 24.4 4 146.7 62 3.69 3.190 \n", "Merc 230 22.8 4 140.8 95 3.92 3.150 \n", "Merc 280 19.2 6 167.6 123 3.92 3.440 \n", "Merc 280C 17.8 6 167.6 123 3.92 3.440 \n", "Merc 450SE 16.4 8 275.8 180 3.07 4.070 \n", "Merc 450SL 17.3 8 275.8 180 3.07 3.730 \n", "Merc 450SLC 15.2 8 275.8 180 3.07 3.780 \n", "Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 \n", "Lincoln Continental 10.4 8 460.0 215 3.00 5.424 \n", "Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 \n", "Fiat 128 32.4 4 78.7 66 4.08 2.200 \n", "Honda Civic 30.4 4 75.7 52 4.93 1.615 \n", "Toyota Corolla 33.9 4 71.1 65 4.22 1.835 \n", "Toyota Corona 21.5 4 120.1 97 3.70 2.465 \n", "Dodge Challenger 15.5 8 318.0 150 2.76 3.520 \n", "AMC Javelin 15.2 8 304.0 150 3.15 3.435 \n", "Camaro Z28 13.3 8 350.0 245 3.73 3.840 \n", "Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 \n", "Fiat X1-9 27.3 4 79.0 66 4.08 1.935 \n", "Porsche 914-2 26.0 4 120.3 91 4.43 2.140 \n", "Lotus Europa 30.4 4 95.1 113 3.77 1.513 \n", "Ford Pantera L 15.8 8 351.0 264 4.22 3.170 \n", "Ferrari Dino 19.7 6 145.0 175 3.62 2.770 \n", "Maserati Bora 15.0 8 301.0 335 3.54 3.570 \n", "\n", " qsec vs am gear carb \n", " \n", "Mazda RX4 16.46 0 1 4 4 \n", "Mazda RX4 Wag 17.02 0 1 4 4 \n", "Datsun 710 18.61 1 1 4 1 \n", "Hornet 4 Drive 19.44 1 0 3 1 \n", "Hornet Sportabout 17.02 0 0 3 2 \n", "Valiant 20.22 1 0 3 1 \n", "Duster 360 15.84 0 0 3 4 \n", "Merc 240D 20.00 1 0 4 2 \n", "Merc 230 22.90 1 0 4 2 \n", "Merc 280 18.30 1 0 4 4 \n", "Merc 280C 18.90 1 0 4 4 \n", "Merc 450SE 17.40 0 0 3 3 \n", "Merc 450SL 17.60 0 0 3 3 \n", "Merc 450SLC 18.00 0 0 3 3 \n", "Cadillac Fleetwood 17.98 0 0 3 4 \n", "Lincoln Continental 17.82 0 0 3 4 \n", "Chrysler Imperial 17.42 0 0 3 4 \n", "Fiat 128 19.47 1 1 4 1 \n", "Honda Civic 18.52 1 1 4 2 \n", "Toyota Corolla 19.90 1 1 4 1 \n", "Toyota Corona 20.01 1 0 3 1 \n", "Dodge Challenger 16.87 0 0 3 2 \n", "AMC Javelin 17.30 0 0 3 2 \n", "Camaro Z28 15.41 0 0 3 4 \n", "Pontiac Firebird 17.05 0 0 3 2 \n", "Fiat X1-9 18.90 1 1 4 1 \n", "Porsche 914-2 16.70 0 1 5 2 \n", "Lotus Europa 16.90 1 1 5 2 \n", "Ford Pantera L 14.50 0 1 5 4 \n", "Ferrari Dino 15.50 0 1 5 6 \n", "Maserati Bora 14.60 0 1 5 8 " ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> filter(5 <= row_number() < n()) # cannot filter" ] }, { "cell_type": "code", "execution_count": 26, "id": "7dc416a2", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:53.841148Z", "iopub.status.busy": "2021-07-16T22:27:53.840428Z", "iopub.status.idle": "2021-07-16T22:27:54.095942Z", "shell.execute_reply": "2021-07-16T22:27:54.098637Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
mpgcyldisphpdratwtqsecvsamgearcarb
<float64><int64><float64><int64><float64><float64><float64><int64><int64><int64><int64>
Hornet Sportabout18.78360.01753.153.44017.020032
Valiant18.16225.01052.763.46020.221031
Duster 36014.38360.02453.213.57015.840034
Merc 240D24.44146.7623.693.19020.001042
Merc 23022.84140.8953.923.15022.901042
Merc 28019.26167.61233.923.44018.301044
Merc 280C17.86167.61233.923.44018.901044
Merc 450SE16.48275.81803.074.07017.400033
Merc 450SL17.38275.81803.073.73017.600033
Merc 450SLC15.28275.81803.073.78018.000033
Cadillac Fleetwood10.48472.02052.935.25017.980034
Lincoln Continental10.48460.02153.005.42417.820034
Chrysler Imperial14.78440.02303.235.34517.420034
Fiat 12832.4478.7664.082.20019.471141
Honda Civic30.4475.7524.931.61518.521142
Toyota Corolla33.9471.1654.221.83519.901141
Toyota Corona21.54120.1973.702.46520.011031
Dodge Challenger15.58318.01502.763.52016.870032
AMC Javelin15.28304.01503.153.43517.300032
Camaro Z2813.38350.02453.733.84015.410034
Pontiac Firebird19.28400.01753.083.84517.050032
Fiat X1-927.3479.0664.081.93518.901141
Porsche 914-226.04120.3914.432.14016.700152
Lotus Europa30.4495.11133.771.51316.901152
Ford Pantera L15.88351.02644.223.17014.500154
Ferrari Dino19.76145.01753.622.77015.500156
Maserati Bora15.08301.03353.543.57014.600158
Volvo 142E21.44121.01094.112.78018.601142
\n", "
\n" ], "text/plain": [ " mpg cyl disp hp drat wt \\\n", " \n", "Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 \n", "Valiant 18.1 6 225.0 105 2.76 3.460 \n", "Duster 360 14.3 8 360.0 245 3.21 3.570 \n", "Merc 240D 24.4 4 146.7 62 3.69 3.190 \n", "Merc 230 22.8 4 140.8 95 3.92 3.150 \n", "Merc 280 19.2 6 167.6 123 3.92 3.440 \n", "Merc 280C 17.8 6 167.6 123 3.92 3.440 \n", "Merc 450SE 16.4 8 275.8 180 3.07 4.070 \n", "Merc 450SL 17.3 8 275.8 180 3.07 3.730 \n", "Merc 450SLC 15.2 8 275.8 180 3.07 3.780 \n", "Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 \n", "Lincoln Continental 10.4 8 460.0 215 3.00 5.424 \n", "Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 \n", "Fiat 128 32.4 4 78.7 66 4.08 2.200 \n", "Honda Civic 30.4 4 75.7 52 4.93 1.615 \n", "Toyota Corolla 33.9 4 71.1 65 4.22 1.835 \n", "Toyota Corona 21.5 4 120.1 97 3.70 2.465 \n", "Dodge Challenger 15.5 8 318.0 150 2.76 3.520 \n", "AMC Javelin 15.2 8 304.0 150 3.15 3.435 \n", "Camaro Z28 13.3 8 350.0 245 3.73 3.840 \n", "Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 \n", "Fiat X1-9 27.3 4 79.0 66 4.08 1.935 \n", "Porsche 914-2 26.0 4 120.3 91 4.43 2.140 \n", "Lotus Europa 30.4 4 95.1 113 3.77 1.513 \n", "Ford Pantera L 15.8 8 351.0 264 4.22 3.170 \n", "Ferrari Dino 19.7 6 145.0 175 3.62 2.770 \n", "Maserati Bora 15.0 8 301.0 335 3.54 3.570 \n", "Volvo 142E 21.4 4 121.0 109 4.11 2.780 \n", "\n", " qsec vs am gear carb \n", " \n", "Hornet Sportabout 17.02 0 0 3 2 \n", "Valiant 20.22 1 0 3 1 \n", "Duster 360 15.84 0 0 3 4 \n", "Merc 240D 20.00 1 0 4 2 \n", "Merc 230 22.90 1 0 4 2 \n", "Merc 280 18.30 1 0 4 4 \n", "Merc 280C 18.90 1 0 4 4 \n", "Merc 450SE 17.40 0 0 3 3 \n", "Merc 450SL 17.60 0 0 3 3 \n", "Merc 450SLC 18.00 0 0 3 3 \n", "Cadillac Fleetwood 17.98 0 0 3 4 \n", "Lincoln Continental 17.82 0 0 3 4 \n", "Chrysler Imperial 17.42 0 0 3 4 \n", "Fiat 128 19.47 1 1 4 1 \n", "Honda Civic 18.52 1 1 4 2 \n", "Toyota Corolla 19.90 1 1 4 1 \n", "Toyota Corona 20.01 1 0 3 1 \n", "Dodge Challenger 16.87 0 0 3 2 \n", "AMC Javelin 17.30 0 0 3 2 \n", "Camaro Z28 15.41 0 0 3 4 \n", "Pontiac Firebird 17.05 0 0 3 2 \n", "Fiat X1-9 18.90 1 1 4 1 \n", "Porsche 914-2 16.70 0 1 5 2 \n", "Lotus Europa 16.90 1 1 5 2 \n", "Ford Pantera L 14.50 0 1 5 4 \n", "Ferrari Dino 15.50 0 1 5 6 \n", "Maserati Bora 14.60 0 1 5 8 \n", "Volvo 142E 18.60 1 1 4 2 " ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> filter(between(row_number(), 5, n()))" ] }, { "cell_type": "code", "execution_count": 27, "id": "65b00ace", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:54.226219Z", "iopub.status.busy": "2021-07-16T22:27:54.225422Z", "iopub.status.idle": "2021-07-16T22:27:54.337352Z", "shell.execute_reply": "2021-07-16T22:27:54.338233Z" } }, "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", "
groupx
<object><float64>
0a0.068146
1a0.418989
2b0.047916
3b0.054781
4c0.000433
5c0.010472
\n", "
\n", "

TibbleGrouped: group (n=3)" ], "text/plain": [ " group x\n", " \n", "0 a 0.068146\n", "1 a 0.418989\n", "2 b 0.047916\n", "3 b 0.054781\n", "4 c 0.000433\n", "5 c 0.010472\n", "[TibbleGrouped: group (n=3)]" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(\n", " group=['a']*10 + ['b']*20 + ['c']*40,\n", " x=runif(70)\n", ")\n", "df >> group_by(f.group) >> slice_min(f.x, 2)" ] }, { "cell_type": "code", "execution_count": 28, "id": "897476cf", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:54.455605Z", "iopub.status.busy": "2021-07-16T22:27:54.454822Z", "iopub.status.idle": "2021-07-16T22:27:54.479309Z", "shell.execute_reply": "2021-07-16T22:27:54.479835Z" } }, "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", "
groupx
<object><float64>
0a0.985698
1a0.712850
2b0.993662
3b0.985569
4c0.994279
5c0.966813
\n", "
\n", "

TibbleGrouped: group (n=3)" ], "text/plain": [ " group x\n", " \n", "0 a 0.985698\n", "1 a 0.712850\n", "2 b 0.993662\n", "3 b 0.985569\n", "4 c 0.994279\n", "5 c 0.966813\n", "[TibbleGrouped: group (n=3)]" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> group_by(f.group) >> slice_max(f.x, 2)" ] }, { "cell_type": "code", "execution_count": 29, "id": "887f2625", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:54.560420Z", "iopub.status.busy": "2021-07-16T22:27:54.558166Z", "iopub.status.idle": "2021-07-16T22:27:54.635454Z", "shell.execute_reply": "2021-07-16T22:27:54.636608Z" } }, "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", "
groupx
<object><float64>
0a0.636650
1a0.068146
2b0.058098
3b0.847180
4c0.743841
5c0.010472
\n", "
\n", "

TibbleGrouped: group (n=3)" ], "text/plain": [ " group x\n", " \n", "0 a 0.636650\n", "1 a 0.068146\n", "2 b 0.058098\n", "3 b 0.847180\n", "4 c 0.743841\n", "5 c 0.010472\n", "[TibbleGrouped: group (n=3)]" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> group_by(f.group) >> slice_sample(2)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/summarise.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "4ba9dd17", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:30.653194Z", "iopub.status.busy": "2021-07-16T22:27:30.652556Z", "iopub.status.idle": "2021-07-16T22:27:33.410785Z", "shell.execute_reply": "2021-07-16T22:27:33.411264Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ summarise
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Summarise a data frame.\n", "\n", "See original API \n", "https://dplyr.tidyverse.org/reference/summarise.html \n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `_groups`: Grouping structure of the result. \n", "    - \"drop_last\": dropping the last level of grouping. \n", "\n", "    - \"drop\": All levels of grouping are dropped. \n", "\n", "    - \"keep\": Same grouping structure as _data. \n", "\n", "    - \"rowwise\": Each row is its own group. \n", "\n", "  `*args`: and \n", "  `**kwargs`: Name-value pairs, where value is the summarized \n", "    data for each group \n", "\n", "##### Returns:\n", "  A data frame with the summarised columns \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/summarise.html\n", "%run nb_helpers.py\n", "\n", "from datar.data import mtcars, starwars\n", "from datar.all import *\n", "\n", "nb_header(summarise)" ] }, { "cell_type": "code", "execution_count": 8, "id": "193d02c5", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:33.468439Z", "iopub.status.busy": "2021-07-16T22:27:33.465218Z", "iopub.status.idle": "2021-07-16T22:27:33.487717Z", "shell.execute_reply": "2021-07-16T22:27:33.490086Z" } }, "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", "
meann
<float64><int64>
0230.72187532
\n", "
\n" ], "text/plain": [ " mean n\n", " \n", "0 230.721875 32" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> summarise(mean=mean(f.disp), n=n())" ] }, { "cell_type": "code", "execution_count": null, "id": "0f48dddc", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:33.498734Z", "iopub.status.busy": "2021-07-16T22:27:33.497950Z", "iopub.status.idle": "2021-07-16T22:27:33.637631Z", "shell.execute_reply": "2021-07-16T22:27:33.638084Z" } }, "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", "
cylmeann
<int64><float64><int64>
06183.3142867
14105.13636411
28353.10000014
\n", "
\n" ], "text/plain": [ " cyl mean n\n", " \n", "0 6 183.314286 7\n", "1 4 105.136364 11\n", "2 8 353.100000 14" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> \\\n", " group_by(f.cyl) >> \\\n", " summarise(mean=mean(f.disp), n=n())" ] }, { "cell_type": "code", "execution_count": null, "id": "96d1660d", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:33.678462Z", "iopub.status.busy": "2021-07-16T22:27:33.677889Z", "iopub.status.idle": "2021-07-16T22:27:33.723973Z", "shell.execute_reply": "2021-07-16T22:27:33.724468Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 14:46:41][datar][ INFO] `summarise()` has grouped output by ['cyl'] (override with `_groups` argument)\n" ] }, { "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", "
cylqsprob
<int64><object><float64>
06[160.0, 196.3]0.25
16[160.0, 196.3]0.75
24[78.85, 120.65]0.25
34[78.85, 120.65]0.75
48[301.75, 390.0]0.25
58[301.75, 390.0]0.75
\n", "
\n", "

TibbleGrouped: cyl (n=3)" ], "text/plain": [ " cyl qs prob\n", " \n", "0 6 [160.0, 196.3] 0.25\n", "1 6 [160.0, 196.3] 0.75\n", "2 4 [78.85, 120.65] 0.25\n", "3 4 [78.85, 120.65] 0.75\n", "4 8 [301.75, 390.0] 0.25\n", "5 8 [301.75, 390.0] 0.75\n", "[TibbleGrouped: cyl (n=3)]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> \\\n", " group_by(f.cyl) >> \\\n", " summarise(qs=quantile(f.disp, c(0.25, 0.75)), prob=c(0.25, 0.75))\n" ] }, { "cell_type": "code", "execution_count": null, "id": "4e64de5a", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:33.770702Z", "iopub.status.busy": "2021-07-16T22:27:33.770156Z", "iopub.status.idle": "2021-07-16T22:27:33.777651Z", "shell.execute_reply": "2021-07-16T22:27:33.778278Z" } }, "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", "
cylqsprob
<int64><object><float64>
06[160.0, 196.3]0.25
16[160.0, 196.3]0.75
24[78.85, 120.65]0.25
34[78.85, 120.65]0.75
48[301.75, 390.0]0.25
58[301.75, 390.0]0.75
\n", "
\n", "

TibbleGrouped: cyl (n=3)" ], "text/plain": [ " cyl qs prob\n", " \n", "0 6 [160.0, 196.3] 0.25\n", "1 6 [160.0, 196.3] 0.75\n", "2 4 [78.85, 120.65] 0.25\n", "3 4 [78.85, 120.65] 0.75\n", "4 8 [301.75, 390.0] 0.25\n", "5 8 [301.75, 390.0] 0.75\n", "[TibbleGrouped: cyl (n=3)]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "with options_context(dplyr_summarise_inform=False):\n", " mtcars >> \\\n", " group_by(f.cyl) >> \\\n", " summarise(qs=quantile(f.disp, c(0.25, 0.75)), prob=c(0.25, 0.75))\n" ] }, { "cell_type": "code", "execution_count": 4, "id": "e5098761", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:34.152815Z", "iopub.status.busy": "2021-07-16T22:27:34.150055Z", "iopub.status.idle": "2021-07-16T22:27:34.225066Z", "shell.execute_reply": "2021-07-16T22:27:34.225477Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 14:46:52][datar][ INFO] `summarise()` has grouped output by ['cyl'] (override with `_groups` argument)\n" ] }, { "data": { "text/plain": [ "['cyl']" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mtcars >> \\\n", " group_by(f.cyl, f.vs) >> \\\n", " summarise(cyl_n = n()) >> \\\n", " group_vars()" ] }, { "cell_type": "code", "execution_count": null, "id": "01a62149", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:34.254608Z", "iopub.status.busy": "2021-07-16T22:27:34.253050Z", "iopub.status.idle": "2021-07-16T22:27:34.259957Z", "shell.execute_reply": "2021-07-16T22:27:34.260364Z" } }, "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", "
cyldispsd
<int64><float64><float64>
06183.314286NaN
14105.136364NaN
28353.100000NaN
\n", "
\n" ], "text/plain": [ " cyl disp sd\n", " \n", "0 6 183.314286 NaN\n", "1 4 105.136364 NaN\n", "2 8 353.100000 NaN" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Unlike dplyr's summarise, f.disp can be reused.\n", "mtcars >> \\\n", " group_by(f.cyl) >> \\\n", " summarise(disp=mean(f.disp), sd=sd(f.disp))" ] }, { "cell_type": "code", "execution_count": null, "id": "d2f97ff6", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:34.297444Z", "iopub.status.busy": "2021-07-16T22:27:34.296691Z", "iopub.status.idle": "2021-07-16T22:27:34.306716Z", "shell.execute_reply": "2021-07-16T22:27:34.307142Z" } }, "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", "
cyldisp_m2
<int64><float64>
06366.628571
14210.272727
28706.200000
\n", "
\n" ], "text/plain": [ " cyl disp_m2\n", " \n", "0 6 366.628571\n", "1 4 210.272727\n", "2 8 706.200000" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Create temporary variable\n", "mtcars >> \\\n", " group_by(f.cyl) >> \\\n", " summarise(_disp_m2=mean(f.disp), disp_m2=f._disp_m2 * 2)" ] }, { "cell_type": "code", "execution_count": 8, "id": "f4bd8382", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:34.322222Z", "iopub.status.busy": "2021-07-16T22:27:34.321493Z", "iopub.status.idle": "2021-07-16T22:27:34.328938Z", "shell.execute_reply": "2021-07-16T22:27:34.329394Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
avg
<float64>
097.311864
\n", "
\n" ], "text/plain": [ " avg\n", " \n", "0 97.311864" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "var = \"mass\"\n", "starwars >> summarise(avg = mean(f[var]))" ] } ], "metadata": { "kernelspec": { "display_name": "datar-TA_GutPO-py3.12", "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.12.2" } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/tibble.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 2, "id": "8b02806d", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:10.487937Z", "iopub.status.busy": "2021-07-16T22:28:10.487068Z", "iopub.status.idle": "2021-07-16T22:28:11.408146Z", "shell.execute_reply": "2021-07-16T22:28:11.408553Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ tibble
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Constructs a data frame\n", "\n", "##### Args:\n", "  `*args`: and \n", "  `**kwargs`: A set of name-value pairs. \n", "  `_name_repair`: treatment of problematic column names: \n", "    - \"minimal\": No name repair or checks, beyond basic existence,\n", "\n", "    - \"unique\": Make sure names are unique and not empty,\n", "\n", "    - \"check_unique\": (default value), no name repair,\n", "      but check they are unique, \n", "\n", "    - \"universal\": Make the names unique and syntactic\n", "\n", "    - a function: apply custom name repair\n", "\n", "  `_rows`: Number of rows of a 0-col dataframe when args and kwargs are \n", "    not provided. When args or kwargs are provided, this is ignored. \n", "\n", "  `_dtypes`: The dtypes for each columns to convert to. \n", "  `_drop_index`: Whether drop the index for the final data frame \n", "  `_index`: The new index of the output frame \n", "\n", "##### Returns:\n", "  A constructed tibble \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ tibble_row
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Constructs a data frame that is guaranteed to occupy one row.\n", "Scalar values will be wrapped with `[]` \n", "\n", "##### Args:\n", "  `*args`: and \n", "  `**kwargs`: A set of name-value pairs. \n", "  `_name_repair`: treatment of problematic column names: \n", "    - \"minimal\": No name repair or checks, beyond basic existence,\n", "\n", "    - \"unique\": Make sure names are unique and not empty,\n", "\n", "    - \"check_unique\": (default value), no name repair,\n", "      but check they are unique, \n", "\n", "    - \"universal\": Make the names unique and syntactic\n", "\n", "    - a function: apply custom name repair\n", "\n", "##### Returns:\n", "  A constructed dataframe \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ tribble
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Create dataframe using an easier to read row-by-row layout\n", "Unlike original API that uses formula (`f.col`) to indicate the column \n", "names, we use `f.col` to indicate them. \n", "\n", "##### Args:\n", "  `*dummies`: Arguments specifying the structure of a dataframe \n", "    Variable names should be specified with `f.name` \n", "\n", "  `_dtypes`: The dtypes for each columns to convert to. \n", "\n", "##### Returns:\n", "  A dataframe \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://tibble.tidyverse.org/reference/tibble.html\n", "# https://tibble.tidyverse.org/reference/tribble.html\n", "%run nb_helpers.py\n", "\n", "from datar import f\n", "from datar.tibble import tibble, tibble_row, tribble\n", "from datar.base import diag, runif\n", "from datar.dplyr import mutate\n", "\n", "nb_header(tibble, tibble_row, tribble)" ] }, { "cell_type": "code", "execution_count": 3, "id": "a786d6b2", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:11.415801Z", "iopub.status.busy": "2021-07-16T22:28:11.415073Z", "iopub.status.idle": "2021-07-16T22:28:11.553606Z", "shell.execute_reply": "2021-07-16T22:28:11.552951Z" } }, "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", "
ab
<int64><int64>
000
112
224
336
448
\n", "
\n" ], "text/plain": [ " a b\n", " \n", "0 0 0\n", "1 1 2\n", "2 2 4\n", "3 3 6\n", "4 4 8" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = range(5)\n", "tibble(a=a, b=f.a*2)" ] }, { "cell_type": "code", "execution_count": 4, "id": "875fe6f2", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:11.560578Z", "iopub.status.busy": "2021-07-16T22:28:11.558571Z", "iopub.status.idle": "2021-07-16T22:28:11.583056Z", "shell.execute_reply": "2021-07-16T22:28:11.583527Z" } }, "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", "
abc
<int64><int64><int64>
0001
1121
2241
3361
4481
\n", "
\n" ], "text/plain": [ " a b c\n", " \n", "0 0 0 1\n", "1 1 2 1\n", "2 2 4 1\n", "3 3 6 1\n", "4 4 8 1" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tibble(a=a, b=f.a * 2, c=1)" ] }, { "cell_type": "code", "execution_count": 5, "id": "fc39e6d2", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:11.589246Z", "iopub.status.busy": "2021-07-16T22:28:11.588647Z", "iopub.status.idle": "2021-07-16T22:28:11.607914Z", "shell.execute_reply": "2021-07-16T22:28:11.608285Z" } }, "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", "
xy
<float64><float64>
00.6395111.279022
10.5738881.147776
20.1234710.246943
30.8072061.614412
40.1591200.318241
50.8936971.787394
60.8975841.795168
70.1597800.319559
80.9197171.839433
90.3045610.609122
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 0.639511 1.279022\n", "1 0.573888 1.147776\n", "2 0.123471 0.246943\n", "3 0.807206 1.614412\n", "4 0.159120 0.318241\n", "5 0.893697 1.787394\n", "6 0.897584 1.795168\n", "7 0.159780 0.319559\n", "8 0.919717 1.839433\n", "9 0.304561 0.609122" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tibble(x=runif(10), y=f.x*2)" ] }, { "cell_type": "code", "execution_count": 6, "id": "dada58f8", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:11.620997Z", "iopub.status.busy": "2021-07-16T22:28:11.615155Z", "iopub.status.idle": "2021-07-16T22:28:11.625329Z", "shell.execute_reply": "2021-07-16T22:28:11.625705Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[NameNonUniqueError] Names must be unique: 1\n" ] } ], "source": [ "x = 1\n", "with try_catch():\n", " tibble(x, x)" ] }, { "cell_type": "code", "execution_count": 7, "id": "8a22cb4b", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:11.632085Z", "iopub.status.busy": "2021-07-16T22:28:11.631328Z", "iopub.status.idle": "2021-07-16T22:28:11.653232Z", "shell.execute_reply": "2021-07-16T22:28:11.653724Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 14:48:49][datar][WARNING] New names:\n", "[2022-12-02 14:48:49][datar][WARNING] * '1' -> '1__0'\n", "[2022-12-02 14:48:49][datar][WARNING] * '1' -> '1__1'\n" ] }, { "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", "
1__01__1
<int64><int64>
011
\n", "
\n" ], "text/plain": [ " 1__0 1__1\n", " \n", "0 1 1" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tibble(x, x, _name_repair=\"unique\")" ] }, { "cell_type": "code", "execution_count": 8, "id": "6007cacc", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:11.705803Z", "iopub.status.busy": "2021-07-16T22:28:11.705211Z", "iopub.status.idle": "2021-07-16T22:28:11.709633Z", "shell.execute_reply": "2021-07-16T22:28:11.710113Z" } }, "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", "
11
<int64><int64>
011
\n", "
\n" ], "text/plain": [ " 1 1\n", " \n", "0 1 1" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tibble(x, x, _name_repair=\"minimal\") # duplicated columns allowed" ] }, { "cell_type": "code", "execution_count": 9, "id": "aadc8985", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:11.725364Z", "iopub.status.busy": "2021-07-16T22:28:11.724805Z", "iopub.status.idle": "2021-07-16T22:28:11.746001Z", "shell.execute_reply": "2021-07-16T22:28:11.746392Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 14:49:00][datar][WARNING] New names:\n", "[2022-12-02 14:49:00][datar][WARNING] * '1' -> '_1'\n", "[2022-12-02 14:49:00][datar][WARNING] * '2' -> '_2'\n" ] }, { "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", "
_1_2
<int64><int64>
012
\n", "
\n" ], "text/plain": [ " _1 _2\n", " \n", "0 1 2" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = 1\n", "tibble(a * 1, a * 2, _name_repair=\"universal\")" ] }, { "cell_type": "code", "execution_count": 10, "id": "7a863e15", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:11.772009Z", "iopub.status.busy": "2021-07-16T22:28:11.771418Z", "iopub.status.idle": "2021-07-16T22:28:11.782345Z", "shell.execute_reply": "2021-07-16T22:28:11.782803Z" } }, "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", "
11_1
<int64><int64>
011
\n", "
\n" ], "text/plain": [ " 1 1_1\n", " \n", "0 1 1" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from typing import Iterable\n", "# use annotation to tell it's all names\n", "# not only a single name\n", "def make_unique(names: Iterable[str]): \n", " new_names = []\n", " for name in names:\n", " name_count = new_names.count(name)\n", " if name_count == 0:\n", " new_names.append(name)\n", " else:\n", " new_names.append(f'{name}_{name_count}')\n", " return new_names\n", "\n", "tibble(a, a, _name_repair=make_unique)" ] }, { "cell_type": "code", "execution_count": 11, "id": "c76a319b", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:11.806211Z", "iopub.status.busy": "2021-07-16T22:28:11.805521Z", "iopub.status.idle": "2021-07-16T22:28:11.821359Z", "shell.execute_reply": "2021-07-16T22:28:11.821905Z" } }, "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", "
23
<int64><int64>
023
\n", "
\n" ], "text/plain": [ " 2 3\n", " \n", "0 2 3" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# if not annotation specified\n", "# assuming a single name\n", "def fix_names(name):\n", " import re\n", " return re.sub(r'\\s+', '_', name)\n", "\n", "\n", "tibble(a + 1, a + 2, _name_repair = fix_names)" ] }, { "cell_type": "code", "execution_count": 12, "id": "20cff9a2", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:11.880394Z", "iopub.status.busy": "2021-07-16T22:28:11.879447Z", "iopub.status.idle": "2021-07-16T22:28:11.899118Z", "shell.execute_reply": "2021-07-16T22:28:11.898664Z" } }, "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", "
ab
<int64><int64>
011
\n", "
\n" ], "text/plain": [ " a b\n", " \n", "0 1 1" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tibble(x, x, _name_repair=[\"a\", \"b\"])" ] }, { "cell_type": "code", "execution_count": 13, "id": "7e006c14", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:11.922711Z", "iopub.status.busy": "2021-07-16T22:28:11.922043Z", "iopub.status.idle": "2021-07-16T22:28:11.950480Z", "shell.execute_reply": "2021-07-16T22:28:11.950869Z" } }, "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", "
bcad
<int64><int64><int64><int64>
04704
15815
26926
\n", "
\n" ], "text/plain": [ " b c a d\n", " \n", "0 4 7 0 4\n", "1 5 8 1 5\n", "2 6 9 2 6" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tibble(\n", " tibble(\n", " b = [4,5,6],\n", " c = [7,8,9]\n", " ),\n", " a = range(3),\n", " d = f.b\n", ")" ] }, { "cell_type": "code", "execution_count": 14, "id": "2d9a00e0", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:11.969013Z", "iopub.status.busy": "2021-07-16T22:28:11.968444Z", "iopub.status.idle": "2021-07-16T22:28:12.016367Z", "shell.execute_reply": "2021-07-16T22:28:12.016822Z" } }, "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", "
ab$0b$1b$2b$3c$x$0c$x$1
<int64><int64><int64><int64><int64><int64><int64>
00100010
11010001
22001000
33000100
\n", "
\n" ], "text/plain": [ " a b$0 b$1 b$2 b$3 c$x$0 c$x$1\n", " \n", "0 0 1 0 0 0 1 0\n", "1 1 0 1 0 0 0 1\n", "2 2 0 0 1 0 0 0\n", "3 3 0 0 0 1 0 0" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s = tibble(diag(1, 4))\n", "t = tibble(s.iloc[:, :2], _name_repair=['x', 'y'])\n", "tibble(\n", " a=range(4),\n", " b=s,\n", " c=t\n", ")" ] }, { "cell_type": "code", "execution_count": 15, "id": "bdef0cd4", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:12.023191Z", "iopub.status.busy": "2021-07-16T22:28:12.022331Z", "iopub.status.idle": "2021-07-16T22:28:12.033135Z", "shell.execute_reply": "2021-07-16T22:28:12.033516Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[ValueError] `b` must be size [1 3], not 4.\n" ] } ], "source": [ "with try_catch():\n", " tibble(a=range(3), b=range(4))" ] }, { "cell_type": "code", "execution_count": 16, "id": "0b39dd2f", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:12.039777Z", "iopub.status.busy": "2021-07-16T22:28:12.038743Z", "iopub.status.idle": "2021-07-16T22:28:12.285097Z", "shell.execute_reply": "2021-07-16T22:28:12.285549Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
.dotted
<int64>
03
\n", "
\n" ], "text/plain": [ " .dotted\n", " \n", "0 3" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tibble(_dotted = 3, _name_repair=lambda x: x.replace('_', '.'))" ] }, { "cell_type": "code", "execution_count": 17, "id": "e066dd0e", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:12.346792Z", "iopub.status.busy": "2021-07-16T22:28:12.345984Z", "iopub.status.idle": "2021-07-16T22:28:12.458197Z", "shell.execute_reply": "2021-07-16T22:28:12.458863Z" } }, "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", "
xy
<int64><int64>
011
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 1 1" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = 3\n", "tibble(x=1, y=f.x)" ] }, { "cell_type": "code", "execution_count": 18, "id": "065802b4", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:12.491292Z", "iopub.status.busy": "2021-07-16T22:28:12.490533Z", "iopub.status.idle": "2021-07-16T22:28:12.501385Z", "shell.execute_reply": "2021-07-16T22:28:12.501890Z" } }, "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", "
xy
<int64><int64>
013
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 1 3" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tibble(x=1, y=x)" ] }, { "cell_type": "code", "execution_count": 19, "id": "948a38e3", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:12.514668Z", "iopub.status.busy": "2021-07-16T22:28:12.513896Z", "iopub.status.idle": "2021-07-16T22:28:12.521217Z", "shell.execute_reply": "2021-07-16T22:28:12.521659Z" } }, "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", "
colAcolB
<object><int64>
0a1
1b2
2c3
\n", "
\n" ], "text/plain": [ " colA colB\n", " \n", "0 a 1\n", "1 b 2\n", "2 c 3" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tribble(\n", " f.colA, f.colB,\n", " \"a\", 1,\n", " \"b\", 2,\n", " \"c\", 3\n", ")" ] }, { "cell_type": "code", "execution_count": 20, "id": "3730b8a8", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:12.536248Z", "iopub.status.busy": "2021-07-16T22:28:12.535536Z", "iopub.status.idle": "2021-07-16T22:28:12.542704Z", "shell.execute_reply": "2021-07-16T22:28:12.543208Z" } }, "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", "
xy
<object><object>
0a[1, 2, 3]
1b[4, 5, 6]
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 a [1, 2, 3]\n", "1 b [4, 5, 6]" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tribble(\n", " f.x, f.y,\n", " \"a\", [1,2,3],\n", " \"b\", [4,5,6]\n", ")" ] }, { "cell_type": "code", "execution_count": 21, "id": "057cd848", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:12.589393Z", "iopub.status.busy": "2021-07-16T22:28:12.588770Z", "iopub.status.idle": "2021-07-16T22:28:12.597896Z", "shell.execute_reply": "2021-07-16T22:28:12.598334Z" } }, "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", "
ab
<int64><object>
01[2, 3]
\n", "
\n" ], "text/plain": [ " a b\n", " \n", "0 1 [2, 3]" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tibble_row(a=1, b=[[2,3]])" ] }, { "cell_type": "code", "execution_count": 22, "id": "b1a7d485", "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", "
xy$y
<int64><int64>
011
\n", "
\n" ], "text/plain": [ " x y$y\n", " \n", "0 1 1" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# inside a verb\n", "\n", "tibble(x=1) >> mutate(y=tibble(y=f.x))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/uncount.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "c822a641", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:41.539542Z", "iopub.status.busy": "2021-07-16T22:27:41.538779Z", "iopub.status.idle": "2021-07-16T22:27:42.396417Z", "shell.execute_reply": "2021-07-16T22:27:42.396954Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ uncount
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Duplicating rows according to a weighting variable\n", "\n", "##### Args:\n", "  `data`: A data frame \n", "  `weights`: A vector of weights. Evaluated in the context of data \n", "  `_remove`: If TRUE, and weights is the name of a column in data, \n", "    then this column is removed. \n", "\n", "  `_id`: Supply a string to create a new variable which gives a \n", "    unique identifier for each created row (0-based). \n", "\n", "##### Returns:\n", "  dataframe with rows repeated. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://tidyr.tidyverse.org/reference/uncount.html\n", "%run nb_helpers.py\n", "\n", "from datar.all import *\n", "\n", "nb_header(uncount)" ] }, { "cell_type": "code", "execution_count": 2, "id": "597c386a", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:42.429322Z", "iopub.status.busy": "2021-07-16T22:27:42.428768Z", "iopub.status.idle": "2021-07-16T22:27:42.617412Z", "shell.execute_reply": "2021-07-16T22:27:42.617782Z" } }, "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", "
x
<object>
0a
1b
2b
\n", "
\n" ], "text/plain": [ " x\n", " \n", "0 a\n", "1 b\n", "2 b" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(x = c(\"a\", \"b\"), n = c(1, 2))\n", "df >> uncount(f.n)" ] }, { "cell_type": "code", "execution_count": 3, "id": "ba0f3bcb", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:42.745543Z", "iopub.status.busy": "2021-07-16T22:27:42.744874Z", "iopub.status.idle": "2021-07-16T22:27:42.766238Z", "shell.execute_reply": "2021-07-16T22:27:42.766615Z" } }, "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", "
idx
<int64><object>
00a
11b
21b
\n", "
\n" ], "text/plain": [ " id x\n", " \n", "0 0 a\n", "1 1 b\n", "2 1 b" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> uncount(f.n, _id=\"id\")" ] }, { "cell_type": "code", "execution_count": 4, "id": "aac00379", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:42.804374Z", "iopub.status.busy": "2021-07-16T22:27:42.803762Z", "iopub.status.idle": "2021-07-16T22:27:42.839607Z", "shell.execute_reply": "2021-07-16T22:27:42.840394Z" } }, "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", "
xn
<object><int64>
0a1
1a1
2b2
3b2
\n", "
\n" ], "text/plain": [ " x n\n", " \n", "0 a 1\n", "1 a 1\n", "2 b 2\n", "3 b 2" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "uncount(df, 2)" ] }, { "cell_type": "code", "execution_count": 5, "id": "93f8367f", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:42.860672Z", "iopub.status.busy": "2021-07-16T22:27:42.860109Z", "iopub.status.idle": "2021-07-16T22:27:42.872296Z", "shell.execute_reply": "2021-07-16T22:27:42.872858Z" } }, "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", "
x
<object>
0a
1a
2b
\n", "
\n" ], "text/plain": [ " x\n", " \n", "0 a\n", "1 a\n", "2 b" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> uncount(2//f.n)" ] }, { "cell_type": "code", "execution_count": null, "id": "2734c069", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/unite.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "35dd20d5", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:16.606534Z", "iopub.status.busy": "2021-07-16T22:28:16.605830Z", "iopub.status.idle": "2021-07-16T22:28:17.907102Z", "shell.execute_reply": "2021-07-16T22:28:17.907562Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ unite
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Unite multiple columns into one by pasting strings together\n", "\n", "##### Args:\n", "  `data`: A data frame. \n", "  `col`: The name of the new column, as a string or symbol. \n", "  `*columns`: Columns to unite \n", "  `sep`: Separator to use between values. \n", "  `remove`: If True, remove input columns from output data frame. \n", "  `na_rm`: If True, missing values will be remove prior to uniting \n", "    each value. \n", "\n", "##### Returns:\n", "  The dataframe with selected columns united \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://tidyr.tidyverse.org/reference/unite.html\n", "%run nb_helpers.py\n", "\n", "from datar.all import *\n", "\n", "nb_header(unite)\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "6edc9543", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:17.921087Z", "iopub.status.busy": "2021-07-16T22:28:17.920349Z", "iopub.status.idle": "2021-07-16T22:28:18.288917Z", "shell.execute_reply": "2021-07-16T22:28:18.286498Z" } }, "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", "
xy
<object><object>
0ab
1aNaN
2NaNb
3NaNNaN
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 a b\n", "1 a NaN\n", "2 NaN b\n", "3 NaN NaN" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = expand_grid(x=c(\"a\", NA), y=c(\"b\", NA))\n", "df" ] }, { "cell_type": "code", "execution_count": 3, "id": "74d75279", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:18.336918Z", "iopub.status.busy": "2021-07-16T22:28:18.336162Z", "iopub.status.idle": "2021-07-16T22:28:18.874250Z", "shell.execute_reply": "2021-07-16T22:28:18.874650Z" } }, "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", "
zxy
<object><object><object>
0a_bab
1aaNaN
2bNaNb
3NaNNaN
\n", "
\n" ], "text/plain": [ " z x y\n", " \n", "0 a_b a b\n", "1 a a NaN\n", "2 b NaN b\n", "3 NaN NaN" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> unite(\"z\", c(f.x, f.y), remove=False)" ] }, { "cell_type": "code", "execution_count": 4, "id": "1d97911c", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:18.975591Z", "iopub.status.busy": "2021-07-16T22:28:18.974873Z", "iopub.status.idle": "2021-07-16T22:28:19.105442Z", "shell.execute_reply": "2021-07-16T22:28:19.107130Z" } }, "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", "
zxy
<object><object><object>
0a_bab
1aaNaN
2bNaNb
3NaNNaN
\n", "
\n" ], "text/plain": [ " z x y\n", " \n", "0 a_b a b\n", "1 a a NaN\n", "2 b NaN b\n", "3 NaN NaN" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> unite(\"z\", [0, 1], na_rm=True, remove=False)" ] }, { "cell_type": "code", "execution_count": 5, "id": "77331626", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:28:19.260230Z", "iopub.status.busy": "2021-07-16T22:28:19.259595Z", "iopub.status.idle": "2021-07-16T22:28:19.429797Z", "shell.execute_reply": "2021-07-16T22:28:19.430243Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2022-12-02 14:51:25][datar][WARNING] Expected 2 pieces. Missing pieces filled with `NA` in 3 rows ['a', 'b', ''].\n" ] }, { "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", "
xy
<object><object>
0ab
1aNaN
2bNaN
3NaN
\n", "
\n" ], "text/plain": [ " x y\n", " \n", "0 a b\n", "1 a NaN\n", "2 b NaN\n", "3 NaN" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> \\\n", " unite(\"xy\", c(f.x, f.y)) >> \\\n", " separate(f.xy, c(\"x\", \"y\"))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/notebooks/with_groups.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 1, "id": "86647a1e", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:23.471684Z", "iopub.status.busy": "2021-07-16T22:27:23.470754Z", "iopub.status.idle": "2021-07-16T22:27:24.596869Z", "shell.execute_reply": "2021-07-16T22:27:24.592829Z" } }, "outputs": [ { "data": { "text/html": [ "
Try this notebook on binder.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "###
★ with_groups
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "##### Modify the grouping variables for a single operation.\n", "\n", "##### Args:\n", "  `_data`: A data frame \n", "  `_groups`: columns passed by group_by \n", "    Use None to temporarily ungroup. \n", "\n", "  `_func`: Function to apply to regrouped data. \n", "\n", "##### Returns:\n", "  The new data frame with operations applied. \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# https://dplyr.tidyverse.org/reference/with_groups.html\n", "%run nb_helpers.py\n", "\n", "from datar.all import *\n", "\n", "nb_header(with_groups)" ] }, { "cell_type": "code", "execution_count": 2, "id": "139a79fa", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:24.654249Z", "iopub.status.busy": "2021-07-16T22:27:24.653532Z", "iopub.status.idle": "2021-07-16T22:27:25.280451Z", "shell.execute_reply": "2021-07-16T22:27:25.281069Z" } }, "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", "
gxx_mean
<int64><float64><float64>
010.2446110.525006
110.8054020.525006
220.8627070.829213
320.7957190.829213
430.8129100.812910
\n", "
\n", "

TibbleGrouped: g (n=3)" ], "text/plain": [ " g x x_mean\n", " \n", "0 1 0.244611 0.525006\n", "1 1 0.805402 0.525006\n", "2 2 0.862707 0.829213\n", "3 2 0.795719 0.829213\n", "4 3 0.812910 0.812910\n", "[TibbleGrouped: g (n=3)]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = tibble(g=c(1, 1, 2, 2, 3), x=runif(5))\n", "df >> with_groups(f.g, mutate, x_mean = mean(f.x)) " ] }, { "cell_type": "code", "execution_count": 3, "id": "65133081", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:25.407736Z", "iopub.status.busy": "2021-07-16T22:27:25.407070Z", "iopub.status.idle": "2021-07-16T22:27:25.456650Z", "shell.execute_reply": "2021-07-16T22:27:25.457055Z" } }, "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", "
gxx1
<int64><float64><float64>
010.2446110.244611
110.8054020.244611
220.8627070.862707
320.7957190.862707
430.8129100.812910
\n", "
\n", "

TibbleGrouped: g (n=3)" ], "text/plain": [ " g x x1\n", " \n", "0 1 0.244611 0.244611\n", "1 1 0.805402 0.244611\n", "2 2 0.862707 0.862707\n", "3 2 0.795719 0.862707\n", "4 3 0.812910 0.812910\n", "[TibbleGrouped: g (n=3)]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> with_groups(f.g, lambda df: df >> mutate(x1 = first(f.x))) " ] }, { "cell_type": "code", "execution_count": 4, "id": "1c9e8a12", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:25.523727Z", "iopub.status.busy": "2021-07-16T22:27:25.522838Z", "iopub.status.idle": "2021-07-16T22:27:25.804228Z", "shell.execute_reply": "2021-07-16T22:27:25.806102Z" } }, "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", "
gxx_mean
<int64><float64><float64>
010.2446110.70427
110.8054020.70427
220.8627070.70427
320.7957190.70427
430.8129100.70427
\n", "
\n" ], "text/plain": [ " g x x_mean\n", " \n", "0 1 0.244611 0.70427\n", "1 1 0.805402 0.70427\n", "2 2 0.862707 0.70427\n", "3 2 0.795719 0.70427\n", "4 3 0.812910 0.70427" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> \\\n", " group_by(f.g) >> \\\n", " with_groups(None, mutate, x_mean = mean(f.x))" ] }, { "cell_type": "code", "execution_count": 5, "id": "ec8f5fe0", "metadata": { "execution": { "iopub.execute_input": "2021-07-16T22:27:25.983097Z", "iopub.status.busy": "2021-07-16T22:27:25.982377Z", "iopub.status.idle": "2021-07-16T22:27:26.253418Z", "shell.execute_reply": "2021-07-16T22:27:26.253859Z" } }, "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", "
x
<float64>
00.244611
10.805402
20.862707
30.795719
40.812910
\n", "
\n" ], "text/plain": [ " x\n", " \n", "0 0.244611\n", "1 0.805402\n", "2 0.862707\n", "3 0.795719\n", "4 0.812910" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df >> \\\n", " group_by(f.g) >> \\\n", " with_groups(None, mutate, g=None)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('base')", "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.9.5" }, "vscode": { "interpreter": { "hash": "9ed5c94d10bf621c6841991b7e31ffd0f3c8de8ec4167710459737a50edc58e4" } } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: docs/options.md ================================================ Options are used to change some behaviors in `datar`. For environment variable configuration (such as controlling verb AST fallback behavior), see [Environment Variables](ENV_VARS.md). ## Available options ### allow_conflict_names Whether to allow conflict names that reversed by python. For example, `filter` is a python builtin function, but also a `dplyr` function. You should use `filter_` instead. By default, `datar` will raise an error when you try to import `filter`. You can set this option to `True` to allow this behavior. ```python >>> from datar.all import filter >>> # or from datar.dplyr import filter Traceback (most recent call last): File "", line 1, in ImportError: cannot import name 'filter' from 'datar.all' ``` ```python >>> from datar import options >>> options(allow_conflict_names=True) >>> from datar.all import filter >>> filter ``` The conflict names under `datar.base` are: - `min` - `max` - `sum` - `abs` - `round` - `all` - `any` - `re` The conflict names under `datar.dplyr` are: - `filter` - `slice` ### backends If you have multiple backends installed, you can use this option to specify which backends to use. ## Configuration files You can change the default behavior of datar by configuring a `.toml.toml` file in your home directory. For example, to always use underscore-suffixed names for conflicting names, you can add the following to your `~/.datar.toml` file: ```toml allow_conflict_names = true ``` You can also have a project/directory-based configuration file (`./.datar.toml`) in your current working directory, which has higher priority than the home directory configuration file. ================================================ FILE: docs/reference-maps/ALL.md ================================================ |Module|Description|Reference| |-|-|-| |`base`|APIs ported from `r-base/r-stats/r-utils`|[:octicons-cross-reference-16:][5]| |#|#|#| |`dplyr`|APIs ported from `tidyverse/dplyr`|[:octicons-cross-reference-16:][2]| |`tidyr`|APIs ported from `tidyverse/tidyr`|[:octicons-cross-reference-16:][4]| |`tibble`|APIs ported from `tidyverse/tibble`|[:octicons-cross-reference-16:][1]| |`forcats`|APIs ported from `tidyverse/forcats`|[:octicons-cross-reference-16:][9]| |#|#|#| |`datasets`|Datasets collected from `tidyverse` or other related packages|[:octicons-cross-reference-16:][3]| |#|#|#| |`datar`|Datar-specific verbs/functions|[:octicons-cross-reference-16:][6]| [1]: ../tibble [2]: ../dplyr [3]: ../datasets [4]: ../tidyr [5]: ../base [6]: ../datar [9]: ../forcats ================================================ FILE: docs/reference-maps/base.md ================================================ ## Reference of `datar.base` See [here](../stats) for APIs ported from `r-stats` and [here](../utils) for APIs ported from `r-utils` **Legend:** |Sample|Status| |---|---| |[normal]()|API that is regularly ported| |[strike-through]()|API that is not ported, or not an API originally| |[**bold**]()|API that is unique in `datar`| |[_italic_]()|Working in process| ### Constants |API|Description|Notebook example| |---|---|---:| |`pi`|the ratio of the circumference of a circle to its diameter.|[:material-notebook:][4]| |`letters`|the 26 lower-case letters of the Roman alphabet|[:material-notebook:][4]| |`LETTERS`|the 26 upper-case letters of the Roman alphabet|[:material-notebook:][4]| |`month.abb`|the three-letter abbreviations for the English month names|[:material-notebook:][4]| |`month.name`|the English names for the months of the year|[:material-notebook:][4]| ### Options |API|Description|Notebook example| |---|---|---:| |[`options`][5]|Allow the user to set and examine a variety of global _options_|[:material-notebook:][4]| |[`get_option()`][6]|Get the value of a certain option (R's `getOption()`)|[:material-notebook:][4]| |[**`options_context()`**][7]|A context manager to temporarily modify the options|[:material-notebook:][4]| ### Arithmetic functions |API|Description|Notebook example| |---|---|---:| |[`mean()`][8]|Calculate the mean of the values|[:material-notebook:][151]| |[`median()`][9]|Calculate the median of the values|[:material-notebook:][151]| |[`min()`][10]|Calculate the min of the values|[:material-notebook:][151]| |[`max()`][11]|Calculate the max of the values|[:material-notebook:][151]| |[`pmin()`][12]|Calculate the min of the values rowwisely|[:material-notebook:][151]| |[`pmax()`][13]|Calculate the max of the values rowwisely|[:material-notebook:][151]| |[`sum()`][14]|Calculate the sum of the values|[:material-notebook:][151]| |[`abs()`][15]|Calculate the absolute values of the values|[:material-notebook:][151]| |[`round()`][16]|Round the numbers|[:material-notebook:][151]| |[`var()`][17]|Calculate the variance of the values|[:material-notebook:][151]| |[`ceiling()`][18]|Get the ceiling integers of the numbers|[:material-notebook:][151]| |[`floor()`][19]|Get the floor integers of the numbers|[:material-notebook:][151]| |[`sqrt()`][20]|Get the square root of the numbers|[:material-notebook:][151]| |[`cov()`][21]|Calculate the covariance of the values|[:material-notebook:][151]| |[`prod()`][117]|Calculate Product of the input|[:material-notebook:][151]| |[`sign()`][118]|Get the signs of the corresponding elements of x|[:material-notebook:][151]| |[`signif()`][125]|Rounds the values in its first argument to the specified number of significant digits|[:material-notebook:][151]| |[`trunc()`][119]|Get the integers truncated for each element in x|[:material-notebook:][151]| |[`exp()`][120]|Calculates the power of natural number|[:material-notebook:][151]| |[`log()`][121]|Computes logarithms, by default natural logarithm|[:material-notebook:][151]| |[`log2()`][122]|Computes logarithms with base 2|[:material-notebook:][151]| |[`log10()`][123]|Computes logarithms with base 10|[:material-notebook:][151]| |[`log1p()`][124]|Computes log(1+x)|[:material-notebook:][151]| |[`quantile()`][152]|Produces sample quantiles corresponding to the given probabilities.|[:material-notebook:][151]| |[`sd()`, `std()`][153]|Computes the standard deviation of the values|[:material-notebook:][151]| |[`weighted_mean()`][154]|Computes the weighted mean of the values|[:material-notebook:][151]| |[`col_sums()`][155]|Computes column sums of a dataframe|[:material-notebook:][151]| |[`row_sums()`][156]|Computes row sums of a dataframe|[:material-notebook:][151]| |[`col_means()`][157]|Computes column means of a dataframe|[:material-notebook:][151]| |[`row_means()`][158]|Computes row means of a dataframe|[:material-notebook:][151]| |[`col_sds()`][159]|Computes column sds of a dataframe|[:material-notebook:][151]| |[`row_sds()`][160]|Computes row sds of a dataframe|[:material-notebook:][151]| |[`col_medians()`][161]|Computes column medians of a dataframe|[:material-notebook:][151]| |[`row_medians()`][162]|Computes row medians of a dataframe|[:material-notebook:][151]| ### Bessel functions |API|Description|Notebook example| |---|---|---:| |[`bessel_i()`][22]|Bessel Functions of integer and fractional order of first kind|[:material-notebook:][4]| |[`bessel_k()`][24]|Bessel Functions of integer and fractional order of second kind|[:material-notebook:][4]| |[`bessel_j()`][23]|Modified Bessel functions of first kind|[:material-notebook:][4]| |[`bessel_y()`][25]|Modified Bessel functions of third kind|[:material-notebook:][4]| ### Casting values between types |API|Description|Notebook example| |---|---|---:| |[`as_integer()`][26] [`as_int`][26]|Cast data to integer|[:material-notebook:][4]| |[`as_double()`][27]|Cast data to double (`numpy.float64`)|[:material-notebook:][4]| |[`as_float()`][28]|Cast data to float (`numpy.float_`)|[:material-notebook:][4]| |[`as_numeric()`][29]|Cast data to numeric|[:material-notebook:][4]| ### Complex numbers |API|Description|Notebook example| |---|---|---:| |[`re()`][30]|Get the real part of a complex number|[:material-notebook:][4]| |[`mod()`][31]|Get the modulus of a complex number|[:material-notebook:][4]| |[`im()`][32]|Get the imaginary part of a complex number|[:material-notebook:][4]| |[`arg()`][33]|Get the argument of a complex number|[:material-notebook:][4]| |[`conj()`][34]|Get the complex conjugate of a complex number|[:material-notebook:][4]| |[`is_complex()`][35]|Test if data is complex number|[:material-notebook:][4]| |[`as_complex()`][36]|Cast data to a complex number|[:material-notebook:][4]| ### Cumulativate functions |API|Description|Notebook example| |---|---|---:| |[`cumsum()`][37]|Cummulative sum|[:material-notebook:][4]| |[`cumprod()`][38]|Cummulative product|[:material-notebook:][4]| |[`cummin()`][39]|Cummulative min|[:material-notebook:][4]| |[`cummax()`][40]|Cummulative max|[:material-notebook:][4]| ### Date functions |API|Description|Notebook example| |---|---|---:| |[`as_date()`][41]|Cast data to date|[:material-notebook:][4]| |[**`as_pd_date()`**][150]|Alias of `pandas.to_datetime()`|| ### Factor data |API|Description|Notebook example| |---|---|---:| |[`factor()`][42]|Construct factor|[:material-notebook:][4]| |[`droplevels()`][43]|Drop unused levels|[:material-notebook:][4]| |[`levels()`][44]|Get levels of factors|[:material-notebook:][4]| |[`is_factor()`][45] [`is_categorical`][45]|Test if data is factor|[:material-notebook:][4]| |[`as_factor()`][46] [`as_categorical`][46]|Cast data to factor|[:material-notebook:][4]| |[`is_ordered()`][140]|Check if a factor is ordered|| |[`nlevels()`][141]|Get number of levels of a factor|| |[`ordered()`][142]|Create an ordered factor|| ### Logical/Boolean values |API|Description|Notebook example| |---|---|---:| |`TRUE`|Logical true|[:material-notebook:][4]| |`FALSE`|Logical false|[:material-notebook:][4]| |[`is_true()`][47]|Test if data is scalar true (R's `isTRUE`)|[:material-notebook:][4]| |[`is_false()`][48]|Test if data is scalar false (R's `FALSE`)|[:material-notebook:][4]| |[`is_logical()`][49] [`is_bool()`][49]|Test if data is logical/boolean|[:material-notebook:][4]| |[`as_logical()`][50] [`as_bool()`][50]|Cast data to logical/boolean|[:material-notebook:][4]| ### NA (missing values) |API|Description|Notebook example| |---|---|---:| |`Inf`|Infinite number|[:material-notebook:][4]| |`NA`|Missing value|[:material-notebook:][4]| |`NaN`|Missing value, same as `NA`|[:material-notebook:][4]| |[`is_na()`][51]|Test if data is NA|[:material-notebook:][4]| |[`any_na()`][52]|Test if any element is NA|[:material-notebook:][4]| |[`is_finite()`][126]|Test if x is finite|| |[`is_infinite()`][127]|Test if x is infinite|| |[`is_nan()`][128]|Test if x is nan|| ### NULL |API|Description|Notebook example| |---|---|---:| |`NULL`|NULL value|[:material-notebook:][4]| |[`is_null()`][53]|Test if data is null|[:material-notebook:][4]| |[`as_null()`][54]|Cast anything to NULL|[:material-notebook:][4]| ### Random |API|Description|Notebook example| |---|---|---:| |[`set_seed()`][55]|Set the randomization seed|[:material-notebook:][4]| ### Functions to create and manipulate sequences |API|Description|Notebook example| |---|---|---:| |[`c()`][56]|Collection of data|[:material-notebook:][4]| |[`seq()`][57]|Generate sequence|[:material-notebook:][4]| |[`seq_len()`][58]|Generate sequence with length|[:material-notebook:][4]| |[`seq_along()`][59]|Generate sequence along with another sequence|[:material-notebook:][4]| |[`rev()`][60]|Reverse a sequence|[:material-notebook:][4]| |[`rep()`][61]|Generate sequence with repeats|[:material-notebook:][4]| |[`lengths()`][62]|Get the length of elements in the sequence|[:material-notebook:][4]| |[`unique()`][63]|Get the unique elements|[:material-notebook:][4]| |[`sample()`][64]|Sample the elements from sequence|[:material-notebook:][4]| |[`length()`][65]|Get the length of data|[:material-notebook:][4]| |[`match()`][129]|match returns a vector of the positions of (first) matches of its first argument in its second.|| |[`rank()`][143]|Returns the sample ranks of the values in a vector.|[:material-notebook:][163]| |[`order()`][144]|Returns a permutation which rearranges its first argument into ascending or descending order|| |[`sort()`][145]|Sorting or Ordering Vectors|| ### Special functions |API|Description|Notebook example| |---|---|---:| |[`beta()`][66]|Beta function|[:material-notebook:][4]| |[`lbeta()`][67]|Natural logarithm of beta function|[:material-notebook:][4]| |[`gamma()`][68]|Gamma function|[:material-notebook:][4]| |[`lgamma()`][69]|Natural logarithm of gamma function|[:material-notebook:][4]| |[`digamma()`][70]|the first derivatives of the logarithm of the gamma function.|[:material-notebook:][4]| |[`trigamma()`][71]|the second derivatives of the logarithm of the gamma function.|[:material-notebook:][4]| |[`psigamma()`][72]|polygamma funnction|[:material-notebook:][4]| |[`choose()`][73]|binomial coefficients|[:material-notebook:][4]| |[`lchoose()`][74]|the logarithms of binomial coefficients.|[:material-notebook:][4]| |[`factorial()`][75]|factorial|[:material-notebook:][4]| |[`lfactorial()`][76]|Natural logarithm of factorial|[:material-notebook:][4]| ### String functions |API|Description|Notebook example| |---|---|---:| |[`is_character()`][77] [`is_str`][77] [`is_string`][77]|Test if data is string|[:material-notebook:][4]| |[`as_character()`][78] [`as_str`][78] [`as_string`][78]|Cast data to string|[:material-notebook:][4]| |[`grep()`][79]|Test if pattern in string|[:material-notebook:][4]| |[`grepl()`][80]|Logical version of `grep`|[:material-notebook:][4]| |[`sub()`][81]|Replace substrings in strings|[:material-notebook:][4]| |[`gsub()`][82]|Replace all matched substring in strings|[:material-notebook:][4]| |[`nchar()`][83]|Get length of string|[:material-notebook:][4]| |[`nzhcar()`][84]|Test if string is not empty|[:material-notebook:][4]| |[`paste()`][85]|Concatenate strings|[:material-notebook:][4]| |[`paste0()`][86]|Concatenate strings with `sep=''`|[:material-notebook:][4]| |[`sprintf()`][87]|C-style string formatting|[:material-notebook:][4]| |[`substr()`][88]|Get substring|[:material-notebook:][4]| |[`substring()`][89]|Get substring with a start only|[:material-notebook:][4]| |[`strsplit()`][90]|Split strings with delimiter|[:material-notebook:][4]| |[`startswith()`][130]|Test if strings start with given prefix|| |[`endswith()`][131]|Test if strings end with given suffix|| |[`strtoi()`][132]|Convert strings to integers|| |[`chartr()`][133]|Replace characters in strings|| |[`tolower()`][134]|Transform strings to lower case|| |[`toupper()`][135]|Transform strings to upper case|| |[`trimws()`][149]|Remove leading and/or trailing whitespace from character strings.|| ### Table |API|Description|Notebook example| |---|---|---:| |[`table()`][91]|Cross Tabulation and Table Creation|[:material-notebook:][4]| |[`tabulate()`][146]|Takes the integer-valued vector `bin` and counts the number of times each integer occurs in it.|| ### Testing value types |API|Description|Notebook example| |---|---|---:| |[`is_double()`][92] [`is_float()`][92]|Test if data is double or float (`numpy.float_`)|[:material-notebook:][4]| |[`is_integer()`][93] [`is_int()`][93]|Test if data is integer|[:material-notebook:][4]| |[`is_numeric()`][94]|Test if data is numeric|[:material-notebook:][4]| |[`is_atomic()`][95]|Test is data is atomic|[:material-notebook:][4]| |[`is_element(), `is_in()`][96]|Test if value is an element of an array (R's `%in`)|[:material-notebook:][4]| ### Trigonometric and hyper bolic functions |API|Description|Notebook example| |---|---|---:| |[`cos()`][97]|cosine|[:material-notebook:][4]| |[`sin()`][98]|sine|[:material-notebook:][4]| |[`tan()`][99]|tangent|[:material-notebook:][4]| |[`acos()`][100]|Arc-cosine|[:material-notebook:][4]| |[`asin()`][101]|Arc-sine|[:material-notebook:][4]| |[`atan()`][102]|Arc-tangent|[:material-notebook:][4]| |[`atan2()`][103]|`atan(y/x)`|[:material-notebook:][4]| |[`cospi()`][104]|`cos(pi*x)`|[:material-notebook:][4]| |[`sinpi()`][105]|`sin(pi*x)`|[:material-notebook:][4]| |[`tanpi()`][106]|`tan(pi*x)`|[:material-notebook:][4]| |[`cosh()`][107]|Hyperbolic cosine|[:material-notebook:][4]| |[`sinh()`][108]|Hyperbolic sine|[:material-notebook:][4]| |[`tanh()`][109]|Hyperbolic tangent|[:material-notebook:][4]| |[`acosh()`][110]|Hyperbolic cosine|[:material-notebook:][4]| |[`asinh()`][111]|Hyperbolic sine|[:material-notebook:][4]| |[`atanh()`][112]|Hyperbolic tangent|[:material-notebook:][4]| ### Which |API|Description|Notebook example| |---|---|---:| |[which()][1]|Which indices are True?|[:material-notebook:][4]| |[which_min()][2] [which_max()][3]|Where is the minimum or maximum or first TRUE or FALSE|[:material-notebook:][4]| ### Other functions |API|Description|Notebook example| |---|---|---:| |[`glimpse()`][166]|Get a glimpse of your data|| |[`cut()`][113]|Convert Numeric to Factor|[:material-notebook:][163]| |[`diff()`][164]|Returns suitably lagged and iterated differences.|[:material-notebook:][163]| |[`identity()`][114]|Identity Function|[:material-notebook:][163]| |[`expandgrid()`][115]|Create a Data Frame from All Combinations of Factor Variables|[:material-notebook:][163]| |[`outer()`][165]|Compute the outer product of two vectors.|[:material-notebook:][163]| |[`max_col()`][136]|Find the maximum position for each row of a matrix|| |[`append()`][147]|Add elements to a vector.|| |[`complete_cases()`][137]|Get a bool array indicating whether the values of rows are complete in a data frame.|| |[`proportions()`][147], [`prop_table`][147]|Returns conditional proportions given `margins`|| |[`make_names()`][137]|Make names available as columns and can be accessed by `df.`|[:material-notebook:][163]| |[`make_unique()`][138]|Make the names unique, alias of `make_names(names, unique=True)`|[:material-notebook:][163]| [1]: ../../api/datar.base.which/#datar.dplyr.which.which [2]: ../../api/datar.base.which/#datar.dplyr.which.which_min [3]: ../../api/datar.base.which/#datar.dplyr.which.which_max [4]: ../../notebooks/base [5]: ../../api/datar.apis.core/#datar.apis.core.options [6]: ../../api/datar.apis.core/#datar.apis.core.get_option [7]: ../../api/datar.apis.core/#datar.apis.core.options_context [8]: ../../api/datar.apis.base/#datar.apis.base.mean [9]: ../../api/datar.apis.base/#datar.apis.base.median [10]: ../../api/datar.apis.base/#datar.apis.base.min [11]: ../../api/datar.apis.base/#datar.apis.base.max [12]: ../../api/datar.apis.base/#datar.apis.base.pmin [13]: ../../api/datar.apis.base/#datar.apis.base.pmax [14]: ../../api/datar.apis.base/#datar.apis.base.sum [15]: ../../api/datar.apis.base/#datar.apis.base.abs [16]: ../../api/datar.apis.base/#datar.apis.base.round [17]: ../../api/datar.apis.base/#datar.apis.base.var [18]: ../../api/datar.apis.base/#datar.apis.base.ceiling [19]: ../../api/datar.apis.base/#datar.apis.base.floor [20]: ../../api/datar.apis.base/#datar.apis.base.sqrt [21]: ../../api/datar.apis.base/#datar.apis.base.cov [22]: ../../api/datar.apis.base/#datar.apis.base.bessel_i [23]: ../../api/datar.apis.base/#datar.apis.base.bessel_j [24]: ../../api/datar.apis.base/#datar.apis.base.bessel_k [25]: ../../api/datar.apis.base/#datar.apis.base.bessel_y [26]: ../../api/datar.apis.base/#datar.apis.base.as_integer [27]: ../../api/datar.apis.base/#datar.apis.base.as_double [28]: ../../api/datar.apis.base/#datar.apis.base.as_float [29]: ../../api/datar.apis.base/#datar.apis.base.as_numeric [30]: ../../api/datar.apis.base/#datar.apis.base.re [31]: ../../api/datar.apis.base/#datar.apis.base.mod [32]: ../../api/datar.apis.base/#datar.apis.base.im [33]: ../../api/datar.apis.base/#datar.apis.base.arg [34]: ../../api/datar.apis.base/#datar.apis.base.conj [35]: ../../api/datar.apis.base/#datar.apis.base.is_complex [36]: ../../api/datar.apis.base/#datar.apis.base.as_complex [37]: ../../api/datar.apis.base/#datar.apis.base.cumsum [38]: ../../api/datar.apis.base/#datar.apis.base.cumprod [39]: ../../api/datar.apis.base/#datar.apis.base.cummin [40]: ../../api/datar.apis.base/#datar.apis.base.cummax [41]: ../../api/datar.apis.base/#datar.apis.base.as_date [42]: ../../api/datar.apis.base/#datar.apis.base.factor [43]: ../../api/datar.apis.base/#datar.apis.base.droplevels [44]: ../../api/datar.apis.base/#datar.apis.base.levels [45]: ../../api/datar.apis.base/#datar.apis.base.is_factor [46]: ../../api/datar.apis.base/#datar.apis.base.as_factor [47]: ../../api/datar.apis.base/#datar.apis.base.is_true [48]: ../../api/datar.apis.base/#datar.apis.base.is_false [49]: ../../api/datar.apis.base/#datar.apis.base.is_logical [50]: ../../api/datar.apis.base/#datar.apis.base.as_logical [51]: ../../api/datar.apis.base/#datar.apis.base.is_na [52]: ../../api/datar.apis.base/#datar.apis.base.any_na [53]: ../../api/datar.apis.base/#datar.apis.base.is_null [54]: ../../api/datar.apis.base/#datar.apis.base.as_null [55]: ../../api/datar.apis.base/#datar.apis.base.set_seed [56]: ../../api/datar.apis.base/#datar.apis.base.c [57]: ../../api/datar.apis.base/#datar.apis.base.seq [58]: ../../api/datar.apis.base/#datar.apis.base.seq_len [59]: ../../api/datar.apis.base/#datar.apis.base.seq_along [60]: ../../api/datar.apis.base/#datar.apis.base.rev [61]: ../../api/datar.apis.base/#datar.apis.base.rep [62]: ../../api/datar.apis.base/#datar.apis.base.lengths [63]: ../../api/datar.apis.base/#datar.apis.base.unique [64]: ../../api/datar.apis.base/#datar.apis.base.sample [65]: ../../api/datar.apis.base/#datar.apis.base.length [66]: ../../api/datar.apis.base/#datar.apis.base.beta [67]: ../../api/datar.apis.base/#datar.apis.base.lbeta [68]: ../../api/datar.apis.base/#datar.apis.base.gamma [69]: ../../api/datar.apis.base/#datar.apis.base.lgamma [70]: ../../api/datar.apis.base/#datar.apis.base.digamma [71]: ../../api/datar.apis.base/#datar.apis.base.trigamma [72]: ../../api/datar.apis.base/#datar.apis.base.psigamma [73]: ../../api/datar.apis.base/#datar.apis.base.choose [74]: ../../api/datar.apis.base/#datar.apis.base.lchoose [75]: ../../api/datar.apis.base/#datar.apis.base.factorial [76]: ../../api/datar.apis.base/#datar.apis.base.lfactorial [77]: ../../api/datar.apis.base/#datar.apis.base.is_character [78]: ../../api/datar.apis.base/#datar.apis.base.as_character [79]: ../../api/datar.apis.base/#datar.apis.base.grep [80]: ../../api/datar.apis.base/#datar.apis.base.grepl [81]: ../../api/datar.apis.base/#datar.apis.base.sub [82]: ../../api/datar.apis.base/#datar.apis.base.gsub [83]: ../../api/datar.apis.base/#datar.apis.base.nchar [84]: ../../api/datar.apis.base/#datar.apis.base.nzchar [85]: ../../api/datar.apis.base/#datar.apis.base.paste [86]: ../../api/datar.apis.base/#datar.apis.base.paste0 [87]: ../../api/datar.apis.base/#datar.apis.base.sprintf [88]: ../../api/datar.apis.base/#datar.apis.base.substr [89]: ../../api/datar.apis.base/#datar.apis.base.substring [90]: ../../api/datar.apis.base/#datar.apis.base.strsplit [91]: ../../api/datar.apis.base/#datar.apis.base.table [92]: ../../api/datar.apis.base/#datar.apis.base.is_double [93]: ../../api/datar.apis.base/#datar.apis.base.is_float [94]: ../../api/datar.apis.base/#datar.apis.base.is_integer [95]: ../../api/datar.apis.base/#datar.apis.base.is_atomic [96]: ../../api/datar.apis.base/#datar.apis.base.is_element [97]: ../../api/datar.apis.base/#datar.apis.base.cos [98]: ../../api/datar.apis.base/#datar.apis.base.sin [99]: ../../api/datar.apis.base/#datar.apis.base.tan [100]: ../../api/datar.apis.base/#datar.apis.base.acos [101]: ../../api/datar.apis.base/#datar.apis.base.asin [102]: ../../api/datar.apis.base/#datar.apis.base.atan [103]: ../../api/datar.apis.base/#datar.apis.base.atan2 [104]: ../../api/datar.apis.base/#datar.apis.base.cospi [105]: ../../api/datar.apis.base/#datar.apis.base.sinpi [106]: ../../api/datar.apis.base/#datar.apis.base.tanpi [107]: ../../api/datar.apis.base/#datar.apis.base.cosh [108]: ../../api/datar.apis.base/#datar.apis.base.sinh [109]: ../../api/datar.apis.base/#datar.apis.base.tanh [110]: ../../api/datar.apis.base/#datar.apis.base.acosh [111]: ../../api/datar.apis.base/#datar.apis.base.asinh [112]: ../../api/datar.apis.base/#datar.apis.base.atanh [113]: ../../api/datar.apis.base/#datar.apis.base.cut [114]: ../../api/datar.apis.base/#datar.apis.base.identity [115]: ../../api/datar.apis.base/#datar.apis.base.expandgrid [116]: ../../api/datar.apis.base/#datar.apis.base.data_context [117]: ../../api/datar.apis.base/#datar.apis.base.prod [118]: ../../api/datar.apis.base/#datar.apis.base.sign [119]: ../../api/datar.apis.base/#datar.apis.base.trunc [120]: ../../api/datar.apis.base/#datar.apis.base.exp [121]: ../../api/datar.apis.base/#datar.apis.base.log [122]: ../../api/datar.apis.base/#datar.apis.base.log2 [123]: ../../api/datar.apis.base/#datar.apis.base.log10 [124]: ../../api/datar.apis.base/#datar.apis.base.log1p [125]: ../../api/datar.apis.base/#datar.apis.base.signif [126]: ../../api/datar.apis.base/#datar.apis.base.is_finite [127]: ../../api/datar.apis.base/#datar.apis.base.is_infinite [128]: ../../api/datar.apis.base/#datar.apis.base.is_nan [129]: ../../api/datar.apis.base/#datar.apis.base.match [130]: ../../api/datar.apis.base/#datar.apis.base.startswith [131]: ../../api/datar.apis.base/#datar.apis.base.endswith [132]: ../../api/datar.apis.base/#datar.apis.base.strtoi [133]: ../../api/datar.apis.base/#datar.apis.base.chartr [134]: ../../api/datar.apis.base/#datar.apis.base.tolower [135]: ../../api/datar.apis.base/#datar.apis.base.toupper [136]: ../../api/datar.apis.base/#datar.apis.base.max_col [137]: ../../api/datar.apis.base/#datar.apis.base.complete_cases [138]: ../../api/datar.apis.base/#datar.apis.base.make_names [139]: ../../api/datar.apis.base/#datar.apis.base.make_unique [140]: ../../api/datar.apis.base/#datar.apis.base.is_ordered [141]: ../../api/datar.apis.base/#datar.apis.base.nlevels [142]: ../../api/datar.apis.base/#datar.apis.base.ordered [143]: ../../api/datar.apis.base/#datar.apis.base.rank [144]: ../../api/datar.apis.base/#datar.apis.base.order [145]: ../../api/datar.apis.base/#datar.apis.base.sort [146]: ../../api/datar.apis.base/#datar.apis.base.tabulate [147]: ../../api/datar.apis.base/#datar.apis.base.append [148]: ../../api/datar.apis.base/#datar.apis.base.proportions [149]: ../../api/datar.apis.base/#datar.apis.base.trimws [150]: ../../api/datar.apis.base/#datar.apis.base.as_pd_date [151]: ../../notebooks/base-arithmetic [152]: ../../api/datar.apis.base/#datar.apis.base.quantile [153]: ../../api/datar.apis.base/#datar.apis.base.sd [154]: ../../api/datar.apis.base/#datar.apis.base.weighted_mean [155]: ../../api/datar.apis.base/#datar.apis.base.col_sums [156]: ../../api/datar.apis.base/#datar.apis.base.row_sums [157]: ../../api/datar.apis.base/#datar.apis.base.col_means [158]: ../../api/datar.apis.base/#datar.apis.base.row_means [159]: ../../api/datar.apis.base/#datar.apis.base.col_sds [160]: ../../api/datar.apis.base/#datar.apis.base.row_sds [161]: ../../api/datar.apis.base/#datar.apis.base.col_medians [162]: ../../api/datar.apis.base/#datar.apis.base.row_medians [163]: ../../notebooks/base-funs [164]: ../../api/datar.apis.base/#datar.apis.base.diff [165]: ../../api/datar.apis.base/#datar.apis.base.outer [166]: ../../api/datar.apis.base/#datar.apis.base.glimpse ================================================ FILE: docs/reference-maps/datasets.md ================================================ ## Reference of `datar.data` |API|Description|Source| |---|---|---:| |`airlines`|translation between two letter carrier codes and names|[`r-nycflights13`][1]| |`airports`|airport names and locations|[`r-nycflights13`][1]| |`flights`|all flights that departed from NYC in 2013|[`r-nycflights13`][1]| |`weather`|hourly meterological data for each airport|[`r-nycflights13`][1]| |`planes`|construction information about each plane|[`r-nycflights13`][1]| |#|#|#| |`state_abb`|character vector of 2-letter abbreviations for the state names.|[`r-datasets-state`][15]| |`state_division`|factor giving state divisions (New England, Middle Atlantic, South Atlantic, East South Central, West South Central, East North Central, West North Central, Mountain, and Pacific).|[`r-datasets-state`][15]| |`state_region`|factor giving the region (Northeast, South, North Central, West) that each state belongs to.|[`r-datasets-state`][15]| |#|#|#| |`airquality`|Daily air quality measurements in New York, May to September 1973.|[`r-datasets-airquality`][2]| |`anscombe`|Four x-y datasets which have the same traditional statistical properties|[`r-datasets-anscombe`][3]| |`faithful`|Waiting time between eruptions and the duration of the eruption for the Old Faithful geyser in Yellowstone National Park, Wyoming, USA|[`r-datasets-faithful`][31]| |`iris`|Edgar Anderson's Iris Data|[`r-datasets-iris`][9]| |`mtcars`|Motor Trend Car Road Tests|[`r-datasets-mtcars`][10]| |`warpbreaks`|The Number of Breaks in Yarn during Weaving|[`r-datasets-warpbreaks`][19]| |`ToothGrowth`|The Effect of Vitamin C on Tooth Growth in Guinea Pigs|[`r-datasets-ToothGrowth`][21]| |#|#|#| |`band_instruments`|Band members of the Beatles and Rolling Stones|[`r-dplyr-band_members`][4]| |`band_instruments2`|Band members of the Beatles and Rolling Stones|[`r-dplyr-band_members`][4]| |`band_members`|Band members of the Beatles and Rolling Stones|[`r-dplyr-band_members`][4]| |#|#|#| |`table1`|Example tabular representations|[`r-dplyr-storms`][17]| |`table2`|Example tabular representations|[`r-dplyr-storms`][17]| |`table3`|Example tabular representations|[`r-dplyr-storms`][17]| |`table4a`|Example tabular representations|[`r-dplyr-storms`][17]| |`table4b`|Example tabular representations|[`r-dplyr-storms`][17]| |`table5`|Example tabular representations|[`r-dplyr-storms`][17]| |#|#|#| |`starwars`|Starwars characters (columns `films`, `vehicles` and `starships` are not included)|[`r-dplyr-starwars`][14]| |`storms`|This data is a subset of the NOAA Atlantic hurricane database best track data|[`r-dplyr-storms`][16]| |`us_rent_income`|US rent and income data|[`r-dplyr-us_rent_income`][18]| |`world_bank_pop`|Population data from the world bank|[`r-dplyr-world_bank_pop`][20]| |#|#|#| |`billboard`|Song rankings for Billboard top 100 in the year 2000|[`r-tidyr-billboard`][5]| |`construction`|Completed construction in the US in 2018|[`r-tidyr-construction`][6]| |`fish_encounters`|Information about fish swimming down a river|[`r-tidyr-fish_encounters`][8]| |`population`|A subset of data from the World Health Organization Global Tuberculosis Report, and accompanying global populations.|[`r-tidyr-who`][11]| |`relig_income`|Pew religion and income survey|[`r-tidyr-relig_income`][12]| |`smiths`|A small demo dataset describing John and Mary Smith.|[`r-tidyr-smiths`][13]| |`who`|A subset of data from the World Health Organization Global Tuberculosis Report, and accompanying global populations.|[`r-tidyr-who`][11]| |#|#|#| |`diamonds`|A dataset containing the prices and other attributes of almost 54,000 diamonds|[`r-ggplot2-diamonds`][7]| |`economics` `economics_long`|US economic time series|[`r-ggplot2-economics`][22]| |`faithfuld`|2d density estimate of Old Faithful data|[`r-ggplot2-faithfuld`][23]| |`midwest`|Midwest demographics|[`r-ggplot2-midwest`][24]| |`mpg`|Fuel economy data from 1999 to 2008 for 38 popular models of cars|[`r-ggplot2-mpg`][25]| |`msleep`|An updated and expanded version of the mammals sleep dataset|[`r-ggplot2-msleep`][26]| |`presidential`|Terms of 11 presidents from Eisenhower to Obama|[`r-ggplot2-presidential`][27]| |`seals`|Vector field of seal movements|[`r-ggplot2-seals`][28]| |`txhousing`|Housing sales in TX|[`r-ggplot2-txhousing`][29]| |`luv_colours`|`colors()` in Luv space|[`r-ggplot2-luv_colours`][30]| |#|#| |`gss_cat`|A sample of categorical variables from the General Social survey|[`r-forcats-gss_cat`][32]| [1]: https://github.com/tidyverse/nycflights13 [2]: https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/airquality [3]: https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/anscombe [4]: https://dplyr.tidyverse.org/reference/band_members.html [5]: https://tidyr.tidyverse.org/reference/billboard.html [6]: https://tidyr.tidyverse.org/reference/construction.html [7]: https://ggplot2.tidyverse.org/reference/diamonds.html [8]: https://tidyr.tidyverse.org/reference/fish_encounters.html [9]: https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/iris [10]: https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/mtcars [11]: https://tidyr.tidyverse.org/reference/who.html [12]: https://tidyr.tidyverse.org/reference/relig_income.html [13]: https://tidyr.tidyverse.org/reference/smiths.html [14]: https://dplyr.tidyverse.org/reference/starwars.html [15]: https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/state [16]: https://dplyr.tidyverse.org/reference/storms.html [17]: https://tidyr.tidyverse.org/reference/table1.html [18]: https://tidyr.tidyverse.org/reference/us_rent_income.html [19]: https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/warpbreaks [20]: https://tidyr.tidyverse.org/reference/world_bank_pop.html [21]: https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/ToothGrowth [22]: https://ggplot2.tidyverse.org/reference/economics.html [23]: https://ggplot2.tidyverse.org/reference/faithfuld.html [24]: https://ggplot2.tidyverse.org/reference/midwest.html [25]: https://ggplot2.tidyverse.org/reference/mpg.html [26]: https://ggplot2.tidyverse.org/reference/msleep.html [27]: https://ggplot2.tidyverse.org/reference/presidential.html [28]: https://ggplot2.tidyverse.org/reference/seals.html [29]: https://ggplot2.tidyverse.org/reference/txhousing.html [30]: https://ggplot2.tidyverse.org/reference/luv_colours.html [31]: https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/faithfulZZ [32]: https://forcats.tidyverse.org/reference/gss_cat.html ================================================ FILE: docs/reference-maps/dplyr.md ================================================ ## Reference of `datar.dplyr` Reference map of `r-tidyverse-dplyr` can be found [here][1]. **Legend:** |Sample|Status| |---|---| |[normal]()|API that is regularly ported| |[strike-through]()|API that is not ported, or not an API originally| |[**bold**]()|API that is unique in `datar`| |[_italic_]()|Working in process| ### One table verbs |API|Description|Notebook example| |---|---|---:| |[arrange()][2]|Arrange rows by column values| [:material-notebook:][3] | |[count()][4] [tally()][5] [add_count()][6] [add_tally()][7]|Count observations by group| [:material-notebook:][8] | |[distinct()][9]|Subset distinct/unique rows| [:material-notebook:][10] | |[filter()][11]|Subset rows using column values| [:material-notebook:][12] | |[mutate()][13] [transmute()][14]|Create, modify, and delete columns| [:material-notebook:][15] | |[pull()][16]|Extract a single column| [:material-notebook:][17] | |[reframe()][142]|Reframe a data frame| [:material-notebook:][142] | |[relocate()][18]|Change column order| [:material-notebook:][19] | |[rename()][20] [rename_with()][21]|Rename columns| [:material-notebook:][22] | |[select()][23]| Subset columns using their names and types| [:material-notebook:][24] | |[summarise() summarize()][25]| Summarise each group to fewer rows| [:material-notebook:][26] | |[slice()][27] [slice_head()][28] [slice_tail()][29] [slice_min()][30] [slice_max()][31] [slice_sample()][32]| Subset rows using their positions| [:material-notebook:][33] | ### Two table verbs |API|Description|Notebook example| |---|---|---:| |[bind_rows()][34] [bind_cols()][35]|Efficiently bind multiple data frames by row and column|[:material-notebook:][36]| |[intersect()][37] [setdiff()][38] [setequal()][39] [union()][40]|Set operations on data frame|[:material-notebook:][41]| |[all_of()][42] [any_of()][43] [contains()][44] [ends_with()][45] [everything()][46] [last_col()][47] [matches()][48] [num_range()][49] [one_of()][50] [starts_with()][51]|Select variables from character vectors|[:material-notebook:][52]| |[union_all()][53]|Set operations|[:material-notebook:][54]| |[inner_join()][55] [left_join()][56] [right_join()][57] [full_join()][58]|Mutating joins|[:material-notebook:][59]| |[nest_join()][60]|Nest join|[:material-notebook:][61]| |[semi_join()][62] [anti_join()][63]|Filtering joins|[:material-notebook:][64]| ### Grouping |API|Description|Notebook example| |---|---|---:| |[group_by()][65] [ungroup()][66]|Group by one or more variables|[:material-notebook:][67]| |[group_cols() group_vars()][68]|Select grouping variables|[:material-notebook:][69]| |[rowwise()][70]|Group input by rows|[:material-notebook:][71]| ### Vector functions |API|Description|Notebook example| |---|---|---:| |[across()][72] [if_any()][73] [if_all()][74]|Apply a function (or functions) across multiple columns|[:material-notebook:][75]| |[c_across()][76]|Combine values from multiple columns|[:material-notebook:][77]| |[between()][78]|Do values in a numeric vector fall in specified range?|[:material-notebook:][79]| |[case_when()][80]|A general vectorised if|[:material-notebook:][81]| |[coalesce()][82]|Find first non-missing element|[:material-notebook:][83]| |[cumall()][84] [cumany()][85] [cummean()][86]|Cumulativate versions of any, all, and mean|[:material-notebook:][87]| |[desc()][88]|Descending order|[:material-notebook:][89]| |[if_else()][90]|Vectorised if|[:material-notebook:][91]| |[lag()][92] [lead()][93]|Compute lagged or leading values|[:material-notebook:][94]| |[order_by()][95]|A helper function for ordering window function output|[:material-notebook:][96]| |[n()][97] [cur_data()][98] [cur_data_all()][99] [cur_group()][100] [cur_group_id()][101] [cur_group_rows()][102] [cur_column()][103]|Context dependent expressions|[:material-notebook:][104]| |[n_distinct()][105]|Efficiently count the number of unique values in a set of vectors|[:material-notebook:][106]| |[na_if()][107]|Convert values to NA|[:material-notebook:][108]| |[near()][109]|Compare two numeric vectors|[:material-notebook:][110]| |[nth()][111] [first()][112] [last()][113]|Extract the first, last or nth value from a vector|[:material-notebook:][114]| |[row_number()][115] [ntile()][116] [min_rank()][117] [dense_rank()][118] [percent_rank()][119] [cume_dist()][120]|Windowed rank functions.|[:material-notebook:][121]| |[recode()][122] [recode_factor()][123]|Recode values|[:material-notebook:][124]| ### Data See [datasets][125] ### Remote tables ### Experimental |API|Description|Notebook example| |---|---|---:| |[group_map()][126] [group_modify()][127] [group_walk()][128]|Apply a function to each group|[:material-notebook:][129]| |[group_trim()][130]|Trim grouping structure|[:material-notebook:][131]| |[group_split()][132]|Split data frame by groups|[:material-notebook:][133]| |[with_groups()][134]|Perform an operation with temporary groups|[:material-notebook:][135]| |[rows_insert()][136] [rows_update()][137] [rows_patch()][138] [rows_upsert()][139] [rows_delete()][140]|Manipulate individual rows|[:material-notebook:][141]| ### Questioning ### Superseded [1]: https://dplyr.tidyverse.org/reference/index.html [2]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.arrange [3]: ../../notebooks/arrange [4]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.count [5]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.tally [6]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.add_count [7]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.add_tally [8]: ../../notebooks/count [9]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.distinct [10]: ../../notebooks/distinct [11]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.filter [12]: ../../notebooks/filter [13]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.mutate [14]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.transmutate [15]: ../../notebooks/mutate [16]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.pull [17]: ../../notebooks/pull [18]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.relocate [19]: ../../notebooks/relocate [20]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.rename [21]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.rename_with [22]: ../../notebooks/rename [23]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.select [24]: ../../notebooks/select [25]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.summarise [26]: ../../notebooks/summarise [27]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.slice [28]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.slice_head [29]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.slice_tail [30]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.slice_min [31]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.slice_max [32]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.slice_sample [33]: ../../notebooks/slice [34]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.bind_rows [35]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.bind_cols [36]: ../../notebooks/bind [37]: ../../api/datar.base.verbs/#datar.base.verbs.intersect [38]: ../../api/datar.base.verbs/#datar.base.verbs.setdiff [39]: ../../api/datar.base.verbs/#datar.base.verbs.seqequal [40]: ../../api/datar.base.verbs/#datar.base.verbs.union [41]: ../../notebooks/setops [42]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.all_of [43]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.any_of [44]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.contains [45]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.ends_with [46]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.everything [47]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.last_col [48]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.matches [49]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.num_range [50]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.one_of [51]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.starts_with [52]: ../../notebooks/select [53]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.union_all [54]: ../../notebooks/select [55]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.inner_join [56]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.left_join [57]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.right_join [58]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.full_join [59]: ../../notebooks/mutate-joins [60]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.nest_join [61]: ../../notebooks/nest-join [62]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.semi_join [63]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.anti_join [64]: ../../notebooks/filter-joins [65]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.group_by [66]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.ungroup [67]: ../../notebooks/group_by [68]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.group_vars [69]: ../../notebooks/group_by [70]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.rowwise [71]: ../../notebooks/rowwise [72]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.across [73]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.if_any [74]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.if_all [75]: ../../notebooks/across [76]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.c_across [77]: ../../notebooks/across [78]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.between [79]: ../../notebooks/between [80]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.case_when [81]: ../../notebooks/case_when [82]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.coalesce [83]: ../../notebooks/coalesce [84]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.cumall [85]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.cumany [86]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.cummean [87]: ../../notebooks/cumall [88]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.desc [89]: ../../notebooks/desc [90]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.if_else [91]: ../../notebooks/case_when [92]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.lag [93]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.lead [94]: ../../notebooks/lead-lag [95]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.order_by [96]: ../../notebooks/lead-lag [97]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.n [98]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.cur_data [99]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.cur_data_all [100]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.cur_group [101]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.cur_group_id [102]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.cur_group_rows [103]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.cur_column [104]: ../../notebooks/context [105]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.n_distinct [106]: ../../notebooks/distinct [107]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.na_if [108]: ../../notebooks/na_if [109]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.near [110]: ../../notebooks/near [111]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.nth [112]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.first [113]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.last [114]: ../../notebooks/nth [115]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.row_number [116]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.ntile [117]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.min_rank [118]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.dense_rank [119]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.percent_rank [120]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.cume_dist [121]: ../../notebooks/ranking [122]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.recode [123]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.recode_factor [124]: ../../notebooks/recode [125]: ../datasets [126]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.group_map [127]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.group_modify [128]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.group_walk [129]: ../../notebooks/group_map [130]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.group_trim [131]: ../../notebooks/group_trim [132]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.group_split [133]: ../../notebooks/group_split [134]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.with_groups [135]: ../../notebooks/with_groups [136]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.rows_insert [137]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.rows_update [138]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.rows_patch [139]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.rows_upsert [140]: ../../api/datar.apis.dplyr/#datar.apis.dplyr.rows_delete [141]: ../../notebooks/rows [142]: ../../notebooks/reframe ================================================ FILE: docs/reference-maps/forcats.md ================================================ ## Reference of `datar.forcats` Reference map of `r-tidyverse-forcats` can be found [here][1]. **Legend:** |Sample|Status| |---|---| |[normal]()|API that is regularly ported| |[strike-through]()|API that is not ported, or not an API originally| |[**bold**]()|API that is unique in `datar`| |[_italic_]()|Working in process| ### Change order of levels |API|Description|Notebook example| |---|---|---:| |[fct_relevel()][2]|Reorder factor levels by hand|[:material-notebook:][3]| |[fct_inorder()][4] [fct_infreq()][5] [fct_inseq()][6]|Reorder factor levels by first appearance, frequency, or numeric order|[:material-notebook:][3]| |[fct_reorder()][7] [fct_reorder2()][8] [last2()][9] [first2()][10]|Reorder factor levels by sorting along another variable|[:material-notebook:][3]| |[fct_shuffle()][11]|Randomly permute factor levels|[:material-notebook:][3]| |[fct_rev()][12]|Reverse order of factor levels|[:material-notebook:][3]| |[fct_shift()][13]|Shift factor levels to left or right, wrapping around at end|[:material-notebook:][3]| ### Change value of levels |API|Description|Notebook example| |---|---|---:| |[fct_anon()][15]|Anonymise factor levels|[:material-notebook:][14]| |[fct_collapse()][16]|Collapse factor levels into manually defined groups|[:material-notebook:][14]| |[fct_lump()][17] [fct_lump_min()][18] [fct_lump_prop()][19] [fct_lump_n()][20] [fct_lump_lowfreq()][41]|Lump together actor levels into "other"|[:material-notebook:][14]| |[fct_other()][21]|Replace levels with "other"|[:material-notebook:][14]| |[fct_recode()][22]|Change factor levels by hand|[:material-notebook:][14]| |[fct_relabel()][23]|Automatically relabel factor levels, collapse as necessary|[:material-notebook:][14]| ### Add/remove levels |API|Description|Notebook example| |---|---|---:| |[fct_expand()][25]|Add additional levels to a factor|[:material-notebook:][24]| |[fct_explicit_na()][26]|Make missing values explicit||[:material-notebook:][24]| |[fct_drop()][27]|Drop unused levels||[:material-notebook:][24]| |[fct_unify()][28]|Unify the levels in a list of factors||[:material-notebook:][24]| ### Combine multiple factors |API|Description|Notebook example| |---|---|---:| |[fct_c()][29]|Concatenate factors, combining levels|[:material-notebook:][31]| |[fct_cross()][30]|Combine levels from two or more factors to create a new factor|[:material-notebook:][31]| ### Other helpers |API|Description|Notebook example| |---|---|---:| |[as_factor()][33]|Convert input to a factor|[:material-notebook:][32]| |[fct_count()][34]|Count entries in a factor|[:material-notebook:][32]| |[fct_match()][35]|Test for presence of levels in a factor|[:material-notebook:][32]| |[fct_unique()][36]|Unique values of a factor|[:material-notebook:][32]| |[lvls_reorder()][37] [lvls_revalue()][38] [lvls_expand()][39]|Low-level functions for manipulating levels|[:material-notebook:][32]| |[lvls_union()][40]|Find all levels in a list of factors|[:material-notebook:][32]| [1]: https://forcats.tidyverse.org/reference/index.html [2]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_relevel [3]: ../../notebooks/forcats_lvl_order [4]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_inorder [5]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_infreq [6]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_inseq [7]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_reorder [8]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_reorder2 [9]: ../../api/datar.apis.forcats/#datar.apis.forcats.last2 [10]: ../../api/datar.apis.forcats/#datar.apis.forcats.first2 [11]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_shuffle [12]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_rev [13]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_shift [14]: ../../notebooks/forcats_lvl_value [15]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_relevel [16]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_relevel [17]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_lump [18]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_lump_min [19]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_lump_prop [20]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_lump_n [21]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_other [22]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_recode [23]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_relabel [24]: ../../notebooks/forcats_lvl_addrm [25]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_expand [26]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_explicit_na [27]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_drop [28]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_unify [29]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_c [30]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_cross [31]: ../../notebooks/forcats_fct_multi [32]: ../../notebooks/forcats_misc [33]: ../../api/datar.apis.forcats/#datar.apis.forcats.as_factor [34]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_count [35]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_match [36]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_unique [37]: ../../api/datar.apis.forcats/#datar.apis.forcats.lvls_reorder [38]: ../../api/datar.apis.forcats/#datar.apis.forcats.lvls_revalue [39]: ../../api/datar.apis.forcats/#datar.apis.forcats.lvls_expand [40]: ../../api/datar.apis.forcats/#datar.apis.forcats.lvls_union [41]: ../../api/datar.apis.forcats/#datar.apis.forcats.fct_lump_lowfreq ================================================ FILE: docs/reference-maps/other.md ================================================ ## Reference of `datar.datar` **Legend:** |Sample|Status| |---|---| |[normal]()|API that is regularly ported| |[strike-through]()|API that is not ported, or not an API originally| |[**bold**]()|API that is unique in `datar`| |[_italic_]()|Working in process| ### Verbs |API|Description|Notebook example| |---|---|---:| |[**`get()`**][2]|Extract values from data frames|[:material-notebook:][1]| |[**`flatten()`**][2]|Flatten values of data frames|[:material-notebook:][1]| |[**`pipe()`**][9]|Apply a function to data in a piping workflow|[:material-notebook:][1]| ### Functions |[**`itemgetter()`**][3]|Turn `a[f.x]` to a valid verb argument with `itemgetter(a, f.x)`|[:material-notebook:][1]| |[**`attrgetter()`**][4]|`f.x.` but works with `SeriesGroupBy` object|[:material-notebook:][1]| |[**`pd_str()`**][4]|`str` accessor but works with `SeriesGroupBy` object|[:material-notebook:][1]| |[**`pd_cat()`**][4]|`cat` accessor but works with `SeriesGroupBy` object|[:material-notebook:][1]| |[**`pd_dt()`**][4]|`dt` accessor but works with `SeriesGroupBy` object|[:material-notebook:][1]| [1]: ../../notebooks/datar [2]: ../../api/datar.apis.datar/#datar.apis.datar.get [3]: ../../api/datar.apis.datar/#datar.apis.datar.flatten [4]: ../../api/datar.apis.datar/#datar.apis.datar.itemgetter [5]: ../../api/datar.apis.datar/#datar.apis.datar.attrgetter [6]: ../../api/datar.apis.datar/#datar.apis.datar.pd_str [7]: ../../api/datar.apis.datar/#datar.apis.datar.pd_cat [8]: ../../api/datar.apis.datar/#datar.apis.datar.pd_dt [9]: ../../api/datar.misc/#datar.misc.pipe ================================================ FILE: docs/reference-maps/stats.md ================================================ ## Reference of `datar.datar` **Legend:** |Sample|Status| |---|---| |[normal]()|API that is regularly ported| |[strike-through]()|API that is not ported, or not an API originally| |[**bold**]()|API that is unique in `datar`| |[_italic_]()|Working in process| ### Stats |API|Description|Notebook example| |---|---|---:| |[`rnorm()`][1]|Generates random deviates for the normal distribution|| |[`rpois()`][2]|Generates random deviates for the Poisson distribution|| |[`runif()`][3]|Generates random deviates for the uniform distribution|| [1]: ../../api/datar.apis.base/#datar.apis.base.rnorm [2]: ../../api/datar.apis.base/#datar.apis.base.rpois [3]: ../../api/datar.apis.base/#datar.apis.base.runif ================================================ FILE: docs/reference-maps/tibble.md ================================================ ## Reference of `datar.tibble` Reference map of `r-tidyverse-tibble` can be found [here][1]. **Legend:** |Sample|Status| |---|---| |[normal]()|API that is regularly ported| |[strike-through]()|API that is not ported, or not an API originally| |[**bold**]()|API that is unique in `datar`| |_italic_|Working in process| ### Tibbles !!! Tip Tibbles in `datar` are just `pandas.DataFrame`s. So there is no difference between data frames created by `tibble()` and `pandas.DataFrame`, unlike in R, `tibble` and `data.frame`. Also note that tibbles in `datar` are not `rownames`/`index` aware for most APIs, just like most `tidyverse` APIs. |API|Description|Notebook example| |---|---|---:| |`tibble-package`||| |[`tibble()`][12] [`tibble_row()`][18]|Build a data frame| [:material-notebook:][2] | |[`fibble()`][13]|Same as `tibble()` but used as Verb arguments| [:material-notebook:][2] | |`tbl_df-class`||| |`print()` `format()`||| |[`tribble()`][3]|Row-wise tibble creation|[:material-notebook:][2]| ### Coercion |API|Description|Notebook example| |---|---|---:| |`is_tibble()`||| |[`as_tibble()`][19]|Convert data frames into datar's tibbles|| |`new_tibble()` `validate_tibble()`||| |[`enframe()`][4] [`deframe()`][14]|Converting iterables to data frames, and vice versa| [:material-notebook:][5]| ### Manipulation |API|Description|Notebook example| |---|---|---:| |`$` `[[` `[`|Please subset data frames using `pandas` syntax (`df.col`, `df['col']`, `df.loc[...]` or `df.iloc[...]`| |[`add_row()`][6]| Add rows to a data frame | [:material-notebook:][7] | |[`add_column()`][8]| Add columns to a data frame | [:material-notebook:][9] | ### Helpers |API|Description|Notebook example| |---|---|---:| |`reexports`||| |[`has_rownames()`/`has_index()`][10] [`remove_rownames()`/`remove_index()`/`drop_index()`][15] [`rownames_to_column()`/`index_to_column()`][16] [`rowid_to_column()` `column_to_rownames()`/`column_to_index()`][17]|Tools for working with row names/DataFrame indexes|[:material-notebook:][11]| |`view()`||| ### Vectors, matrices, and lists [1]: https://tibble.tidyverse.org/reference/index.html [2]: ../../notebooks/tibble [3]: ../../api/datar.apis.tibble/#datar.apis.tibble.tribble [4]: ../../api/datar.apis.tibble/#datar.apis.tibble.enframe [5]: ../../notebooks/enframe [6]: ../../api/datar.apis.tibble/#datar.apis.tibble.add_row [7]: ../../notebooks/add_row [8]: ../../api/datar.apis.tibble/#datar.apis.tibble.add_column [9]: ../../notebooks/add_column [10]: ../../api/datar.apis.tibble/#datar.apis.tibble.has_rownames [11]: ../../notebooks/rownames [12]: ../../api/datar.apis.tibble/#datar.apis.tibble.tibble [13]: ../../api/datar.apis.tibble/#datar.apis.tibble.fibble [14]: ../../api/datar.apis.tibble/#datar.apis.tibble.deframe [15]: ../../api/datar.apis.tibble/#datar.apis.tibble.remove_rownames [16]: ../../api/datar.apis.tibble/#datar.apis.tibble.rownames_to_column [17]: ../../api/datar.apis.tibble/#datar.apis.tibble.rowid_to_column [18]: ../../api/datar.apis.tibble/#datar.apis.tibble.tibble_row [19]: ../../api/datar.apis.tibble/#datar.apis.tibble.as_tibble ================================================ FILE: docs/reference-maps/tidyr.md ================================================ ## Reference of `datar.dplyr` Reference map of `r-tidyverse-tidyr` can be found [here][1]. **Legend:** |Sample|Status| |---|---| |[normal]()|API that is regularly ported| |[strike-through]()|API that is not ported, or not an API originally| |[**bold**]()|API that is unique in `datar`| |[_italic_]()|Working in process| ### Pivoting |API|Description|Notebook example| |---|---|---:| |[pivot_longer()][26]|Pivot data from wide to long|[:material-notebook:][27]| |[pivot_wider()][28]|Pivot data from long to wide|[:material-notebook:][29]| ### Rectangling |API|Description|Notebook example| |---|---|---:| |_`hoist()`_ _`unnest_longer()`_ _`unnest_wider()`_ _`unnest_auto()`_|Rectangle a nested list into a tidy tibble|| ### Nesting |API|Description|Notebook example| |---|---|---:| |[`nest()`][9] [`unnest()`][10]|Nest and unnest|[:material-notebook:][11]| ### Character vectors |API|Description|Notebook example| |---|---|---:| |[`extract()`][22]|Extract a character column into multiple columns using regular expression groups|[:material-notebook:][23]| |[`separate()`][30]|Separate a character column into multiple columns with a regular expression or numeric locations|[:material-notebook:][31]| |[`separate_rows()`][34]|Separate a collapsed column into multiple rows|[:material-notebook:][35]| |[`unite()`][36]|Unite multiple columns into one by pasting strings together|[:material-notebook:][37]| ### Missing values |API|Description|Notebook example| |---|---|---:| |[`complete()`][18]|Complete a data frame with missing combinations of data|[:material-notebook:][19]| |[`drop_na()`][20]|Drop rows containing missing values|[:material-notebook:][21]| |[`expand()`][12] [`crossing()`][13] [`nesting()`][14]|Expand data frame to include all possible combinations of values|[:material-notebook:][15]| |[`expand_grid()`][16]| |[`fill()`][24]|Fill in missing values with previous or next value|[:material-notebook:][25]| |[`full_seq()`][40]|Create the full sequence of values in a vector|[:material-notebook:][41]| |[`replace_na()`][38]|Replace NAs with specified values|[:material-notebook:][39]| ### Miscellanea |API|Description|Notebook example| |---|---|---:| |[`chop()`][3] [`unchop()`][4]|Chop and unchop|[:material-notebook:][5]| |[`pack()`][6] [`unpack()`][7]|Pack and unpack|[:material-notebook:][8]| |[`uncount()`][32]|"Uncount" a data frame|[:material-notebook:][33]| ### Data See [datasets][2] [1]: https://tidyr.tidyverse.org/reference/index.html [2]: ../datasets [3]: ../../api/datar.apis.tidyr/#datar.apis.tidyr.chop [4]: ../../api/datar.apis.tidyr/#datar.apis.tidyr.unchop [5]: ../../notebooks/chop [6]: ../../api/datar.apis.tidyr/#datar.apis.tidyr.pack [7]: ../../api/datar.apis.tidyr/#datar.apis.tidyr.unpack [8]: ../../notebooks/chop [9]: ../../api/datar.apis.tidyr/#datar.apis.tidyr.nest [10]: ../../api/datar.apis.tidyr/#datar.apis.tidyr.unnest [11]: ../../notebooks/nest [12]: ../../api/datar.apis.tidyr/#datar.apis.tidyr.expand [13]: ../../api/datar.apis.tidyr/#datar.apis.tidyr.crossing [14]: ../../api/datar.apis.tidyr/#datar.apis.tidyr.nesting [15]: ../../notebooks/expand [16]: ../../api/datar.apis.tidyr/#datar.apis.tidyr.expand_grid [17]: ../../notebooks/expand_grid [18]: ../../api/datar.apis.tidyr/#datar.apis.tidyr.complete [19]: ../../notebooks/complete [20]: ../../api/datar.apis.tidyr/#datar.apis.tidyr.drop_na [21]: ../../notebooks/drop_na [22]: ../../api/datar.apis.tidyr/#datar.apis.tidyr.extract [23]: ../../notebooks/extract [24]: ../../api/datar.apis.tidyr/#datar.apis.tidyr.fill [25]: ../../notebooks/fill [26]: ../../api/datar.apis.tidyr/#datar.apis.tidyr.pivot_longer [27]: ../../notebooks/pivot_longer [28]: ../../api/datar.apis.tidyr/#datar.apis.tidyr.pivot_wider [29]: ../../notebooks/pivot_wider [30]: ../../api/datar.apis.tidyr/#datar.apis.tidyr.separate [31]: ../../notebooks/separate [32]: ../../api/datar.apis.tidyr/#datar.apis.tidyr.uncount [33]: ../../notebooks/uncount [34]: ../../api/datar.apis.tidyr/#datar.apis.tidyr.separate_rows [35]: ../../notebooks/separate [36]: ../../api/datar.apis.tidyr/#datar.apis.tidyr.unite [37]: ../../notebooks/unite [38]: ../../api/datar.apis.tidyr/#datar.apis.tidyr.replace_na [39]: ../../notebooks/replace_na [40]: ../../api/datar.apis.tidyr/#datar.apis.tidyr.full_seq [41]: ../../notebooks/full_seq ================================================ FILE: docs/reference-maps/utils.md ================================================ ## Reference of `datar.datar` **Legend:** |Sample|Status| |---|---| |[normal]()|API that is regularly ported| |[strike-through]()|API that is not ported, or not an API originally| |[**bold**]()|API that is unique in `datar`| |[_italic_]()|Working in process| ### Utils |API|Description|Notebook example| |---|---|---:| |[`head()`][1]|Get the head of the object|| |[`tail()`][2]|Get the tail of the object|| [1]: ../../api/datar.apis.base/#datar.apis.base.head [2]: ../../api/datar.apis.base/#datar.apis.base.tail ================================================ FILE: docs/style.css ================================================ .md-main__inner.md-grid { max-width: 80%; margin-left: 32px; } .md-typeset .admonition, .md-typeset details { font-size: .7rem !important; } .md-typeset table:not([class]) td { padding: .55em 1.25em !important; } .md-typeset table:not([class]) th { padding: .75em 1.25em !important; } .md-grid { max-width: none; } .mkapi-docstring{ line-height: 1; } .mkapi-node { background-color: #f4faff; border-top: 3px solid #151922; } .mkapi-node .mkapi-object-container { background-color: #d1d4d6; padding: .12em .4em; } .mkapi-node .mkapi-object-container .mkapi-object.code { background: none; border: none; } .mkapi-node .mkapi-object-container .mkapi-object.code * { font-size: .65rem !important; } .mkapi-node pre { line-height: 1.5; } .md-typeset pre>code { overflow: visible; line-height: 1.2; } .mkapi-docstring .md-typeset pre>code { font-size: 0.1rem !important; } .mkapi-section-name.bases { margin-top: .2em; } .mkapi-section-body.bases { padding-bottom: .7em; line-height: 1.3; } .mkapi-section.bases { margin-bottom: .8em; } .mkapi-node * { font-size: .7rem; } .mkapi-node a.mkapi-src-link { word-break: keep-all; } .mkapi-docstring { padding: .4em .15em !important; } .mkapi-section-name-body { font-size: .72rem !important; } .mkapi-node ul.mkapi-items li { line-height: 1.4 !important; } .mkapi-node ul.mkapi-items li * { font-size: .65rem !important; } .mkapi-node code.mkapi-object-signature { padding-right: 2px; } .mkapi-node .mkapi-code * { font-size: .6rem; } .mkapi-node a.mkapi-docs-link { font-size: .6rem; } .mkapi-node h1.mkapi-object.mkapi-object-code { margin: .2em .3em; } .mkapi-node h1.mkapi-object.mkapi-object-code .mkapi-object-kind.mkapi-object-kind-code { font-style: normal; margin-right: 16px; } .mkapi-node .mkapi-item-name { font-size: .7rem !important; color: #555; padding-right: 4px; } .md-typeset { font-size: .75rem !important; line-height: 1.5 !important; } .mkapi-object-kind.package.top { font-size: .8rem !important; color: #111; } .mkapi-object.package.top > h2 { font-size: .8rem !important; } .mkapi-object-body.package.top * { font-size: .75rem !important; } .mkapi-object-kind.module.top { font-size: .75rem !important; color: #222; } .mkapi-object-body.module.top * { font-size: .75rem !important; } .mkapi-section-body.examples pre code { font-size: .65rem !important; overflow: auto; } ================================================ FILE: mkdocs.yml ================================================ site_name: datar repo_url: https://github.com/pwwang/datar repo_name: pwwang/datar theme: favicon: favicon.png logo: favicon.png icon: repo: fontawesome/brands/github palette: primary: black name: 'material' font: text: - FreightSans - "Helvetica Neue" - Helvetica - Arial - sans-serif code: - IBMPlexMono - SFMono-Regular - Menlo - Monaco - Consolas - "Liberation Mono" - "Courier New" - monospace features: - navigation.top markdown_extensions: - markdown.extensions.admonition - pymdownx.emoji: emoji_index: !!python/name:material.extensions.emoji.twemoji emoji_generator: !!python/name:material.extensions.emoji.to_svg - pymdownx.superfences: preserve_tabs: true - toc: baselevel: 2 plugins: - search # necessary for search to work - mkapi - mkdocs-jupyter: execute: false extra_css: - style.css nav: - 'Home': 'index.md' - 'Reference maps': - 'reference-maps/ALL.md' - 'reference-maps/base.md' - 'reference-maps/dplyr.md' - 'reference-maps/tibble.md' - 'reference-maps/tidyr.md' - 'reference-maps/forcats.md' - 'reference-maps/datasets.md' - 'reference-maps/other.md' - 'Import datar': 'import.md' - 'Backends': 'backends.md' - 'Options': 'options.md' - 'Environment Variables': 'ENV_VARS.md' - 'The f-expression': 'f.md' - 'Data': 'data.md' - 'Examples': - 'across': 'notebooks/across.ipynb' - 'add_column': 'notebooks/add_column.ipynb' - 'add_row': 'notebooks/add_row.ipynb' - 'arrange': 'notebooks/arrange.ipynb' - 'base': 'notebooks/base.ipynb' - 'base-arithmetic': 'notebooks/base-arithmetic.ipynb' - 'base-funs': 'notebooks/base-funs.ipynb' - 'between': 'notebooks/between.ipynb' - 'bind': 'notebooks/bind.ipynb' - 'case_when': 'notebooks/case_when.ipynb' - 'chop': 'notebooks/chop.ipynb' - 'coalesce': 'notebooks/coalesce.ipynb' - 'complete': 'notebooks/complete.ipynb' - 'context': 'notebooks/context.ipynb' - 'count': 'notebooks/count.ipynb' - 'cumall': 'notebooks/cumall.ipynb' - 'desc': 'notebooks/desc.ipynb' - 'distinct': 'notebooks/distinct.ipynb' - 'drop_na': 'notebooks/drop_na.ipynb' - 'enframe': 'notebooks/enframe.ipynb' - 'expand': 'notebooks/expand.ipynb' - 'expand_grid': 'notebooks/expand_grid.ipynb' - 'extract': 'notebooks/extract.ipynb' - 'fill': 'notebooks/fill.ipynb' - 'filter': 'notebooks/filter.ipynb' - 'filter-joins': 'notebooks/filter-joins.ipynb' - 'forcats_fct_multi': 'notebooks/forcats_fct_multi.ipynb' - 'forcats_lvl_addrm': 'notebooks/forcats_lvl_addrm.ipynb' - 'forcats_lvl_order': 'notebooks/forcats_lvl_order.ipynb' - 'forcats_lvl_value': 'notebooks/forcats_lvl_value.ipynb' - 'forcats_misc': 'notebooks/forcats_misc.ipynb' - 'full_seq': 'notebooks/full_seq.ipynb' - 'other': 'notebooks/other.ipynb' - 'group_by': 'notebooks/group_by.ipynb' - 'group_map': 'notebooks/group_map.ipynb' - 'group_split': 'notebooks/group_split.ipynb' - 'group_trim': 'notebooks/group_trim.ipynb' - 'lead-lag': 'notebooks/lead-lag.ipynb' - 'mutate-joins': 'notebooks/mutate-joins.ipynb' - 'mutate': 'notebooks/mutate.ipynb' - 'n_distinct': 'notebooks/n_distinct.ipynb' - 'na_if': 'notebooks/na_if.ipynb' - 'near': 'notebooks/near.ipynb' - 'nest': 'notebooks/nest.ipynb' - 'nest-join': 'notebooks/nest-join.ipynb' - 'nth': 'notebooks/nth.ipynb' - 'pack': 'notebooks/pack.ipynb' - 'pivot_longer': 'notebooks/pivot_longer.ipynb' - 'pivot_wider': 'notebooks/pivot_wider.ipynb' - 'pull': 'notebooks/pull.ipynb' - 'ranking': 'notebooks/ranking.ipynb' - 'readme': 'notebooks/readme.ipynb' - 'recode': 'notebooks/recode.ipynb' - 'reframe': 'notebooks/reframe.ipynb' - 'relocate': 'notebooks/relocate.ipynb' - 'rename': 'notebooks/rename.ipynb' - 'replace_na': 'notebooks/replace_na.ipynb' - 'rownames': 'notebooks/rownames.ipynb' - 'rows': 'notebooks/rows.ipynb' - 'rowwise': 'notebooks/rowwise.ipynb' - 'select': 'notebooks/select.ipynb' - 'separate': 'notebooks/separate.ipynb' - 'setops': 'notebooks/setops.ipynb' - 'slice': 'notebooks/slice.ipynb' - 'summarise': 'notebooks/summarise.ipynb' - 'tibble': 'notebooks/tibble.ipynb' - 'uncount': 'notebooks/uncount.ipynb' - 'unite': 'notebooks/unite.ipynb' - 'with_groups': 'notebooks/with_groups.ipynb' - 'API': 'mkapi/api/datar' - 'Change Log': CHANGELOG.md ================================================ FILE: pyproject.toml ================================================ [project] name = "datar" version = "0.15.17" description = "A Grammar of Data Manipulation in python" authors = [ {name = "pwwang", email = "pwwang@pwwang.com"} ] license = {text = "MIT"} readme = "README.md" requires-python = ">=3.9" dependencies = [ "simplug>=0.5,<0.6", "pipda>=0.13.1,<0.14", "python-simpleconf[toml]>=0.9,<0.10", ] [project.optional-dependencies] numpy = ["datar-numpy>=0.3.4,<0.4"] pandas = ["datar-pandas>=0.7,<0.8"] # pandas = {path = "../datar-pandas"} # polars = ["datar-polars"] arrow = ["datar-arrow>=0.2,<0.3"] # modin = ["datar-pandas>=0.6,<0.7"] [project.urls] Homepage = "https://github.com/pwwang/datar" Repository = "https://github.com/pwwang/datar" [dependency-groups] dev = [ "pytest>=8.1,<9", "pytest-cov>=6,<7", "flake8", "six>=1.16,<2", "numpy", "python-slugify>=8,<9", ] docs = [ "mkdocs>=1.6,<2", "mkdocs-material>=9.6,<10", "pymdown-extensions>=10.14,<11", "mkapi-fix>=0.1,<0.2", "mkdocs-jupyter>=0.25,<0.26", "ipykernel>=6.29,<7", "ipython-genutils>=0.2,<0.3", "plotnine>=0.13,<0.14", "klib>=1.3,<2", "pardoc>=0.2,<0.3", "varname>=0.15,<0.16", ] [build-system] requires = ["hatchling"] build-backend = "hatchling.build" [tool.mypy] ignore_missing_imports = true allow_redefinition = true disable_error_code = ["attr-defined", "no-redef", "union-attr"] show_error_codes = true strict_optional = false [tool.pytest.ini_options] addopts = "-vv -p no:asyncio --tb=short --cov-config=.coveragerc --cov=datar --cov-report xml:cov.xml --cov-report term-missing" filterwarnings = [ # "error" ] console_output_style = "progress" junit_family = "xunit1" [tool.black] line-length = 80 target-version = ['py39', 'py310', 'py311', 'py312'] include = '\.pyi?$' ================================================ FILE: setup.py ================================================ """ # This will not be included in the distribution. # The distribution is managed by uv # This file is kept only for # 1. Github to index the dependents # 2. pip install -e . """ from setuptools import setup setup(name="datar") ================================================ FILE: tests/__init__.py ================================================ ================================================ FILE: tests/conflict_names.py ================================================ import argparse def test_getattr(module, allow_conflict_names, fun, error): from datar import options options(allow_conflict_names=allow_conflict_names) if module == "all": import datar.all as d elif module == "base": import datar.base as d elif module == "dplyr": import datar.dplyr as d if not error: return getattr(d, fun) try: getattr(d, fun) except Exception as e: raised = type(e).__name__ assert raised == error, f"Raised {raised}, expected {error}" else: raise AssertionError(f"{error} should have raised") def _import(module, fun): if module == "all" and fun == "sum": from datar.all import sum # noqa: F401 elif module == "all" and fun == "slice": from datar.all import slice # noqa: F401 elif module == "base" and fun == "sum": from datar.base import sum # noqa: F401 elif module == "dplyr" and fun == "slice": from datar.dplyr import slice # noqa: F401 def test_import(module, allow_conflict_names, fun, error): from datar import options options(allow_conflict_names=allow_conflict_names) if not error: return _import(module, fun) try: _import(module, fun) except Exception as e: raised = type(e).__name__ assert raised == error, f"Raised {raised}, expected {error}" else: raise AssertionError(f"{error} should have raised") def make_test(module, allow_conflict_names, getattr, fun, error): if fun == "_": fun = "sum" if module in ["all", "base"] else "slice" if getattr: return test_getattr(module, allow_conflict_names, fun, error) return test_import(module, allow_conflict_names, fun, error) def main(): parser = argparse.ArgumentParser() parser.add_argument( "--module", choices=["all", "base", "dplyr"], required=True, help="The module to test" ) parser.add_argument( "--allow-conflict-names", action="store_true", help="Whether to allow conflict names", default=False, ) parser.add_argument( "--getattr", action="store_true", help=( "Whether to test datar.all.sum, " "otherwise test from datar.all import sum." ), default=False, ) parser.add_argument( "--fun", help=( "The function to test. " "If _ then sum for all/base, slice for dplyr" ), choices=["sum", "filter", "_"], default="_", ) parser.add_argument( "--error", help="The error to expect", ) args = parser.parse_args() make_test( args.module, args.allow_conflict_names, args.getattr, args.fun, args.error, ) if __name__ == "__main__": main() ================================================ FILE: tests/conftest.py ================================================ from datar import options def pytest_sessionstart(session): # Load no plugins options(backends=[None]) ================================================ FILE: tests/test_array_ufunc.py ================================================ import pytest # noqa: F401 import numpy as np from pipda import Context from datar import f from datar.core import plugin as _ # noqa: F401 from datar.apis.misc import array_ufunc def test_default(): out = np.sqrt(f)._pipda_eval([1, 4, 9], Context.EVAL) assert out.tolist() == [1, 2, 3] def test_misc_obj(): class Foo(list): pass @array_ufunc.register(Foo) def _array_ufunc(x, ufunc, *args, kind, **kwargs): return ufunc([i * 2 for i in x], *args, **kwargs) out = np.sqrt(f)._pipda_eval(Foo([2, 8, 18]), Context.EVAL) assert out.tolist() == [2, 4, 6] ================================================ FILE: tests/test_base.py ================================================ import pytest from datar.base import ( ceiling, cov, floor, mean, median, pmax, pmin, sqrt, var, scale, col_sums, col_means, col_sds, col_medians, row_sums, row_means, row_sds, row_medians, min_, max_, round_, sum_, abs_, prod, sign, signif, trunc, exp, log, log2, log10, log1p, sd, weighted_mean, quantile, bessel_i, bessel_j, bessel_k, bessel_y, as_double, as_integer, as_logical, as_character, as_factor, as_ordered, as_date, as_numeric, arg, conj, mod, re_, im, as_complex, is_complex, cummax, cummin, cumprod, cumsum, droplevels, levels, set_levels, is_factor, is_ordered, nlevels, factor, ordered, cut, diff, expand_grid, outer, make_names, make_unique, rank, identity, is_logical, is_true, is_false, is_na, is_finite, is_infinite, any_na, as_null, is_null, set_seed, rep, c_, c, length, lengths, order, sort, rev, sample, seq, seq_along, seq_len, match, beta, lgamma, digamma, trigamma, choose, factorial, gamma, lfactorial, lchoose, lbeta, psigamma, rnorm, runif, rpois, rbinom, rcauchy, rchisq, rexp, is_character, grep, grepl, sub, gsub, strsplit, paste, paste0, sprintf, substr, substring, startswith, endswith, strtoi, trimws, toupper, tolower, chartr, nchar, nzchar, table, tabulate, is_atomic, is_double, is_element, is_integer, is_numeric, any_, all_, acos, acosh, asin, asinh, atan, atanh, cos, cosh, cospi, sin, sinh, sinpi, tan, tanh, tanpi, atan2, append, colnames, set_colnames, rownames, set_rownames, dim, diag, duplicated, intersect, ncol, nrow, proportions, setdiff, setequal, unique, t, union, max_col, complete_cases, head, tail, which, which_min, which_max, ) from datar.core.utils import NotImplementedByCurrentBackendError @pytest.mark.parametrize("fun,args", [ (ceiling, [1]), (cov, [[1, 2], [3, 4]]), (floor, [1]), (mean, [1]), (median, [1]), (pmax, [1]), (pmin, [1]), (sqrt, [1]), (var, [1]), (scale, [1]), (col_sums, [1]), (col_means, [1]), (col_sds, [1]), (col_medians, [1]), (row_sums, [1]), (row_means, [1]), (row_sds, [1]), (row_medians, [1]), (min_, [1]), (max_, [1]), (round_, [1]), (sum_, [1]), (abs_, [1]), (prod, [1]), (sign, [1]), (signif, [1]), (trunc, [1]), (exp, [1]), (log, [1]), (log2, [1]), (log10, [1]), (log1p, [1]), (sd, [1]), (weighted_mean, [1]), (quantile, [1]), (bessel_i, [1, 2]), (bessel_j, [1, 2]), (bessel_k, [1, 2]), (bessel_y, [1, 2]), (as_double, [1]), (as_integer, [1]), (as_logical, [1]), (as_character, [1]), (as_factor, [1]), (as_ordered, [1]), (as_date, [1]), (as_numeric, [1]), (arg, [1]), (conj, [1]), (mod, [1]), (re_, [1]), (im, [1]), (as_complex, [1]), (is_complex, [1]), (cummax, [1]), (cummin, [1]), (cumprod, [1]), (cumsum, [1]), (droplevels, [1]), (levels, [1]), (set_levels, [1, 1]), (is_factor, [1]), (is_ordered, [1]), (nlevels, [1]), (factor, [1]), (ordered, [1]), (cut, [1, 1]), (diff, [1]), (expand_grid, [1]), (outer, [1, 1]), (rank, [1]), (is_logical, [1]), (is_true, [1]), (is_false, [1]), (is_na, [1]), (is_finite, [1]), (is_infinite, [1]), (any_na, [1]), (as_null, [1]), (is_null, [1]), (set_seed, [1]), (rep, [1]), (c_, [1]), (c, [1]), (length, [1]), (lengths, [1]), (order, [1]), (rev, [1]), (seq, [1]), (seq_along, [1]), (seq_len, [1]), (sort, [1]), (sample, [1]), (match, [1, 1]), (is_element, [1, 1]), (is_atomic, [1]), (is_double, [1]), (is_integer, [1]), (is_numeric, [1]), (any_, [1]), (all_, [1]), (acos, [1]), (acosh, [1]), (asin, [1]), (asinh, [1]), (atan, [1]), (atanh, [1]), (cos, [1]), (cosh, [1]), (cospi, [1]), (sin, [1]), (sinh, [1]), (sinpi, [1]), (tan, [1]), (tanh, [1]), (tanpi, [1]), (atan2, [1, 1]), (beta, [1, 1]), (choose, [1, 1]), (digamma, [1]), (lgamma, [1]), (lbeta, [1, 1]), (trigamma, [1]), (factorial, [1]), (gamma, [1]), (lchoose, [1, 1]), (lfactorial, [1]), (psigamma, [1, 1]), (rnorm, [1, 1]), (runif, [1, 1]), (rcauchy, [1, 1]), (rchisq, [1, 1]), (rexp, [1, 1]), (rpois, [1, 1]), (rbinom, [1, 1, 1]), (is_character, [1]), (grep, [1, 1]), (grepl, [1, 1]), (sub, [1, 1, 1]), (gsub, [1, 1, 1]), (strsplit, [1, 1]), (paste, [1]), (paste0, [1]), (sprintf, [1]), (substr, [1, 1, 1]), (tolower, [1]), (toupper, [1]), (trimws, [1]), (strtoi, [1]), (substring, [1, 1]), (startswith, [1, 1]), (endswith, [1, 1]), (chartr, [1, 1, 1]), (nchar, [1]), (nzchar, [1]), (table, [1]), (tabulate, [1]), (append, [1, 1]), (colnames, [1]), (set_colnames, [1, 1]), (rownames, [1]), (set_rownames, [1, 1]), (dim, [1]), (diag, [1]), (duplicated, [1]), (intersect, [1, 1]), (ncol, [1]), (nrow, [1]), (proportions, [1]), (setdiff, [1, 1]), (setequal, [1, 1]), (unique, [1]), (union, [1, 1]), (t, [1]), (max_col, [1]), (complete_cases, [1]), (head, [1]), (tail, [1]), (which, [1]), (which_min, [1]), (which_max, [1]), ]) def test_default_implementation(fun, args): with pytest.raises(NotImplementedByCurrentBackendError): fun(*args) @pytest.mark.parametrize("x, uniq, y", [ (["a", "b", "c"], False, ["a", "b", "c"]), ("a", False, ["a"]), (1, False, ["_1"]), ]) def test_make_names(x, uniq, y): out = make_names(x, uniq) assert out == y @pytest.mark.parametrize("x, y", [ (["a", "b", "c"], ["a", "b", "c"]), ("a", ["a"]), ]) def test_make_unique(x, y): out = make_unique(x) assert out == y def test_identify(): out = identity(1) assert out == 1 ================================================ FILE: tests/test_conflict_names.py ================================================ import sys import subprocess from pathlib import Path import pytest def _run_conflict_names(module, allow_conflict_names, getat, error): here = Path(__file__).parent conflict_names = here / "conflict_names.py" cmd = [ sys.executable, str(conflict_names), "--module", module, ] if error: cmd += ["--error", error] if allow_conflict_names: cmd.append("--allow-conflict-names") if getat: cmd.append("--getattr") p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) return p.wait(), " ".join(cmd) def test_from_all_import_allow_conflict_names_true(): r, cmd = _run_conflict_names("all", True, False, None) assert r == 0, cmd def test_from_all_import_allow_conflict_names_false(): r, cmd = _run_conflict_names("all", False, False, "ImportError") assert r == 0, cmd def test_all_getattr_allow_conflict_names_true(): r, cmd = _run_conflict_names("all", True, True, None) assert r == 0, cmd def test_all_getattr_allow_conflict_names_false(): r, cmd = _run_conflict_names("all", False, True, None) assert r == 0, cmd def test_from_base_import_allow_conflict_names_true(): r, cmd = _run_conflict_names("base", True, False, None) assert r == 0, cmd def test_from_base_import_allow_conflict_names_false(): r, cmd = _run_conflict_names("base", False, False, "ImportError") assert r == 0, cmd def test_base_getattr_allow_conflict_names_true(): r, cmd = _run_conflict_names("base", True, True, None) assert r == 0, cmd def test_base_getattr_allow_conflict_names_false(): r, cmd = _run_conflict_names("base", False, True, None) assert r == 0, cmd def test_from_dplyr_import_allow_conflict_names_true(): r, cmd = _run_conflict_names("dplyr", True, False, None) assert r == 0, cmd def test_from_dplyr_import_allow_conflict_names_false(): r, cmd = _run_conflict_names("dplyr", False, False, "ImportError") assert r == 0, cmd def test_dplyr_getattr_allow_conflict_names_true(): r, cmd = _run_conflict_names("dplyr", True, True, None) assert r == 0, cmd def test_dplyr_getattr_allow_conflict_names_false(): r, cmd = _run_conflict_names("dplyr", False, True, None) assert r == 0, cmd ================================================ FILE: tests/test_data.py ================================================ import pytest from datar.data import descr_datasets, add_dataset from datar.core.utils import NotImplementedByCurrentBackendError def test_descr_datasets(): x = descr_datasets() assert "iris" in x x = descr_datasets("iris") assert "iris" in x and len(x) == 1 def test_add_dataset(): add_dataset("test", {"url": ""}) assert "test" in descr_datasets() def test_load_dataset(): with pytest.raises(NotImplementedByCurrentBackendError): from datar.data import iris # noqa: F401 def test_no_such(): with pytest.raises(NotImplementedByCurrentBackendError): from datar.data import nosuch # noqa: F401 ================================================ FILE: tests/test_dplyr.py ================================================ import pytest from datar.core.utils import NotImplementedByCurrentBackendError from datar.dplyr import ( across, add_count, add_tally, all_of, anti_join, any_of, arrange, between, bind_cols, bind_rows, c_across, case_when, coalesce, contains, count, cumall, cumany, cume_dist, cummean, cur_column, cur_data, cur_data_all, cur_group, cur_group_id, cur_group_rows, dense_rank, desc, distinct, ends_with, everything, filter_, first, full_join, glimpse, group_by, group_by_drop_default, group_cols, group_data, group_indices, group_keys, group_map, group_modify, group_rows, group_size, group_split, group_trim, group_vars, group_walk, if_all, if_any, if_else, inner_join, lag, last, last_col, lead, left_join, matches, min_rank, mutate, n, n_distinct, n_groups, na_if, near, nest_join, nth, ntile, num_range, order_by, percent_rank, pull, recode, recode_factor, reframe, relocate, rename, rename_with, right_join, row_number, rows_append, rows_delete, rows_insert, rows_patch, rows_update, rows_upsert, rowwise, select, semi_join, slice_, slice_head, slice_min, slice_sample, slice_tail, slice_max, starts_with, summarise, tally, transmute, ungroup, union_all, where, with_groups, with_order, pick, symdiff, consecutive_id, case_match, cross_join, ) @pytest.mark.parametrize("verb, data, args, kwargs", [ (add_count, None, [], None), (add_tally, None, [], None), (anti_join, None, [None], None), (arrange, None, [], None), (between, None, [1, 2], None), (bind_cols, None, [], None), (bind_rows, None, [], None), (case_when, None, [1], None), (coalesce, None, [], None), (count, None, [], None), (cumall, None, [], None), (cumany, None, [], None), (cume_dist, None, [], None), (cummean, None, [], None), (cur_column, None, [1], None), (dense_rank, None, [], None), (desc, None, [], None), (distinct, None, [], None), (filter_, None, [], None), (first, None, [], None), (full_join, None, [1], None), (glimpse, None, [], None), (group_by, None, [], None), (group_by_drop_default, None, [], None), (group_cols, None, [], None), (group_data, None, [], None), (group_indices, None, [], None), (group_keys, None, [], None), (group_map, None, [1], None), (group_modify, None, [1], None), (group_rows, None, [], None), (group_size, None, [], None), (group_split, None, [], None), (group_trim, None, [], None), (group_vars, None, [], None), (group_walk, None, [1], None), (if_else, None, [1, 2], None), (inner_join, None, [1], None), (lag, None, [], None), (last, None, [], None), (lead, None, [], None), (left_join, None, [1], None), (min_rank, None, [], None), (mutate, None, [], None), (n_distinct, None, [], None), (n_groups, None, [], None), (na_if, None, [1], None), (near, None, [1], None), (nest_join, None, [1], None), (nth, None, [1], None), (ntile, None, [], None), (num_range, None, [1], None), (order_by, None, [1], None), (percent_rank, None, [], None), (pull, None, [], None), (recode, None, [], None), (recode_factor, None, [], None), (reframe, None, [], None), (relocate, None, [], None), (rename, None, [], None), (rename_with, None, [1], None), (right_join, None, [1], None), (row_number, None, [], None), (rows_append, None, [None], None), (rows_delete, None, [None], None), (rows_insert, None, [None], None), (rows_patch, None, [None], None), (rows_update, None, [None], None), (rows_upsert, None, [None], None), (rowwise, None, [], None), (select, None, [], None), (semi_join, None, [1], None), (slice_, None, [], None), (slice_head, None, [], None), (slice_min, None, [1], None), (slice_sample, None, [], None), (slice_tail, None, [], None), (slice_max, None, [1], None), (summarise, None, [], None), (tally, None, [], None), (transmute, None, [], None), (ungroup, None, [], None), (union_all, None, [1], None), (with_groups, None, [1, 2], None), (with_order, None, [1, 2], None), (symdiff, None, [None], None), (consecutive_id, None, [], None), (case_match, None, [], None), (cross_join, None, [1], None), ]) def test_verb_not_implemented(verb, data, args, kwargs): kwargs = kwargs or {} with pytest.raises(NotImplementedByCurrentBackendError): verb(data, *args, **kwargs) @pytest.mark.parametrize("verb, data, args, kwargs", [ (pick, None, [], None), (across, None, [], None), (if_any, None, [], None), (if_all, None, [], None), (c_across, None, [], None), (cur_data, None, [], None), (n, None, [], None), (cur_data_all, None, [], None), (cur_group, None, [], None), (cur_group_id, None, [], None), (cur_group_rows, None, [], None), (where, None, [1], None), (everything, None, [], None), (last_col, None, [], None), (starts_with, None, [1], None), (ends_with, None, [1], None), (contains, None, [1], None), (matches, None, [1], None), (all_of, None, [1], None), (any_of, None, [1], None), ]) def test_dep_verbs(verb, data, args, kwargs): kwargs = kwargs or {} with pytest.raises(NotImplementedByCurrentBackendError): data >> verb(*args, **kwargs) ================================================ FILE: tests/test_forcats.py ================================================ import pytest # noqa: F401 from datar.core.utils import NotImplementedByCurrentBackendError from datar.forcats import ( fct_anon, fct_c, fct_collapse, fct_count, fct_cross, fct_drop, fct_expand, fct_explicit_na, fct_infreq, fct_inorder, fct_inseq, fct_lump, fct_lump_lowfreq, fct_lump_min, fct_lump_n, fct_lump_prop, fct_match, fct_other, fct_recode, fct_relabel, fct_relevel, fct_reorder, fct_reorder2, fct_rev, fct_shift, fct_shuffle, fct_unify, fct_unique, first2, last2, lvls_expand, lvls_reorder, lvls_revalue, lvls_union, ) @pytest.mark.parametrize("verb, data, args, kwargs", [ (fct_anon, None, [], None), (fct_c, None, [], None), (fct_collapse, None, [], None), (fct_count, None, [], None), (fct_cross, None, [], None), (fct_drop, None, [], None), (fct_expand, None, [], None), (fct_explicit_na, None, [], None), (fct_infreq, None, [], None), (fct_inorder, None, [], None), (fct_inseq, None, [], None), (fct_lump, None, [], None), (fct_lump_lowfreq, None, [], None), (fct_lump_min, None, [1], None), (fct_lump_n, None, [1], None), (fct_lump_prop, None, [1], None), (fct_match, None, [1], None), (fct_other, None, [], None), (fct_recode, None, [], None), (fct_relabel, None, [1], None), (fct_relevel, None, [], None), (fct_reorder, None, [1], None), (fct_reorder2, None, [1], None), (fct_rev, None, [], None), (fct_shift, None, [], None), (fct_shuffle, None, [], None), (fct_unify, None, [], None), (fct_unique, None, [], None), (first2, None, [1], None), (last2, None, [1], None), (lvls_expand, None, [1], None), (lvls_reorder, None, [1], None), (lvls_revalue, None, [1], None), (lvls_union, None, [], None), ]) def test_default_impl(verb, data, args, kwargs): kwargs = kwargs or {} with pytest.raises(NotImplementedByCurrentBackendError): verb(data, *args, **kwargs) ================================================ FILE: tests/test_names.py ================================================ # https://github.com/r-lib/vctrs/blob/master/tests/testthat/test-names.R import pytest from typing import Iterable import numpy as np from string import ascii_letters from datar.core.names import ( NameNonUniqueError, repair_names, ) @pytest.mark.parametrize( "names,expect", [ ([1, 2, 3], ["1", "2", "3"]), (["", np.nan], ["", ""]), (["", np.nan], ["", ""]), (["", "", np.nan], ["", "", ""]), (repair_names(["", "", np.nan], repair="minimal"), ["", "", ""]), ], ) def test_minimal(names, expect): assert repair_names(names, repair="minimal") == expect @pytest.mark.parametrize( "names,expect", [ ([np.nan, np.nan], ["__0", "__1"]), (["x", "x"], ["x__0", "x__1"]), (["x", "y"], ["x", "y"]), (["", "x", "y", "x"], ["__0", "x__1", "y", "x__3"]), ([""], ["__0"]), ([np.nan], ["__0"]), ( ["__20", "a__33", "b", "", "a__2__34"], ["__0", "a__1", "b", "__3", "a__4"], ), (["a__1"], ["a"]), (["a__2", "a"], ["a__0", "a__1"]), (["a__3", "a", "a"], ["a__0", "a__1", "a__2"]), (["a__2", "a", "a"], ["a__0", "a__1", "a__2"]), (["a__2", "a__2", "a__2"], ["a__0", "a__1", "a__2"]), ( ["__20", "a__1", "b", "", "a__2"], ["__0", "a__1", "b", "__3", "a__4"], ), ( repair_names(["__20", "a__1", "b", "", "a__2"], repair="unique"), ["__0", "a__1", "b", "__3", "a__4"], ), ( ["", "x", "", "y", "x", "_2", "__"], ["__0", "x__1", "__2", "y", "x__4", "__5", "__6"], ), ], ) def test_unique(names, expect): assert repair_names(names, repair="unique") == expect def test_unique_algebraic_y(): x = ["__20", "a__1", "b", "", "a__2", "d"] y = ["", "a__3", "b", "__3", "e"] # fix names on each, catenate, fix the whole z1 = repair_names( repair_names(x, repair="unique") + repair_names(y, repair="unique"), repair="unique", ) z2 = repair_names(repair_names(x, repair="unique") + y, repair="unique") z3 = repair_names(x + repair_names(y, repair="unique"), repair="unique") z4 = repair_names(x + y, repair="unique") assert z1 == z2 == z3 == z4 @pytest.mark.parametrize( "names,expect", [ (list(ascii_letters), list(ascii_letters)), ( [np.nan, "", "x", "x", "a1:", "_x_y}"], ["__0", "__1", "x__2", "x__3", "a1_", "_x_y_"], ), ( repair_names( [np.nan, "", "x", "x", "a1:", "_x_y}"], repair="universal" ), ["__0", "__1", "x__2", "x__3", "a1_", "_x_y_"], ), (["a", "b", "a", "c", "b"], ["a__0", "b__1", "a__2", "c", "b__4"]), ([""], ["__0"]), ([np.nan], ["__0"]), (["__"], ["__0"]), (["_"], ["_"]), (["_", "_"], ["___0", "___1"]), (["", "_"], ["__0", "_"]), (["", "", "_"], ["__0", "__1", "_"]), (["_", "_", ""], ["___0", "___1", "__2"]), (["_", "", "_"], ["___0", "__1", "___2"]), (["", "_", ""], ["__0", "_", "__2"]), (["__6", "__1__2"], ["__0", "__1"]), (["if__2"], ["_if"]), ( ["", "_", np.nan, "if__4", "if", "if__8", "for", "if){]1"], [ "__0", "_", "__2", "_if__3", "_if__4", "_if__5", "_for", "if___1", ], ), (["a b", "b c"], ["a_b", "b_c"]), ( ["", "_2", "_3", "__4", "___5", "____6", "_____7", "__"], ["__0", "__1", "__2", "__3", "___5", "____6", "_____7", "__7"], ), ( repair_names( ["", "_2", "_3", "__4", "___5", "____6", "_____7", "__"], repair="unique", ), ["__0", "__1", "__2", "__3", "___5", "____6", "_____7", "__7"], ), ( [7, 4, 3, 6, 5, 1, 2, 8], ["_7", "_4", "_3", "_6", "_5", "_1", "_2", "_8"], ), ( repair_names([7, 4, 3, 6, 5, 1, 2, 8], repair="unique"), ["_7", "_4", "_3", "_6", "_5", "_1", "_2", "_8"], ), ], ) def test_universal(names, expect): assert repair_names(names, repair="universal") == expect def test_check_unique(): with pytest.raises(NameNonUniqueError): repair_names([np.nan], repair="check_unique") with pytest.raises(NameNonUniqueError): repair_names([""], repair="check_unique") with pytest.raises(NameNonUniqueError): repair_names(["a", "a"], repair="check_unique") with pytest.raises(NameNonUniqueError): repair_names(["__1"], repair="check_unique") with pytest.raises(NameNonUniqueError): repair_names(["__"], repair="check_unique") assert repair_names(["a", "b"], repair="check_unique") == ["a", "b"] def test_custom_repair(): def replace(names: Iterable[str]): return ["a", "b", "c"] out = repair_names([1, 2, 3], repair=replace) assert out == ["a", "b", "c"] with pytest.raises(ValueError): repair_names([1, 2, 3], repair=1) out = repair_names(["a", "b", "c"], repair=str.upper) assert out == ["A", "B", "C"] out = repair_names(["a", "b", "c"], repair=["x", "y", "z"]) assert out == ["x", "y", "z"] ================================================ FILE: tests/test_options.py ================================================ import pytest from datar.core.options import ( options, options_context, add_option, get_option, ) @pytest.fixture(autouse=True) def reset_options(): opts = options() add_option("x_y_z", True) yield options(opts) def test_options_empty_args_returns_full_options(): from datar.core.options import OPTIONS out = options() assert out == OPTIONS def test_options_with_names_only_selects_options(): out = options("x_y_z") assert len(out) == 1 assert out["x_y_z"] def test_opts_with_names_nameval_pairs_mixed_rets_sel_opts_and_changes_option(): out = options(x_y_z=False, _return=True) assert out == {"x_y_z": True} assert not get_option("x.y.z") def test_options_with_dict_updates_options(): out = options({"x_y_z": True}, _return=True) assert get_option("x_y_z") assert out.x_y_z def test_options_context(): assert get_option("x_y_z") with options_context(x_y_z=False): assert not get_option("x_y_z") assert get_option("x_y_z") ================================================ FILE: tests/test_pipe.py ================================================ import pytest from datar.all import pipe def test_pipe_with_list(): """Test pipe with a list""" data = [1, 2, 3, 4, 5] result = data >> pipe(lambda x: [i * 2 for i in x]) expected = [2, 4, 6, 8, 10] assert result == expected def test_pipe_with_dict(): """Test pipe with a dictionary""" data = {'a': 1, 'b': 2, 'c': 3} result = data >> pipe(lambda x: {k: v * 2 for k, v in x.items()}) expected = {'a': 2, 'b': 4, 'c': 6} assert result == expected def test_pipe_with_args(): """Test pipe with additional positional arguments""" data = [1, 2, 3] def add_value(data, value): return [x + value for x in data] result = data >> pipe(add_value, 10) expected = [11, 12, 13] assert result == expected def test_pipe_with_kwargs(): """Test pipe with keyword arguments""" data = [1, 2, 3] def multiply_data(data, factor=1): return [x * factor for x in data] result = data >> pipe(multiply_data, factor=10) expected = [10, 20, 30] assert result == expected def test_pipe_with_string(): """Test pipe with string operations""" data = "hello" result = data >> pipe(lambda x: x.upper()) assert result == "HELLO" def test_pipe_with_tuple(): """Test pipe with tuple""" data = (1, 2, 3) result = data >> pipe(lambda x: tuple(i * 2 for i in x)) expected = (2, 4, 6) assert result == expected def test_pipe_returns_different_type(): """Test that pipe can return different types""" data = [1, 2, 3, 4, 5] result = data >> pipe(sum) assert result == 15 def test_pipe_chain_multiple(): """Test chaining multiple pipe operations""" data = [1, 2, 3] result = ( data >> pipe(lambda x: [i * 2 for i in x]) >> pipe(lambda x: [i + 1 for i in x]) ) expected = [3, 5, 7] assert result == expected def test_pipe_with_custom_class(): """Test pipe with a custom class""" class Counter: def __init__(self, value): self.value = value def increment(self, amount): return Counter(self.value + amount) def __eq__(self, other): return self.value == other.value counter = Counter(5) result = counter >> pipe(lambda x: x.increment(10)) expected = Counter(15) assert result == expected def test_pipe_with_multiple_args_and_kwargs(): """Test pipe with both args and kwargs""" data = [1, 2, 3] def transform(data, multiplier, offset=0): return [x * multiplier + offset for x in data] result = data >> pipe(transform, 2, offset=5) expected = [7, 9, 11] assert result == expected ================================================ FILE: tests/test_plugin.py ================================================ import pytest import numpy as np from simplug import MultipleImplsForSingleResultHookWarning from pipda import Context from pipda.utils import MultiImplementationsWarning from datar import f from datar.core.plugin import plugin from datar.core.operator import DatarOperator class TestPlugin1: @plugin.impl def get_versions(): return {"abc": "1.2.3"} @plugin.impl def load_dataset(name, metadata): return name * 2 @plugin.impl def misc_api(): from datar.apis.misc import array_ufunc @array_ufunc.register(object, backend="testplugin1") def _array_ufunc(x, ufunc, *args, kind, **kwargs): return ufunc([i * 3 for i in x], *args, **kwargs) return {"other_var": 1} @plugin.impl def operate(op, x, y=None): if op == "add": return x + y + x * y return None @plugin.impl def c_getitem(item): return item * 2 class TestPlugin2: @plugin.impl def load_dataset(name, metadata): return name * 3 @plugin.impl def c_getitem(item): return item * 4 @plugin.impl def operate(op, x, y=None): if op == "add": return x + y + 2 * x * y return None def setup_function(function): plugin.register(TestPlugin1) plugin.register(TestPlugin2) plugin.get_plugin("testplugin1").disable() plugin.get_plugin("testplugin2").disable() @pytest.fixture def with_test_plugin1(): plugin.get_plugin("testplugin1").enable() yield plugin.get_plugin("testplugin1").disable() @pytest.fixture def with_test_plugin2(): plugin.get_plugin("testplugin2").enable() yield plugin.get_plugin("testplugin2").disable() def test_get_versions(with_test_plugin1, capsys): from datar import get_versions assert get_versions(prnt=False)["abc"] == "1.2.3" get_versions() assert "datar" in capsys.readouterr().out def test_misc_api(with_test_plugin1): from datar import all, misc plugin.hooks.misc_api() from importlib import reload reload(misc) assert misc.other_var == 1 reload(all) from datar.all import other_var assert other_var == 1 def test_misc_api_array_ufunc(with_test_plugin1): from datar import f from datar.apis.misc import array_ufunc plugin.hooks.misc_api() with pytest.warns(MultiImplementationsWarning): out = np.sqrt(f)._pipda_eval([3, 12, 27], Context.EVAL) assert out.tolist() == [3, 6, 9] with array_ufunc.with_backend("_default"): out = np.sqrt(f)._pipda_eval([1, 4, 9], Context.EVAL) assert out.tolist() == [1, 2, 3] def test_load_dataset(with_test_plugin1, with_test_plugin2): with pytest.warns(MultipleImplsForSingleResultHookWarning): from datar.data import iris assert iris == "irisirisiris" from datar.data import load_dataset assert load_dataset("iris", __backend="testplugin1") == "irisiris" def test_operate(with_test_plugin1): expr = f[0] + f[1] assert expr._pipda_eval([3, 2], Context.EVAL) == 11 def test_operate2(with_test_plugin1, with_test_plugin2): expr = f[0] + f[1] with pytest.warns(MultipleImplsForSingleResultHookWarning): assert expr._pipda_eval([3, 2], Context.EVAL) == 17 with DatarOperator.with_backend("testplugin1"): assert expr._pipda_eval([3, 2], Context.EVAL) == 11 with pytest.warns(MultipleImplsForSingleResultHookWarning): assert expr._pipda_eval([3, 2], Context.EVAL) == 17 def test_c_getitem(with_test_plugin1): from datar.base import c assert c[11] == 22 def test_c_getitem2(with_test_plugin1, with_test_plugin2): from datar.base import c with pytest.warns(MultipleImplsForSingleResultHookWarning): assert c[11] == 44 with c.with_backend("testplugin1"): assert c[11] == 22 with pytest.warns(MultipleImplsForSingleResultHookWarning): assert c[11] == 44 ================================================ FILE: tests/test_tibble.py ================================================ import pytest # noqa: F401 from datar.core.utils import NotImplementedByCurrentBackendError from datar.tibble import ( add_column, add_row, as_tibble, column_to_rownames, deframe, enframe, has_rownames, remove_rownames, rowid_to_column, rownames_to_column, tibble, tibble_, tibble_row, tribble, ) @pytest.mark.parametrize("verb, data, args, kwargs", [ (add_column, None, [1], None), (add_row, None, [1], None), (as_tibble, None, [], None), (column_to_rownames, None, [], None), (deframe, None, [], None), (enframe, None, [], None), (has_rownames, None, [], None), (remove_rownames, None, [], None), (rowid_to_column, None, ["x"], None), (rownames_to_column, None, ["x"], None), (tibble, None, [], None), (tibble_, None, [], None), (tibble_row, None, [], None), (tribble, None, [], None), ]) def test_default_impl(verb, data, args, kwargs): kwargs = kwargs or {} with pytest.raises(NotImplementedByCurrentBackendError): verb(data, *args, **kwargs) ================================================ FILE: tests/test_tidyr.py ================================================ import pytest from datar.core.utils import NotImplementedByCurrentBackendError from datar.tidyr import ( chop, complete, crossing, drop_na, expand, extract, fill, full_seq, nest, nesting, pack, pivot_longer, pivot_wider, replace_na, separate, separate_rows, unchop, uncount, unite, unnest, unpack, ) @pytest.mark.parametrize("verb, data, args, kwargs", [ (chop, None, [], None), (complete, None, [], None), (crossing, None, [], None), (drop_na, None, [], None), (expand, None, [], None), (extract, None, [1, 1], None), (fill, None, [], None), (full_seq, None, [1], None), (nest, None, [], None), (nesting, None, [], None), (pack, None, [], None), (pivot_longer, None, [1], None), (pivot_wider, None, [], None), (replace_na, None, [], None), (separate, None, [1, 1], None), (separate_rows, None, [], None), (unchop, None, [], None), (uncount, None, [1], None), (unite, None, [1], None), (unnest, None, [], None), (unpack, None, [1], None), ]) def test_default_impl(verb, data, args, kwargs): kwargs = kwargs or {} with pytest.raises(NotImplementedByCurrentBackendError): verb(data, *args, **kwargs) ================================================ FILE: tests/test_utils.py ================================================ import pytest from datar.core.utils import arg_match def test_arg_match(): with pytest.raises(ValueError, match='abc'): arg_match('a', 'a', ['b', 'c'], errmsg='abc') with pytest.raises(ValueError, match='must be one of'): arg_match('a', 'a', ['b', 'c']) assert arg_match('a', 'a', ['a', 'b', 'c']) == 'a' ================================================ FILE: tests/test_verb_env.py ================================================ """Tests for verb environment variable support""" import os import pytest def test_env_var_global(): """Test global environment variable DATAR_VERB_AST_FALLBACK""" # Set the global environment variable os.environ["DATAR_VERB_AST_FALLBACK"] = "piping" try: from datar.core.verb_env import get_verb_ast_fallback # Test that the function reads the environment variable result = get_verb_ast_fallback("test_verb") assert result == "piping" finally: # Clean up del os.environ["DATAR_VERB_AST_FALLBACK"] def test_env_var_per_verb(): """Test per-verb environment variable DATAR__AST_FALLBACK""" # Set a per-verb environment variable os.environ["DATAR_SELECT_AST_FALLBACK"] = "normal" try: from datar.core.verb_env import get_verb_ast_fallback # Test that the function reads the per-verb environment variable result = get_verb_ast_fallback("select") assert result == "normal" finally: # Clean up del os.environ["DATAR_SELECT_AST_FALLBACK"] def test_env_var_per_verb_with_trailing_underscore(): """Test per-verb environment variable for verbs with trailing underscore""" # Set a per-verb environment variable for filter_ verb os.environ["DATAR_FILTER_AST_FALLBACK"] = "raise" try: from datar.core.verb_env import get_verb_ast_fallback # Test that the function reads the per-verb environment variable # even when the function name has a trailing underscore result = get_verb_ast_fallback("filter_") assert result == "raise" finally: # Clean up del os.environ["DATAR_FILTER_AST_FALLBACK"] def test_env_var_precedence(): """Test that per-verb environment variable takes precedence over global""" os.environ["DATAR_VERB_AST_FALLBACK"] = "piping" os.environ["DATAR_MUTATE_AST_FALLBACK"] = "normal" try: from datar.core.verb_env import get_verb_ast_fallback # For mutate, the per-verb setting should take precedence result = get_verb_ast_fallback("mutate") assert result == "normal" # For other verbs, the global setting should be used result = get_verb_ast_fallback("select") assert result == "piping" finally: # Clean up del os.environ["DATAR_VERB_AST_FALLBACK"] del os.environ["DATAR_MUTATE_AST_FALLBACK"] def test_env_var_not_set(): """Test behavior when no environment variable is set""" # Ensure no relevant environment variables are set for key in list(os.environ.keys()): if key.startswith("DATAR_") and key.endswith("_AST_FALLBACK"): del os.environ[key] from datar.core.verb_env import get_verb_ast_fallback # Should return None when no environment variable is set result = get_verb_ast_fallback("test_verb") assert result is None def test_verb_with_env_var(): """Test that verbs can use the helper function""" os.environ["DATAR_VERB_AST_FALLBACK"] = "normal" try: from pipda import register_verb from datar.core.verb_env import get_verb_ast_fallback # Define a simple test verb using the helper @register_verb(ast_fallback=get_verb_ast_fallback("test_verb")) def test_verb(data): """Test verb""" return data # The verb should be registered assert callable(test_verb) finally: # Clean up del os.environ["DATAR_VERB_AST_FALLBACK"] def test_explicit_ast_fallback_with_env_var(): """Test that explicit ast_fallback is used even when env var is set""" os.environ["DATAR_VERB_AST_FALLBACK"] = "normal" try: from pipda import register_verb from datar.core.verb_env import get_verb_ast_fallback # When we explicitly pass an ast_fallback, it should be used # But if we use the helper, it will return the env var value # This test verifies the helper returns the env var result = get_verb_ast_fallback("test_verb") assert result == "normal" finally: # Clean up del os.environ["DATAR_VERB_AST_FALLBACK"] ================================================ FILE: tests/test_verb_env_integration.py ================================================ """Integration test to demonstrate the environment variable feature""" import os import pytest def test_verb_ast_fallback_piping(): """Test that DATAR_*_AST_FALLBACK works with piping mode""" from pipda import register_verb from datar.core.verb_env import get_verb_ast_fallback # Set environment variable for piping mode os.environ['DATAR_PLUS_AST_FALLBACK'] = 'piping' try: # Register a simple verb @register_verb(ast_fallback=get_verb_ast_fallback("plus")) def plus(x, y): return x + y # Test with exec to disable source code detection at runtime # In piping mode, piping call should work result = {} exec("result['val'] = 1 >> plus(1)", {"plus": plus, "result": result}) assert result['val'] == 2 # Normal call in piping mode returns a placeholder when AST is not available result = {} exec("result['val'] = plus(1, 1)", {"plus": plus, "result": result}) # The result is a placeholder object, not the actual computation assert str(result['val']) == 'plus(., 1, 1)' finally: del os.environ['DATAR_PLUS_AST_FALLBACK'] def test_verb_ast_fallback_normal(): """Test that DATAR_*_AST_FALLBACK works with normal mode""" from pipda import register_verb from datar.core.verb_env import get_verb_ast_fallback # Set environment variable for normal mode os.environ['DATAR_MINUS_AST_FALLBACK'] = 'normal' try: # Register a simple verb @register_verb(ast_fallback=get_verb_ast_fallback("minus")) def minus(x, y): return x - y # Test with exec to disable source code detection at runtime # In normal mode, normal call should work result = {} exec("result['val'] = minus(5, 3)", {"minus": minus, "result": result}) assert result['val'] == 2 # Piping call in normal mode raises TypeError when AST is not available result = {} with pytest.raises(TypeError): exec("result['val'] = 5 >> minus(3)", {"minus": minus, "result": result}) finally: del os.environ['DATAR_MINUS_AST_FALLBACK'] def test_verb_ast_fallback_global(): """Test that DATAR_VERB_AST_FALLBACK works as global fallback""" from pipda import register_verb from datar.core.verb_env import get_verb_ast_fallback # Set global environment variable os.environ['DATAR_VERB_AST_FALLBACK'] = 'piping' try: # Register verbs without specific env var @register_verb(ast_fallback=get_verb_ast_fallback("multiply")) def multiply(x, y): return x * y @register_verb(ast_fallback=get_verb_ast_fallback("divide")) def divide(x, y): return x / y # Both should use global piping mode result = {} exec("result['mul'] = 6 >> multiply(2)", {"multiply": multiply, "result": result}) assert result['mul'] == 12 exec("result['div'] = 10 >> divide(2)", {"divide": divide, "result": result}) assert result['div'] == 5 finally: del os.environ['DATAR_VERB_AST_FALLBACK'] def test_verb_ast_fallback_precedence(): """Test that per-verb env var takes precedence over global""" from pipda import register_verb from datar.core.verb_env import get_verb_ast_fallback # Set global to piping and specific verb to normal os.environ['DATAR_VERB_AST_FALLBACK'] = 'piping' os.environ['DATAR_MODULO_AST_FALLBACK'] = 'normal' try: # Register verbs @register_verb(ast_fallback=get_verb_ast_fallback("power")) def power(x, y): return x ** y @register_verb(ast_fallback=get_verb_ast_fallback("modulo")) def modulo(x, y): return x % y # power should use global piping mode result = {} exec("result['pow'] = 2 >> power(3)", {"power": power, "result": result}) assert result['pow'] == 8 # modulo should use specific normal mode exec("result['mod'] = modulo(10, 3)", {"modulo": modulo, "result": result}) assert result['mod'] == 1 finally: del os.environ['DATAR_VERB_AST_FALLBACK'] del os.environ['DATAR_MODULO_AST_FALLBACK'] if __name__ == "__main__": test_verb_ast_fallback_piping() test_verb_ast_fallback_normal() test_verb_ast_fallback_global() test_verb_ast_fallback_precedence() print("All integration tests passed!") ================================================ FILE: tox.ini ================================================ [flake8] ignore = E203, W503, E731 per-file-ignores = # imported but unused __init__.py: F401, E402 datar/all.py: F401, E402, F403, F811 datar/apis/base.py: F401 datar/apis/dplyr.py: F401 datar/apis/forcats.py: F401 datar/apis/tidyr.py: F401 datar/forcats.py: F401, F403 datar/tidyr.py: F401, F403 datar/tibble.py: F401, F403 datar/base.py: F401, F402, F403, E402 datar/dplyr.py: F401, F402, F403, E402 datar/data/metadata.py: E501 tests/test_conflict_names.py: F401 max-line-length = 81