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) ) ```  ```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() ```  ## 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", " Sepal_Length\n", " Sepal_Width\n", " Petal_Length\n", " Petal_Width\n", " Species\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <object>\n", " \n", " \n", " 0\n", " 5.0\n", " 4.0\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 1\n", " 5.0\n", " 3.0\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 2\n", " 5.0\n", " 3.0\n", " 1.3\n", " 0.2\n", " setosa\n", " \n", " \n", " 3\n", " 5.0\n", " 3.0\n", " 1.5\n", " 0.2\n", " setosa\n", " \n", " \n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " \n", " \n", " 4\n", " 5.0\n", " 4.0\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 145\n", " 7.0\n", " 3.0\n", " 5.2\n", " 2.3\n", " virginica\n", " \n", " \n", " 146\n", " 6.0\n", " 2.0\n", " 5.0\n", " 1.9\n", " virginica\n", " \n", " \n", " 147\n", " 6.0\n", " 3.0\n", " 5.2\n", " 2.0\n", " virginica\n", " \n", " \n", " 148\n", " 6.0\n", " 3.0\n", " 5.4\n", " 2.3\n", " virginica\n", " \n", " \n", " 149\n", " 6.0\n", " 3.0\n", " 5.1\n", " 1.8\n", " virginica\n", " \n", " \n", "\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", " Sepal_Length\n", " Sepal_Width\n", " Petal_Length\n", " Petal_Width\n", " Species\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <object>\n", " \n", " \n", " 0\n", " 5.0\n", " 4.0\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 1\n", " 5.0\n", " 3.0\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 2\n", " 5.0\n", " 3.0\n", " 1.3\n", " 0.2\n", " setosa\n", " \n", " \n", " 3\n", " 5.0\n", " 3.0\n", " 1.5\n", " 0.2\n", " setosa\n", " \n", " \n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " \n", " \n", " 4\n", " 5.0\n", " 4.0\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 145\n", " 7.0\n", " 3.0\n", " 5.2\n", " 2.3\n", " virginica\n", " \n", " \n", " 146\n", " 6.0\n", " 2.0\n", " 5.0\n", " 1.9\n", " virginica\n", " \n", " \n", " 147\n", " 6.0\n", " 3.0\n", " 5.2\n", " 2.0\n", " virginica\n", " \n", " \n", " 148\n", " 6.0\n", " 3.0\n", " 5.4\n", " 2.3\n", " virginica\n", " \n", " \n", " 149\n", " 6.0\n", " 3.0\n", " 5.1\n", " 1.8\n", " virginica\n", " \n", " \n", "\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", " Sepal_Length\n", " Sepal_Width\n", " Petal_Length\n", " Petal_Width\n", " Species\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <object>\n", " \n", " \n", " 0\n", " 5.0\n", " 3.5\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 1\n", " 5.0\n", " 3.0\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 2\n", " 5.0\n", " 3.2\n", " 1.3\n", " 0.2\n", " setosa\n", " \n", " \n", " 3\n", " 5.0\n", " 3.1\n", " 1.5\n", " 0.2\n", " setosa\n", " \n", " \n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " \n", " \n", " 4\n", " 5.0\n", " 3.6\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 145\n", " 7.0\n", " 3.0\n", " 5.2\n", " 2.3\n", " virginica\n", " \n", " \n", " 146\n", " 6.0\n", " 2.5\n", " 5.0\n", " 1.9\n", " virginica\n", " \n", " \n", " 147\n", " 6.0\n", " 3.0\n", " 5.2\n", " 2.0\n", " virginica\n", " \n", " \n", " 148\n", " 6.0\n", " 3.4\n", " 5.4\n", " 2.3\n", " virginica\n", " \n", " \n", " 149\n", " 6.0\n", " 3.0\n", " 5.1\n", " 1.8\n", " virginica\n", " \n", " \n", "\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", " Sepal_Length\n", " Sepal_Width\n", " Petal_Length\n", " Petal_Width\n", " Species\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <object>\n", " \n", " \n", " 0\n", " 5.0\n", " 4.0\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 1\n", " 5.0\n", " 3.0\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 2\n", " 5.0\n", " 3.0\n", " 1.3\n", " 0.2\n", " setosa\n", " \n", " \n", " 3\n", " 5.0\n", " 3.0\n", " 1.5\n", " 0.2\n", " setosa\n", " \n", " \n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " \n", " \n", " 4\n", " 5.0\n", " 4.0\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 145\n", " 7.0\n", " 3.0\n", " 5.2\n", " 2.3\n", " virginica\n", " \n", " \n", " 146\n", " 6.0\n", " 2.0\n", " 5.0\n", " 1.9\n", " virginica\n", " \n", " \n", " 147\n", " 6.0\n", " 3.0\n", " 5.2\n", " 2.0\n", " virginica\n", " \n", " \n", " 148\n", " 6.0\n", " 3.0\n", " 5.4\n", " 2.3\n", " virginica\n", " \n", " \n", " 149\n", " 6.0\n", " 3.0\n", " 5.1\n", " 1.8\n", " virginica\n", " \n", " \n", "\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", " Sepal_Length\n", " Sepal_Width\n", " Petal_Length\n", " Petal_Width\n", " Species\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <object>\n", " \n", " \n", " 0\n", " 5.0\n", " 4.0\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 1\n", " 5.0\n", " 3.0\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 2\n", " 5.0\n", " 3.0\n", " 1.3\n", " 0.2\n", " setosa\n", " \n", " \n", " 3\n", " 5.0\n", " 3.0\n", " 1.5\n", " 0.2\n", " setosa\n", " \n", " \n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " \n", " \n", " 4\n", " 5.0\n", " 4.0\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 145\n", " 7.0\n", " 3.0\n", " 5.2\n", " 2.3\n", " virginica\n", " \n", " \n", " 146\n", " 6.0\n", " 2.0\n", " 5.0\n", " 1.9\n", " virginica\n", " \n", " \n", " 147\n", " 6.0\n", " 3.0\n", " 5.2\n", " 2.0\n", " virginica\n", " \n", " \n", " 148\n", " 6.0\n", " 3.0\n", " 5.4\n", " 2.3\n", " virginica\n", " \n", " \n", " 149\n", " 6.0\n", " 3.0\n", " 5.1\n", " 1.8\n", " virginica\n", " \n", " \n", "\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", " Sepal_Length\n", " Sepal_Width\n", " Petal_Length\n", " Petal_Width\n", " Species\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <category>\n", " \n", " \n", " 0\n", " 5.1\n", " 3.5\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 1\n", " 4.9\n", " 3.0\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 2\n", " 4.7\n", " 3.2\n", " 1.3\n", " 0.2\n", " setosa\n", " \n", " \n", " 3\n", " 4.6\n", " 3.1\n", " 1.5\n", " 0.2\n", " setosa\n", " \n", " \n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " \n", " \n", " 4\n", " 5.0\n", " 3.6\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 145\n", " 6.7\n", " 3.0\n", " 5.2\n", " 2.3\n", " virginica\n", " \n", " \n", " 146\n", " 6.3\n", " 2.5\n", " 5.0\n", " 1.9\n", " virginica\n", " \n", " \n", " 147\n", " 6.5\n", " 3.0\n", " 5.2\n", " 2.0\n", " virginica\n", " \n", " \n", " 148\n", " 6.2\n", " 3.4\n", " 5.4\n", " 2.3\n", " virginica\n", " \n", " \n", " 149\n", " 5.9\n", " 3.0\n", " 5.1\n", " 1.8\n", " virginica\n", " \n", " \n", "\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", " Sepal_Length\n", " Sepal_Width\n", " Petal_Length\n", " Petal_Width\n", " Species\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <object>\n", " \n", " \n", " 0\n", " 5.1\n", " 3.5\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 1\n", " 4.9\n", " 3.0\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 2\n", " 4.7\n", " 3.2\n", " 1.3\n", " 0.2\n", " setosa\n", " \n", " \n", " 3\n", " 4.6\n", " 3.1\n", " 1.5\n", " 0.2\n", " setosa\n", " \n", " \n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " \n", " \n", " 4\n", " 5.0\n", " 3.6\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 145\n", " 6.7\n", " 3.0\n", " 5.2\n", " 2.3\n", " virginica\n", " \n", " \n", " 146\n", " 6.3\n", " 2.5\n", " 5.0\n", " 1.9\n", " virginica\n", " \n", " \n", " 147\n", " 6.5\n", " 3.0\n", " 5.2\n", " 2.0\n", " virginica\n", " \n", " \n", " 148\n", " 6.2\n", " 3.4\n", " 5.4\n", " 2.3\n", " virginica\n", " \n", " \n", " 149\n", " 5.9\n", " 3.0\n", " 5.1\n", " 1.8\n", " virginica\n", " \n", " \n", "\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", " Species\n", " Sepal_Length\n", " Sepal_Width\n", " \n", " \n", " \n", " \n", " \n", " <object>\n", " <float64>\n", " <float64>\n", " \n", " \n", " 0\n", " setosa\n", " 5.006\n", " 3.428\n", " \n", " \n", " 1\n", " versicolor\n", " 5.936\n", " 2.770\n", " \n", " \n", " 2\n", " virginica\n", " 6.588\n", " 2.974\n", " \n", " \n", "\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", " Species\n", " Sepal_Length_mean\n", " Sepal_Length_sd\n", " Sepal_Width_mean\n", " Sepal_Width_sd\n", " \n", " \n", " \n", " \n", " \n", " <object>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " \n", " \n", " 0\n", " setosa\n", " 5.006\n", " 0.352490\n", " 3.428\n", " 0.379064\n", " \n", " \n", " 1\n", " versicolor\n", " 5.936\n", " 0.516171\n", " 2.770\n", " 0.313798\n", " \n", " \n", " 2\n", " virginica\n", " 6.588\n", " 0.635880\n", " 2.974\n", " 0.322497\n", " \n", " \n", "\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", " Species\n", " mean_Sepal_Length\n", " mean_Sepal_Width\n", " \n", " \n", " \n", " \n", " \n", " <object>\n", " <float64>\n", " <float64>\n", " \n", " \n", " 0\n", " setosa\n", " 5.006\n", " 3.428\n", " \n", " \n", " 1\n", " versicolor\n", " 5.936\n", " 2.770\n", " \n", " \n", " 2\n", " virginica\n", " 6.588\n", " 2.974\n", " \n", " \n", "\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", " Species\n", " Sepal_Length.mean\n", " Sepal_Length.sd\n", " Sepal_Width.mean\n", " Sepal_Width.sd\n", " \n", " \n", " \n", " \n", " \n", " <object>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " \n", " \n", " 0\n", " setosa\n", " 5.006\n", " 0.352490\n", " 3.428\n", " 0.379064\n", " \n", " \n", " 1\n", " versicolor\n", " 5.936\n", " 0.516171\n", " 2.770\n", " 0.313798\n", " \n", " \n", " 2\n", " virginica\n", " 6.588\n", " 0.635880\n", " 2.974\n", " 0.322497\n", " \n", " \n", "\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", " Species\n", " Sepal_Length.fn0\n", " Sepal_Length.fn1\n", " Sepal_Width.fn0\n", " Sepal_Width.fn1\n", " \n", " \n", " \n", " \n", " \n", " <object>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " \n", " \n", " 0\n", " setosa\n", " 5.006\n", " 0.352490\n", " 3.428\n", " 0.379064\n", " \n", " \n", " 1\n", " versicolor\n", " 5.936\n", " 0.516171\n", " 2.770\n", " 0.313798\n", " \n", " \n", " 2\n", " virginica\n", " 6.588\n", " 0.635880\n", " 2.974\n", " 0.322497\n", " \n", " \n", "\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", " Species\n", " Sepal_Length.fn0\n", " Sepal_Length.fn1\n", " Sepal_Width.fn0\n", " Sepal_Width.fn1\n", " \n", " \n", " \n", " \n", " \n", " <object>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " \n", " \n", " 0\n", " setosa\n", " 5.006\n", " 0.352490\n", " 3.428\n", " 0.379064\n", " \n", " \n", " 1\n", " versicolor\n", " 5.936\n", " 0.516171\n", " 2.770\n", " 0.313798\n", " \n", " \n", " 2\n", " virginica\n", " 6.588\n", " 0.635880\n", " 2.974\n", " 0.322497\n", " \n", " \n", "\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", " Species\n", " Sepal_Length.fn1\n", " Sepal_Length.fn2\n", " Sepal_Width.fn1\n", " Sepal_Width.fn2\n", " \n", " \n", " \n", " \n", " \n", " <object>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " \n", " \n", " 0\n", " setosa\n", " 5.006\n", " 0.352490\n", " 3.428\n", " 0.379064\n", " \n", " \n", " 1\n", " versicolor\n", " 5.936\n", " 0.516171\n", " 2.770\n", " 0.313798\n", " \n", " \n", " 2\n", " virginica\n", " 6.588\n", " 0.635880\n", " 2.974\n", " 0.322497\n", " \n", " \n", "\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", " Sepal_Length\n", " Sepal_Width\n", " Petal_Length\n", " Petal_Width\n", " Species\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <object>\n", " \n", " \n", " 15\n", " 5.7\n", " 4.4\n", " 1.5\n", " 0.4\n", " setosa\n", " \n", " \n", " 32\n", " 5.2\n", " 4.1\n", " 1.5\n", " 0.1\n", " setosa\n", " \n", " \n", " 33\n", " 5.5\n", " 4.2\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", "\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", " Sepal_Length\n", " Sepal_Width\n", " Petal_Length\n", " Petal_Width\n", " Species\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <object>\n", " \n", " \n", " 100\n", " 6.3\n", " 3.3\n", " 6.0\n", " 2.5\n", " virginica\n", " \n", " \n", " 102\n", " 7.1\n", " 3.0\n", " 5.9\n", " 2.1\n", " virginica\n", " \n", " \n", " 104\n", " 6.5\n", " 3.0\n", " 5.8\n", " 2.2\n", " virginica\n", " \n", " \n", " 105\n", " 7.6\n", " 3.0\n", " 6.6\n", " 2.1\n", " virginica\n", " \n", " \n", " 109\n", " 7.2\n", " 3.6\n", " 6.1\n", " 2.5\n", " virginica\n", " \n", " \n", " 112\n", " 6.8\n", " 3.0\n", " 5.5\n", " 2.1\n", " virginica\n", " \n", " \n", " 114\n", " 5.8\n", " 2.8\n", " 5.1\n", " 2.4\n", " virginica\n", " \n", " \n", " 115\n", " 6.4\n", " 3.2\n", " 5.3\n", " 2.3\n", " virginica\n", " \n", " \n", " 117\n", " 7.7\n", " 3.8\n", " 6.7\n", " 2.2\n", " virginica\n", " \n", " \n", " 118\n", " 7.7\n", " 2.6\n", " 6.9\n", " 2.3\n", " virginica\n", " \n", " \n", " 120\n", " 6.9\n", " 3.2\n", " 5.7\n", " 2.3\n", " virginica\n", " \n", " \n", " 124\n", " 6.7\n", " 3.3\n", " 5.7\n", " 2.1\n", " virginica\n", " \n", " \n", " 128\n", " 6.4\n", " 2.8\n", " 5.6\n", " 2.1\n", " virginica\n", " \n", " \n", " 132\n", " 6.4\n", " 2.8\n", " 5.6\n", " 2.2\n", " virginica\n", " \n", " \n", " 135\n", " 7.7\n", " 3.0\n", " 6.1\n", " 2.3\n", " virginica\n", " \n", " \n", " 136\n", " 6.3\n", " 3.4\n", " 5.6\n", " 2.4\n", " virginica\n", " \n", " \n", " 139\n", " 6.9\n", " 3.1\n", " 5.4\n", " 2.1\n", " virginica\n", " \n", " \n", " 140\n", " 6.7\n", " 3.1\n", " 5.6\n", " 2.4\n", " virginica\n", " \n", " \n", " 141\n", " 6.9\n", " 3.1\n", " 5.1\n", " 2.3\n", " virginica\n", " \n", " \n", " 143\n", " 6.8\n", " 3.2\n", " 5.9\n", " 2.3\n", " virginica\n", " \n", " \n", " 144\n", " 6.7\n", " 3.3\n", " 5.7\n", " 2.5\n", " virginica\n", " \n", " \n", " 145\n", " 6.7\n", " 3.0\n", " 5.2\n", " 2.3\n", " virginica\n", " \n", " \n", " 148\n", " 6.2\n", " 3.4\n", " 5.4\n", " 2.3\n", " virginica\n", " \n", " \n", "\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", " id\n", " w\n", " x\n", " y\n", " z\n", " sum\n", " sd\n", " \n", " \n", " \n", " \n", " \n", " <int64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " \n", " \n", " 0\n", " 1\n", " 0.909293\n", " 0.880456\n", " 0.174213\n", " 0.382593\n", " 1.963962\n", " 0.416324\n", " \n", " \n", " 1\n", " 2\n", " 0.102912\n", " 0.952811\n", " 0.632536\n", " 0.845920\n", " 1.688258\n", " 0.429225\n", " \n", " \n", " 2\n", " 3\n", " 0.425592\n", " 0.320275\n", " 0.803515\n", " 0.831533\n", " 1.549382\n", " 0.254112\n", " \n", " \n", " 3\n", " 4\n", " 0.218472\n", " 0.849190\n", " 0.637853\n", " 0.887980\n", " 1.705514\n", " 0.321026\n", " \n", " \n", "\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", " x\n", " y\n", " z\n", " w\n", " \n", " \n", " \n", " \n", " \n", " <int64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " \n", " \n", " 0\n", " 1\n", " 3\n", " -1\n", " 0\n", " \n", " \n", " 1\n", " 2\n", " 2\n", " 0\n", " 0\n", " \n", " \n", " 2\n", " 3\n", " 1\n", " 1\n", " 0\n", " \n", " \n", "\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", " x\n", " z\n", " y\n", " \n", " \n", " \n", " \n", " \n", " <int64>\n", " <int64>\n", " <int64>\n", " \n", " \n", " 0\n", " 1\n", " -1\n", " 3\n", " \n", " \n", " 1\n", " 2\n", " 0\n", " 2\n", " \n", " \n", " 2\n", " 3\n", " 1\n", " 1\n", " \n", " \n", "\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", " x\n", " y\n", " \n", " \n", " \n", " \n", " \n", " <int64>\n", " <int64>\n", " \n", " \n", " 0\n", " 1\n", " 3\n", " \n", " \n", " 1\n", " 2\n", " 2\n", " \n", " \n", " 2\n", " 3\n", " 1\n", " \n", " \n", " 3\n", " 4\n", " 0\n", " \n", " \n", "\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", " x\n", " y\n", " \n", " \n", " \n", " \n", " \n", " <int64>\n", " <int64>\n", " \n", " \n", " 0\n", " 1\n", " 3\n", " \n", " \n", " 1\n", " 2\n", " 2\n", " \n", " \n", " 2\n", " 4\n", " 0\n", " \n", " \n", " 3\n", " 3\n", " 1\n", " \n", " \n", "\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", " x\n", " y\n", " \n", " \n", " \n", " \n", " \n", " <int64>\n", " <int64>\n", " \n", " \n", " 0\n", " 1\n", " 3\n", " \n", " \n", " 1\n", " 2\n", " 2\n", " \n", " \n", " 2\n", " 3\n", " 1\n", " \n", " \n", " 3\n", " 4\n", " 0\n", " \n", " \n", " 4\n", " 5\n", " -1\n", " \n", " \n", "\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", " x\n", " y\n", " \n", " \n", " \n", " \n", " \n", " <int64>\n", " <int64>\n", " \n", " \n", " 0\n", " 1\n", " 3\n", " \n", " \n", " 1\n", " 2\n", " 2\n", " \n", " \n", " 2\n", " 3\n", " 1\n", " \n", " \n", " 3\n", " 4\n", " 0\n", " \n", " \n", "\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", " x\n", " y\n", " \n", " \n", " \n", " \n", " \n", " <int64>\n", " <float64>\n", " \n", " \n", " 0\n", " 1\n", " 3.0\n", " \n", " \n", " 1\n", " 2\n", " 2.0\n", " \n", " \n", " 2\n", " 3\n", " 1.0\n", " \n", " \n", " 3\n", " 4\n", " NaN\n", " \n", " \n", "\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", " mpg\n", " cyl\n", " disp\n", " hp\n", " drat\n", " wt\n", " qsec\n", " vs\n", " am\n", " gear\n", " carb\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <int64>\n", " <float64>\n", " <int64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " \n", " \n", " Toyota Corolla\n", " 33.9\n", " 4\n", " 71.1\n", " 65\n", " 4.22\n", " 1.835\n", " 19.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Honda Civic\n", " 30.4\n", " 4\n", " 75.7\n", " 52\n", " 4.93\n", " 1.615\n", " 18.52\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " Fiat 128\n", " 32.4\n", " 4\n", " 78.7\n", " 66\n", " 4.08\n", " 2.200\n", " 19.47\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Fiat X1-9\n", " 27.3\n", " 4\n", " 79.0\n", " 66\n", " 4.08\n", " 1.935\n", " 18.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Lotus Europa\n", " 30.4\n", " 4\n", " 95.1\n", " 113\n", " 3.77\n", " 1.513\n", " 16.90\n", " 1\n", " 1\n", " 5\n", " 2\n", " \n", " \n", " Datsun 710\n", " 22.8\n", " 4\n", " 108.0\n", " 93\n", " 3.85\n", " 2.320\n", " 18.61\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Toyota Corona\n", " 21.5\n", " 4\n", " 120.1\n", " 97\n", " 3.70\n", " 2.465\n", " 20.01\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " Porsche 914-2\n", " 26.0\n", " 4\n", " 120.3\n", " 91\n", " 4.43\n", " 2.140\n", " 16.70\n", " 0\n", " 1\n", " 5\n", " 2\n", " \n", " \n", " Volvo 142E\n", " 21.4\n", " 4\n", " 121.0\n", " 109\n", " 4.11\n", " 2.780\n", " 18.60\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " Merc 230\n", " 22.8\n", " 4\n", " 140.8\n", " 95\n", " 3.92\n", " 3.150\n", " 22.90\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " Merc 240D\n", " 24.4\n", " 4\n", " 146.7\n", " 62\n", " 3.69\n", " 3.190\n", " 20.00\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " Ferrari Dino\n", " 19.7\n", " 6\n", " 145.0\n", " 175\n", " 3.62\n", " 2.770\n", " 15.50\n", " 0\n", " 1\n", " 5\n", " 6\n", " \n", " \n", " Mazda RX4\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.620\n", " 16.46\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " Mazda RX4 Wag\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.875\n", " 17.02\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " Merc 280\n", " 19.2\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.30\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " Merc 280C\n", " 17.8\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.90\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " Valiant\n", " 18.1\n", " 6\n", " 225.0\n", " 105\n", " 2.76\n", " 3.460\n", " 20.22\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " Hornet 4 Drive\n", " 21.4\n", " 6\n", " 258.0\n", " 110\n", " 3.08\n", " 3.215\n", " 19.44\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " Merc 450SE\n", " 16.4\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 4.070\n", " 17.40\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " Merc 450SL\n", " 17.3\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.730\n", " 17.60\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " Merc 450SLC\n", " 15.2\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.780\n", " 18.00\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " Maserati Bora\n", " 15.0\n", " 8\n", " 301.0\n", " 335\n", " 3.54\n", " 3.570\n", " 14.60\n", " 0\n", " 1\n", " 5\n", " 8\n", " \n", " \n", " AMC Javelin\n", " 15.2\n", " 8\n", " 304.0\n", " 150\n", " 3.15\n", " 3.435\n", " 17.30\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Dodge Challenger\n", " 15.5\n", " 8\n", " 318.0\n", " 150\n", " 2.76\n", " 3.520\n", " 16.87\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Camaro Z28\n", " 13.3\n", " 8\n", " 350.0\n", " 245\n", " 3.73\n", " 3.840\n", " 15.41\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Ford Pantera L\n", " 15.8\n", " 8\n", " 351.0\n", " 264\n", " 4.22\n", " 3.170\n", " 14.50\n", " 0\n", " 1\n", " 5\n", " 4\n", " \n", " \n", " Hornet Sportabout\n", " 18.7\n", " 8\n", " 360.0\n", " 175\n", " 3.15\n", " 3.440\n", " 17.02\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Duster 360\n", " 14.3\n", " 8\n", " 360.0\n", " 245\n", " 3.21\n", " 3.570\n", " 15.84\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Pontiac Firebird\n", " 19.2\n", " 8\n", " 400.0\n", " 175\n", " 3.08\n", " 3.845\n", " 17.05\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Chrysler Imperial\n", " 14.7\n", " 8\n", " 440.0\n", " 230\n", " 3.23\n", " 5.345\n", " 17.42\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Lincoln Continental\n", " 10.4\n", " 8\n", " 460.0\n", " 215\n", " 3.00\n", " 5.424\n", " 17.82\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Cadillac Fleetwood\n", " 10.4\n", " 8\n", " 472.0\n", " 205\n", " 2.93\n", " 5.250\n", " 17.98\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", "\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", " mpg\n", " cyl\n", " disp\n", " hp\n", " drat\n", " wt\n", " qsec\n", " vs\n", " am\n", " gear\n", " carb\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <int64>\n", " <float64>\n", " <int64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " \n", " \n", " Cadillac Fleetwood\n", " 10.4\n", " 8\n", " 472.0\n", " 205\n", " 2.93\n", " 5.250\n", " 17.98\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Lincoln Continental\n", " 10.4\n", " 8\n", " 460.0\n", " 215\n", " 3.00\n", " 5.424\n", " 17.82\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Chrysler Imperial\n", " 14.7\n", " 8\n", " 440.0\n", " 230\n", " 3.23\n", " 5.345\n", " 17.42\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Pontiac Firebird\n", " 19.2\n", " 8\n", " 400.0\n", " 175\n", " 3.08\n", " 3.845\n", " 17.05\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Hornet Sportabout\n", " 18.7\n", " 8\n", " 360.0\n", " 175\n", " 3.15\n", " 3.440\n", " 17.02\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Duster 360\n", " 14.3\n", " 8\n", " 360.0\n", " 245\n", " 3.21\n", " 3.570\n", " 15.84\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Ford Pantera L\n", " 15.8\n", " 8\n", " 351.0\n", " 264\n", " 4.22\n", " 3.170\n", " 14.50\n", " 0\n", " 1\n", " 5\n", " 4\n", " \n", " \n", " Camaro Z28\n", " 13.3\n", " 8\n", " 350.0\n", " 245\n", " 3.73\n", " 3.840\n", " 15.41\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Dodge Challenger\n", " 15.5\n", " 8\n", " 318.0\n", " 150\n", " 2.76\n", " 3.520\n", " 16.87\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " AMC Javelin\n", " 15.2\n", " 8\n", " 304.0\n", " 150\n", " 3.15\n", " 3.435\n", " 17.30\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Maserati Bora\n", " 15.0\n", " 8\n", " 301.0\n", " 335\n", " 3.54\n", " 3.570\n", " 14.60\n", " 0\n", " 1\n", " 5\n", " 8\n", " \n", " \n", " Merc 450SE\n", " 16.4\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 4.070\n", " 17.40\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " Merc 450SL\n", " 17.3\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.730\n", " 17.60\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " Merc 450SLC\n", " 15.2\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.780\n", " 18.00\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " Hornet 4 Drive\n", " 21.4\n", " 6\n", " 258.0\n", " 110\n", " 3.08\n", " 3.215\n", " 19.44\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " Valiant\n", " 18.1\n", " 6\n", " 225.0\n", " 105\n", " 2.76\n", " 3.460\n", " 20.22\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " Merc 280\n", " 19.2\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.30\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " Merc 280C\n", " 17.8\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.90\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " Mazda RX4\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.620\n", " 16.46\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " Mazda RX4 Wag\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.875\n", " 17.02\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " Merc 240D\n", " 24.4\n", " 4\n", " 146.7\n", " 62\n", " 3.69\n", " 3.190\n", " 20.00\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " Ferrari Dino\n", " 19.7\n", " 6\n", " 145.0\n", " 175\n", " 3.62\n", " 2.770\n", " 15.50\n", " 0\n", " 1\n", " 5\n", " 6\n", " \n", " \n", " Merc 230\n", " 22.8\n", " 4\n", " 140.8\n", " 95\n", " 3.92\n", " 3.150\n", " 22.90\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " Volvo 142E\n", " 21.4\n", " 4\n", " 121.0\n", " 109\n", " 4.11\n", " 2.780\n", " 18.60\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " Porsche 914-2\n", " 26.0\n", " 4\n", " 120.3\n", " 91\n", " 4.43\n", " 2.140\n", " 16.70\n", " 0\n", " 1\n", " 5\n", " 2\n", " \n", " \n", " Toyota Corona\n", " 21.5\n", " 4\n", " 120.1\n", " 97\n", " 3.70\n", " 2.465\n", " 20.01\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " Datsun 710\n", " 22.8\n", " 4\n", " 108.0\n", " 93\n", " 3.85\n", " 2.320\n", " 18.61\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Lotus Europa\n", " 30.4\n", " 4\n", " 95.1\n", " 113\n", " 3.77\n", " 1.513\n", " 16.90\n", " 1\n", " 1\n", " 5\n", " 2\n", " \n", " \n", " Fiat X1-9\n", " 27.3\n", " 4\n", " 79.0\n", " 66\n", " 4.08\n", " 1.935\n", " 18.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Fiat 128\n", " 32.4\n", " 4\n", " 78.7\n", " 66\n", " 4.08\n", " 2.200\n", " 19.47\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Honda Civic\n", " 30.4\n", " 4\n", " 75.7\n", " 52\n", " 4.93\n", " 1.615\n", " 18.52\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " Toyota Corolla\n", " 33.9\n", " 4\n", " 71.1\n", " 65\n", " 4.22\n", " 1.835\n", " 19.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", "\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", " mpg\n", " cyl\n", " disp\n", " hp\n", " drat\n", " wt\n", " qsec\n", " vs\n", " am\n", " gear\n", " carb\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <int64>\n", " <float64>\n", " <int64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " \n", " \n", " 0\n", " 10.4\n", " 8\n", " 460.0\n", " 215\n", " 3.00\n", " 5.424\n", " 17.82\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " 1\n", " 14.7\n", " 8\n", " 440.0\n", " 230\n", " 3.23\n", " 5.345\n", " 17.42\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " 2\n", " 10.4\n", " 8\n", " 472.0\n", " 205\n", " 2.93\n", " 5.250\n", " 17.98\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " 3\n", " 16.4\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 4.070\n", " 17.40\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " 4\n", " 19.2\n", " 8\n", " 400.0\n", " 175\n", " 3.08\n", " 3.845\n", " 17.05\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " 5\n", " 13.3\n", " 8\n", " 350.0\n", " 245\n", " 3.73\n", " 3.840\n", " 15.41\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " 6\n", " 15.2\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.780\n", " 18.00\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " 7\n", " 17.3\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.730\n", " 17.60\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " 8\n", " 15.0\n", " 8\n", " 301.0\n", " 335\n", " 3.54\n", " 3.570\n", " 14.60\n", " 0\n", " 1\n", " 5\n", " 8\n", " \n", " \n", " 9\n", " 14.3\n", " 8\n", " 360.0\n", " 245\n", " 3.21\n", " 3.570\n", " 15.84\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " 10\n", " 15.5\n", " 8\n", " 318.0\n", " 150\n", " 2.76\n", " 3.520\n", " 16.87\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " 11\n", " 18.1\n", " 6\n", " 225.0\n", " 105\n", " 2.76\n", " 3.460\n", " 20.22\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " 12\n", " 19.2\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.30\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " 13\n", " 18.7\n", " 8\n", " 360.0\n", " 175\n", " 3.15\n", " 3.440\n", " 17.02\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " 14\n", " 17.8\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.90\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " 15\n", " 15.2\n", " 8\n", " 304.0\n", " 150\n", " 3.15\n", " 3.435\n", " 17.30\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " 16\n", " 21.4\n", " 6\n", " 258.0\n", " 110\n", " 3.08\n", " 3.215\n", " 19.44\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " 17\n", " 24.4\n", " 4\n", " 146.7\n", " 62\n", " 3.69\n", " 3.190\n", " 20.00\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " 18\n", " 15.8\n", " 8\n", " 351.0\n", " 264\n", " 4.22\n", " 3.170\n", " 14.50\n", " 0\n", " 1\n", " 5\n", " 4\n", " \n", " \n", " 19\n", " 22.8\n", " 4\n", " 140.8\n", " 95\n", " 3.92\n", " 3.150\n", " 22.90\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " 20\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.875\n", " 17.02\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " 21\n", " 21.4\n", " 4\n", " 121.0\n", " 109\n", " 4.11\n", " 2.780\n", " 18.60\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " 22\n", " 19.7\n", " 6\n", " 145.0\n", " 175\n", " 3.62\n", " 2.770\n", " 15.50\n", " 0\n", " 1\n", " 5\n", " 6\n", " \n", " \n", " 23\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.620\n", " 16.46\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " 24\n", " 21.5\n", " 4\n", " 120.1\n", " 97\n", " 3.70\n", " 2.465\n", " 20.01\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " 25\n", " 22.8\n", " 4\n", " 108.0\n", " 93\n", " 3.85\n", " 2.320\n", " 18.61\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " 26\n", " 32.4\n", " 4\n", " 78.7\n", " 66\n", " 4.08\n", " 2.200\n", " 19.47\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " 27\n", " 26.0\n", " 4\n", " 120.3\n", " 91\n", " 4.43\n", " 2.140\n", " 16.70\n", " 0\n", " 1\n", " 5\n", " 2\n", " \n", " \n", " 28\n", " 27.3\n", " 4\n", " 79.0\n", " 66\n", " 4.08\n", " 1.935\n", " 18.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " 29\n", " 33.9\n", " 4\n", " 71.1\n", " 65\n", " 4.22\n", " 1.835\n", " 19.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " 30\n", " 30.4\n", " 4\n", " 75.7\n", " 52\n", " 4.93\n", " 1.615\n", " 18.52\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " 31\n", " 30.4\n", " 4\n", " 95.1\n", " 113\n", " 3.77\n", " 1.513\n", " 16.90\n", " 1\n", " 1\n", " 5\n", " 2\n", " \n", " \n", "\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", " mpg\n", " cyl\n", " disp\n", " hp\n", " drat\n", " wt\n", " qsec\n", " vs\n", " am\n", " gear\n", " carb\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <int64>\n", " <float64>\n", " <int64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " \n", " \n", " 0\n", " 24.4\n", " 4\n", " 146.7\n", " 62\n", " 3.69\n", " 3.190\n", " 20.00\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " 1\n", " 22.8\n", " 4\n", " 140.8\n", " 95\n", " 3.92\n", " 3.150\n", " 22.90\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " 2\n", " 21.4\n", " 4\n", " 121.0\n", " 109\n", " 4.11\n", " 2.780\n", " 18.60\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " 3\n", " 21.5\n", " 4\n", " 120.1\n", " 97\n", " 3.70\n", " 2.465\n", " 20.01\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " 4\n", " 22.8\n", " 4\n", " 108.0\n", " 93\n", " 3.85\n", " 2.320\n", " 18.61\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " 5\n", " 32.4\n", " 4\n", " 78.7\n", " 66\n", " 4.08\n", " 2.200\n", " 19.47\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " 6\n", " 26.0\n", " 4\n", " 120.3\n", " 91\n", " 4.43\n", " 2.140\n", " 16.70\n", " 0\n", " 1\n", " 5\n", " 2\n", " \n", " \n", " 7\n", " 27.3\n", " 4\n", " 79.0\n", " 66\n", " 4.08\n", " 1.935\n", " 18.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " 8\n", " 33.9\n", " 4\n", " 71.1\n", " 65\n", " 4.22\n", " 1.835\n", " 19.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " 9\n", " 30.4\n", " 4\n", " 75.7\n", " 52\n", " 4.93\n", " 1.615\n", " 18.52\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " 10\n", " 30.4\n", " 4\n", " 95.1\n", " 113\n", " 3.77\n", " 1.513\n", " 16.90\n", " 1\n", " 1\n", " 5\n", " 2\n", " \n", " \n", " 11\n", " 18.1\n", " 6\n", " 225.0\n", " 105\n", " 2.76\n", " 3.460\n", " 20.22\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " 12\n", " 19.2\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.30\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " 13\n", " 17.8\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.90\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " 14\n", " 21.4\n", " 6\n", " 258.0\n", " 110\n", " 3.08\n", " 3.215\n", " 19.44\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " 15\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.875\n", " 17.02\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " 16\n", " 19.7\n", " 6\n", " 145.0\n", " 175\n", " 3.62\n", " 2.770\n", " 15.50\n", " 0\n", " 1\n", " 5\n", " 6\n", " \n", " \n", " 17\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.620\n", " 16.46\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " 18\n", " 10.4\n", " 8\n", " 460.0\n", " 215\n", " 3.00\n", " 5.424\n", " 17.82\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " 19\n", " 14.7\n", " 8\n", " 440.0\n", " 230\n", " 3.23\n", " 5.345\n", " 17.42\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " 20\n", " 10.4\n", " 8\n", " 472.0\n", " 205\n", " 2.93\n", " 5.250\n", " 17.98\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " 21\n", " 16.4\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 4.070\n", " 17.40\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " 22\n", " 19.2\n", " 8\n", " 400.0\n", " 175\n", " 3.08\n", " 3.845\n", " 17.05\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " 23\n", " 13.3\n", " 8\n", " 350.0\n", " 245\n", " 3.73\n", " 3.840\n", " 15.41\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " 24\n", " 15.2\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.780\n", " 18.00\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " 25\n", " 17.3\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.730\n", " 17.60\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " 26\n", " 14.3\n", " 8\n", " 360.0\n", " 245\n", " 3.21\n", " 3.570\n", " 15.84\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " 27\n", " 15.0\n", " 8\n", " 301.0\n", " 335\n", " 3.54\n", " 3.570\n", " 14.60\n", " 0\n", " 1\n", " 5\n", " 8\n", " \n", " \n", " 28\n", " 15.5\n", " 8\n", " 318.0\n", " 150\n", " 2.76\n", " 3.520\n", " 16.87\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " 29\n", " 18.7\n", " 8\n", " 360.0\n", " 175\n", " 3.15\n", " 3.440\n", " 17.02\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " 30\n", " 15.2\n", " 8\n", " 304.0\n", " 150\n", " 3.15\n", " 3.435\n", " 17.30\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " 31\n", " 15.8\n", " 8\n", " 351.0\n", " 264\n", " 4.22\n", " 3.170\n", " 14.50\n", " 0\n", " 1\n", " 5\n", " 4\n", " \n", " \n", "\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", " mpg\n", " cyl\n", " disp\n", " hp\n", " drat\n", " wt\n", " qsec\n", " vs\n", " am\n", " gear\n", " carb\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <int64>\n", " <float64>\n", " <int64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " \n", " \n", " Lincoln Continental\n", " 10.4\n", " 8\n", " 460.0\n", " 215\n", " 3.00\n", " 5.424\n", " 17.82\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Cadillac Fleetwood\n", " 10.4\n", " 8\n", " 472.0\n", " 205\n", " 2.93\n", " 5.250\n", " 17.98\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Camaro Z28\n", " 13.3\n", " 8\n", " 350.0\n", " 245\n", " 3.73\n", " 3.840\n", " 15.41\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Duster 360\n", " 14.3\n", " 8\n", " 360.0\n", " 245\n", " 3.21\n", " 3.570\n", " 15.84\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Chrysler Imperial\n", " 14.7\n", " 8\n", " 440.0\n", " 230\n", " 3.23\n", " 5.345\n", " 17.42\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Maserati Bora\n", " 15.0\n", " 8\n", " 301.0\n", " 335\n", " 3.54\n", " 3.570\n", " 14.60\n", " 0\n", " 1\n", " 5\n", " 8\n", " \n", " \n", " Merc 450SLC\n", " 15.2\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.780\n", " 18.00\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " AMC Javelin\n", " 15.2\n", " 8\n", " 304.0\n", " 150\n", " 3.15\n", " 3.435\n", " 17.30\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Dodge Challenger\n", " 15.5\n", " 8\n", " 318.0\n", " 150\n", " 2.76\n", " 3.520\n", " 16.87\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Ford Pantera L\n", " 15.8\n", " 8\n", " 351.0\n", " 264\n", " 4.22\n", " 3.170\n", " 14.50\n", " 0\n", " 1\n", " 5\n", " 4\n", " \n", " \n", " Merc 450SE\n", " 16.4\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 4.070\n", " 17.40\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " Merc 450SL\n", " 17.3\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.730\n", " 17.60\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " Merc 280C\n", " 17.8\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.90\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " Valiant\n", " 18.1\n", " 6\n", " 225.0\n", " 105\n", " 2.76\n", " 3.460\n", " 20.22\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " Hornet Sportabout\n", " 18.7\n", " 8\n", " 360.0\n", " 175\n", " 3.15\n", " 3.440\n", " 17.02\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Merc 280\n", " 19.2\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.30\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " Pontiac Firebird\n", " 19.2\n", " 8\n", " 400.0\n", " 175\n", " 3.08\n", " 3.845\n", " 17.05\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Ferrari Dino\n", " 19.7\n", " 6\n", " 145.0\n", " 175\n", " 3.62\n", " 2.770\n", " 15.50\n", " 0\n", " 1\n", " 5\n", " 6\n", " \n", " \n", " Mazda RX4\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.620\n", " 16.46\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " Mazda RX4 Wag\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.875\n", " 17.02\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " Hornet 4 Drive\n", " 21.4\n", " 6\n", " 258.0\n", " 110\n", " 3.08\n", " 3.215\n", " 19.44\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " Volvo 142E\n", " 21.4\n", " 4\n", " 121.0\n", " 109\n", " 4.11\n", " 2.780\n", " 18.60\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " Toyota Corona\n", " 21.5\n", " 4\n", " 120.1\n", " 97\n", " 3.70\n", " 2.465\n", " 20.01\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " Merc 230\n", " 22.8\n", " 4\n", " 140.8\n", " 95\n", " 3.92\n", " 3.150\n", " 22.90\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " Datsun 710\n", " 22.8\n", " 4\n", " 108.0\n", " 93\n", " 3.85\n", " 2.320\n", " 18.61\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Merc 240D\n", " 24.4\n", " 4\n", " 146.7\n", " 62\n", " 3.69\n", " 3.190\n", " 20.00\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " Porsche 914-2\n", " 26.0\n", " 4\n", " 120.3\n", " 91\n", " 4.43\n", " 2.140\n", " 16.70\n", " 0\n", " 1\n", " 5\n", " 2\n", " \n", " \n", " Fiat X1-9\n", " 27.3\n", " 4\n", " 79.0\n", " 66\n", " 4.08\n", " 1.935\n", " 18.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Lotus Europa\n", " 30.4\n", " 4\n", " 95.1\n", " 113\n", " 3.77\n", " 1.513\n", " 16.90\n", " 1\n", " 1\n", " 5\n", " 2\n", " \n", " \n", " Honda Civic\n", " 30.4\n", " 4\n", " 75.7\n", " 52\n", " 4.93\n", " 1.615\n", " 18.52\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " Fiat 128\n", " 32.4\n", " 4\n", " 78.7\n", " 66\n", " 4.08\n", " 2.200\n", " 19.47\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Toyota Corolla\n", " 33.9\n", " 4\n", " 71.1\n", " 65\n", " 4.22\n", " 1.835\n", " 19.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", "\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", " Sepal_Length\n", " Sepal_Width\n", " Petal_Length\n", " Petal_Width\n", " Species\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <object>\n", " \n", " \n", " 13\n", " 4.3\n", " 3.0\n", " 1.1\n", " 0.1\n", " setosa\n", " \n", " \n", " 8\n", " 4.4\n", " 2.9\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 38\n", " 4.4\n", " 3.0\n", " 1.3\n", " 0.2\n", " setosa\n", " \n", " \n", " 42\n", " 4.4\n", " 3.2\n", " 1.3\n", " 0.2\n", " setosa\n", " \n", " \n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " \n", " \n", " 41\n", " 4.5\n", " 2.3\n", " 1.3\n", " 0.3\n", " setosa\n", " \n", " \n", " 118\n", " 7.7\n", " 2.6\n", " 6.9\n", " 2.3\n", " virginica\n", " \n", " \n", " 122\n", " 7.7\n", " 2.8\n", " 6.7\n", " 2.0\n", " virginica\n", " \n", " \n", " 135\n", " 7.7\n", " 3.0\n", " 6.1\n", " 2.3\n", " virginica\n", " \n", " \n", " 117\n", " 7.7\n", " 3.8\n", " 6.7\n", " 2.2\n", " virginica\n", " \n", " \n", " 131\n", " 7.9\n", " 3.8\n", " 6.4\n", " 2.0\n", " virginica\n", " \n", " \n", "\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", " Sepal_Length\n", " Sepal_Width\n", " Petal_Length\n", " Petal_Width\n", " Species\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <object>\n", " \n", " \n", " 131\n", " 7.9\n", " 3.8\n", " 6.4\n", " 2.0\n", " virginica\n", " \n", " \n", " 117\n", " 7.7\n", " 3.8\n", " 6.7\n", " 2.2\n", " virginica\n", " \n", " \n", " 135\n", " 7.7\n", " 3.0\n", " 6.1\n", " 2.3\n", " virginica\n", " \n", " \n", " 122\n", " 7.7\n", " 2.8\n", " 6.7\n", " 2.0\n", " virginica\n", " \n", " \n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " \n", " \n", " 118\n", " 7.7\n", " 2.6\n", " 6.9\n", " 2.3\n", " virginica\n", " \n", " \n", " 41\n", " 4.5\n", " 2.3\n", " 1.3\n", " 0.3\n", " setosa\n", " \n", " \n", " 42\n", " 4.4\n", " 3.2\n", " 1.3\n", " 0.2\n", " setosa\n", " \n", " \n", " 38\n", " 4.4\n", " 3.0\n", " 1.3\n", " 0.2\n", " setosa\n", " \n", " \n", " 8\n", " 4.4\n", " 2.9\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 13\n", " 4.3\n", " 3.0\n", " 1.1\n", " 0.1\n", " setosa\n", " \n", " \n", "\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": [ "
150 rows × 5 columns
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", " x\n", " y\n", " z\n", " w\n", " \n", " \n", " \n", " \n", " \n", " <int64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " \n", " \n", " 0\n", " 1\n", " 3\n", " -1\n", " 0\n", " \n", " \n", " 1\n", " 2\n", " 2\n", " 0\n", " 0\n", " \n", " \n", " 2\n", " 3\n", " 1\n", " 1\n", " 0\n", " \n", " \n", "\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", " x\n", " z\n", " y\n", " \n", " \n", " \n", " \n", " \n", " <int64>\n", " <int64>\n", " <int64>\n", " \n", " \n", " 0\n", " 1\n", " -1\n", " 3\n", " \n", " \n", " 1\n", " 2\n", " 0\n", " 2\n", " \n", " \n", " 2\n", " 3\n", " 1\n", " 1\n", " \n", " \n", "\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", " x\n", " y\n", " \n", " \n", " \n", " \n", " \n", " <int64>\n", " <int64>\n", " \n", " \n", " 0\n", " 1\n", " 3\n", " \n", " \n", " 1\n", " 2\n", " 2\n", " \n", " \n", " 2\n", " 3\n", " 1\n", " \n", " \n", " 3\n", " 4\n", " 0\n", " \n", " \n", "\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", " x\n", " y\n", " \n", " \n", " \n", " \n", " \n", " <int64>\n", " <int64>\n", " \n", " \n", " 0\n", " 1\n", " 3\n", " \n", " \n", " 1\n", " 2\n", " 2\n", " \n", " \n", " 2\n", " 4\n", " 0\n", " \n", " \n", " 3\n", " 3\n", " 1\n", " \n", " \n", "\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", " x\n", " y\n", " \n", " \n", " \n", " \n", " \n", " <int64>\n", " <int64>\n", " \n", " \n", " 0\n", " 1\n", " 3\n", " \n", " \n", " 1\n", " 2\n", " 2\n", " \n", " \n", " 2\n", " 3\n", " 1\n", " \n", " \n", " 3\n", " 4\n", " 0\n", " \n", " \n", " 4\n", " 5\n", " -1\n", " \n", " \n", "\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", " x\n", " y\n", " \n", " \n", " \n", " \n", " \n", " <int64>\n", " <int64>\n", " \n", " \n", " 0\n", " 1\n", " 3\n", " \n", " \n", " 1\n", " 2\n", " 2\n", " \n", " \n", " 2\n", " 3\n", " 1\n", " \n", " \n", " 3\n", " 4\n", " 0\n", " \n", " \n", "\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", " x\n", " y\n", " \n", " \n", " \n", " \n", " \n", " <int64>\n", " <float64>\n", " \n", " \n", " 0\n", " 1\n", " 3.0\n", " \n", " \n", " 1\n", " 2\n", " 2.0\n", " \n", " \n", " 2\n", " 3\n", " 1.0\n", " \n", " \n", " 3\n", " 4\n", " NaN\n", " \n", " \n", "\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", " mpg\n", " cyl\n", " disp\n", " hp\n", " drat\n", " wt\n", " qsec\n", " vs\n", " am\n", " gear\n", " carb\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <int64>\n", " <float64>\n", " <int64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " \n", " \n", " Toyota Corolla\n", " 33.9\n", " 4\n", " 71.1\n", " 65\n", " 4.22\n", " 1.835\n", " 19.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Honda Civic\n", " 30.4\n", " 4\n", " 75.7\n", " 52\n", " 4.93\n", " 1.615\n", " 18.52\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " Fiat 128\n", " 32.4\n", " 4\n", " 78.7\n", " 66\n", " 4.08\n", " 2.200\n", " 19.47\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Fiat X1-9\n", " 27.3\n", " 4\n", " 79.0\n", " 66\n", " 4.08\n", " 1.935\n", " 18.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Lotus Europa\n", " 30.4\n", " 4\n", " 95.1\n", " 113\n", " 3.77\n", " 1.513\n", " 16.90\n", " 1\n", " 1\n", " 5\n", " 2\n", " \n", " \n", " Datsun 710\n", " 22.8\n", " 4\n", " 108.0\n", " 93\n", " 3.85\n", " 2.320\n", " 18.61\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Toyota Corona\n", " 21.5\n", " 4\n", " 120.1\n", " 97\n", " 3.70\n", " 2.465\n", " 20.01\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " Porsche 914-2\n", " 26.0\n", " 4\n", " 120.3\n", " 91\n", " 4.43\n", " 2.140\n", " 16.70\n", " 0\n", " 1\n", " 5\n", " 2\n", " \n", " \n", " Volvo 142E\n", " 21.4\n", " 4\n", " 121.0\n", " 109\n", " 4.11\n", " 2.780\n", " 18.60\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " Merc 230\n", " 22.8\n", " 4\n", " 140.8\n", " 95\n", " 3.92\n", " 3.150\n", " 22.90\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " Merc 240D\n", " 24.4\n", " 4\n", " 146.7\n", " 62\n", " 3.69\n", " 3.190\n", " 20.00\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " Ferrari Dino\n", " 19.7\n", " 6\n", " 145.0\n", " 175\n", " 3.62\n", " 2.770\n", " 15.50\n", " 0\n", " 1\n", " 5\n", " 6\n", " \n", " \n", " Mazda RX4\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.620\n", " 16.46\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " Mazda RX4 Wag\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.875\n", " 17.02\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " Merc 280\n", " 19.2\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.30\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " Merc 280C\n", " 17.8\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.90\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " Valiant\n", " 18.1\n", " 6\n", " 225.0\n", " 105\n", " 2.76\n", " 3.460\n", " 20.22\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " Hornet 4 Drive\n", " 21.4\n", " 6\n", " 258.0\n", " 110\n", " 3.08\n", " 3.215\n", " 19.44\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " Merc 450SE\n", " 16.4\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 4.070\n", " 17.40\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " Merc 450SL\n", " 17.3\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.730\n", " 17.60\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " Merc 450SLC\n", " 15.2\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.780\n", " 18.00\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " Maserati Bora\n", " 15.0\n", " 8\n", " 301.0\n", " 335\n", " 3.54\n", " 3.570\n", " 14.60\n", " 0\n", " 1\n", " 5\n", " 8\n", " \n", " \n", " AMC Javelin\n", " 15.2\n", " 8\n", " 304.0\n", " 150\n", " 3.15\n", " 3.435\n", " 17.30\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Dodge Challenger\n", " 15.5\n", " 8\n", " 318.0\n", " 150\n", " 2.76\n", " 3.520\n", " 16.87\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Camaro Z28\n", " 13.3\n", " 8\n", " 350.0\n", " 245\n", " 3.73\n", " 3.840\n", " 15.41\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Ford Pantera L\n", " 15.8\n", " 8\n", " 351.0\n", " 264\n", " 4.22\n", " 3.170\n", " 14.50\n", " 0\n", " 1\n", " 5\n", " 4\n", " \n", " \n", " Hornet Sportabout\n", " 18.7\n", " 8\n", " 360.0\n", " 175\n", " 3.15\n", " 3.440\n", " 17.02\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Duster 360\n", " 14.3\n", " 8\n", " 360.0\n", " 245\n", " 3.21\n", " 3.570\n", " 15.84\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Pontiac Firebird\n", " 19.2\n", " 8\n", " 400.0\n", " 175\n", " 3.08\n", " 3.845\n", " 17.05\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Chrysler Imperial\n", " 14.7\n", " 8\n", " 440.0\n", " 230\n", " 3.23\n", " 5.345\n", " 17.42\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Lincoln Continental\n", " 10.4\n", " 8\n", " 460.0\n", " 215\n", " 3.00\n", " 5.424\n", " 17.82\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Cadillac Fleetwood\n", " 10.4\n", " 8\n", " 472.0\n", " 205\n", " 2.93\n", " 5.250\n", " 17.98\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", "\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", " mpg\n", " cyl\n", " disp\n", " hp\n", " drat\n", " wt\n", " qsec\n", " vs\n", " am\n", " gear\n", " carb\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <int64>\n", " <float64>\n", " <int64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " \n", " \n", " Cadillac Fleetwood\n", " 10.4\n", " 8\n", " 472.0\n", " 205\n", " 2.93\n", " 5.250\n", " 17.98\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Lincoln Continental\n", " 10.4\n", " 8\n", " 460.0\n", " 215\n", " 3.00\n", " 5.424\n", " 17.82\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Chrysler Imperial\n", " 14.7\n", " 8\n", " 440.0\n", " 230\n", " 3.23\n", " 5.345\n", " 17.42\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Pontiac Firebird\n", " 19.2\n", " 8\n", " 400.0\n", " 175\n", " 3.08\n", " 3.845\n", " 17.05\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Hornet Sportabout\n", " 18.7\n", " 8\n", " 360.0\n", " 175\n", " 3.15\n", " 3.440\n", " 17.02\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Duster 360\n", " 14.3\n", " 8\n", " 360.0\n", " 245\n", " 3.21\n", " 3.570\n", " 15.84\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Ford Pantera L\n", " 15.8\n", " 8\n", " 351.0\n", " 264\n", " 4.22\n", " 3.170\n", " 14.50\n", " 0\n", " 1\n", " 5\n", " 4\n", " \n", " \n", " Camaro Z28\n", " 13.3\n", " 8\n", " 350.0\n", " 245\n", " 3.73\n", " 3.840\n", " 15.41\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Dodge Challenger\n", " 15.5\n", " 8\n", " 318.0\n", " 150\n", " 2.76\n", " 3.520\n", " 16.87\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " AMC Javelin\n", " 15.2\n", " 8\n", " 304.0\n", " 150\n", " 3.15\n", " 3.435\n", " 17.30\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Maserati Bora\n", " 15.0\n", " 8\n", " 301.0\n", " 335\n", " 3.54\n", " 3.570\n", " 14.60\n", " 0\n", " 1\n", " 5\n", " 8\n", " \n", " \n", " Merc 450SE\n", " 16.4\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 4.070\n", " 17.40\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " Merc 450SL\n", " 17.3\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.730\n", " 17.60\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " Merc 450SLC\n", " 15.2\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.780\n", " 18.00\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " Hornet 4 Drive\n", " 21.4\n", " 6\n", " 258.0\n", " 110\n", " 3.08\n", " 3.215\n", " 19.44\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " Valiant\n", " 18.1\n", " 6\n", " 225.0\n", " 105\n", " 2.76\n", " 3.460\n", " 20.22\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " Merc 280\n", " 19.2\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.30\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " Merc 280C\n", " 17.8\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.90\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " Mazda RX4\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.620\n", " 16.46\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " Mazda RX4 Wag\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.875\n", " 17.02\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " Merc 240D\n", " 24.4\n", " 4\n", " 146.7\n", " 62\n", " 3.69\n", " 3.190\n", " 20.00\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " Ferrari Dino\n", " 19.7\n", " 6\n", " 145.0\n", " 175\n", " 3.62\n", " 2.770\n", " 15.50\n", " 0\n", " 1\n", " 5\n", " 6\n", " \n", " \n", " Merc 230\n", " 22.8\n", " 4\n", " 140.8\n", " 95\n", " 3.92\n", " 3.150\n", " 22.90\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " Volvo 142E\n", " 21.4\n", " 4\n", " 121.0\n", " 109\n", " 4.11\n", " 2.780\n", " 18.60\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " Porsche 914-2\n", " 26.0\n", " 4\n", " 120.3\n", " 91\n", " 4.43\n", " 2.140\n", " 16.70\n", " 0\n", " 1\n", " 5\n", " 2\n", " \n", " \n", " Toyota Corona\n", " 21.5\n", " 4\n", " 120.1\n", " 97\n", " 3.70\n", " 2.465\n", " 20.01\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " Datsun 710\n", " 22.8\n", " 4\n", " 108.0\n", " 93\n", " 3.85\n", " 2.320\n", " 18.61\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Lotus Europa\n", " 30.4\n", " 4\n", " 95.1\n", " 113\n", " 3.77\n", " 1.513\n", " 16.90\n", " 1\n", " 1\n", " 5\n", " 2\n", " \n", " \n", " Fiat X1-9\n", " 27.3\n", " 4\n", " 79.0\n", " 66\n", " 4.08\n", " 1.935\n", " 18.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Fiat 128\n", " 32.4\n", " 4\n", " 78.7\n", " 66\n", " 4.08\n", " 2.200\n", " 19.47\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Honda Civic\n", " 30.4\n", " 4\n", " 75.7\n", " 52\n", " 4.93\n", " 1.615\n", " 18.52\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " Toyota Corolla\n", " 33.9\n", " 4\n", " 71.1\n", " 65\n", " 4.22\n", " 1.835\n", " 19.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", "\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", " mpg\n", " cyl\n", " disp\n", " hp\n", " drat\n", " wt\n", " qsec\n", " vs\n", " am\n", " gear\n", " carb\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <int64>\n", " <float64>\n", " <int64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " \n", " \n", " 0\n", " 10.4\n", " 8\n", " 460.0\n", " 215\n", " 3.00\n", " 5.424\n", " 17.82\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " 1\n", " 14.7\n", " 8\n", " 440.0\n", " 230\n", " 3.23\n", " 5.345\n", " 17.42\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " 2\n", " 10.4\n", " 8\n", " 472.0\n", " 205\n", " 2.93\n", " 5.250\n", " 17.98\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " 3\n", " 16.4\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 4.070\n", " 17.40\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " 4\n", " 19.2\n", " 8\n", " 400.0\n", " 175\n", " 3.08\n", " 3.845\n", " 17.05\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " 5\n", " 13.3\n", " 8\n", " 350.0\n", " 245\n", " 3.73\n", " 3.840\n", " 15.41\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " 6\n", " 15.2\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.780\n", " 18.00\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " 7\n", " 17.3\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.730\n", " 17.60\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " 8\n", " 15.0\n", " 8\n", " 301.0\n", " 335\n", " 3.54\n", " 3.570\n", " 14.60\n", " 0\n", " 1\n", " 5\n", " 8\n", " \n", " \n", " 9\n", " 14.3\n", " 8\n", " 360.0\n", " 245\n", " 3.21\n", " 3.570\n", " 15.84\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " 10\n", " 15.5\n", " 8\n", " 318.0\n", " 150\n", " 2.76\n", " 3.520\n", " 16.87\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " 11\n", " 18.1\n", " 6\n", " 225.0\n", " 105\n", " 2.76\n", " 3.460\n", " 20.22\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " 12\n", " 19.2\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.30\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " 13\n", " 18.7\n", " 8\n", " 360.0\n", " 175\n", " 3.15\n", " 3.440\n", " 17.02\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " 14\n", " 17.8\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.90\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " 15\n", " 15.2\n", " 8\n", " 304.0\n", " 150\n", " 3.15\n", " 3.435\n", " 17.30\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " 16\n", " 21.4\n", " 6\n", " 258.0\n", " 110\n", " 3.08\n", " 3.215\n", " 19.44\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " 17\n", " 24.4\n", " 4\n", " 146.7\n", " 62\n", " 3.69\n", " 3.190\n", " 20.00\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " 18\n", " 15.8\n", " 8\n", " 351.0\n", " 264\n", " 4.22\n", " 3.170\n", " 14.50\n", " 0\n", " 1\n", " 5\n", " 4\n", " \n", " \n", " 19\n", " 22.8\n", " 4\n", " 140.8\n", " 95\n", " 3.92\n", " 3.150\n", " 22.90\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " 20\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.875\n", " 17.02\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " 21\n", " 21.4\n", " 4\n", " 121.0\n", " 109\n", " 4.11\n", " 2.780\n", " 18.60\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " 22\n", " 19.7\n", " 6\n", " 145.0\n", " 175\n", " 3.62\n", " 2.770\n", " 15.50\n", " 0\n", " 1\n", " 5\n", " 6\n", " \n", " \n", " 23\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.620\n", " 16.46\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " 24\n", " 21.5\n", " 4\n", " 120.1\n", " 97\n", " 3.70\n", " 2.465\n", " 20.01\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " 25\n", " 22.8\n", " 4\n", " 108.0\n", " 93\n", " 3.85\n", " 2.320\n", " 18.61\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " 26\n", " 32.4\n", " 4\n", " 78.7\n", " 66\n", " 4.08\n", " 2.200\n", " 19.47\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " 27\n", " 26.0\n", " 4\n", " 120.3\n", " 91\n", " 4.43\n", " 2.140\n", " 16.70\n", " 0\n", " 1\n", " 5\n", " 2\n", " \n", " \n", " 28\n", " 27.3\n", " 4\n", " 79.0\n", " 66\n", " 4.08\n", " 1.935\n", " 18.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " 29\n", " 33.9\n", " 4\n", " 71.1\n", " 65\n", " 4.22\n", " 1.835\n", " 19.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " 30\n", " 30.4\n", " 4\n", " 75.7\n", " 52\n", " 4.93\n", " 1.615\n", " 18.52\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " 31\n", " 30.4\n", " 4\n", " 95.1\n", " 113\n", " 3.77\n", " 1.513\n", " 16.90\n", " 1\n", " 1\n", " 5\n", " 2\n", " \n", " \n", "\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", " mpg\n", " cyl\n", " disp\n", " hp\n", " drat\n", " wt\n", " qsec\n", " vs\n", " am\n", " gear\n", " carb\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <int64>\n", " <float64>\n", " <int64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " \n", " \n", " 0\n", " 24.4\n", " 4\n", " 146.7\n", " 62\n", " 3.69\n", " 3.190\n", " 20.00\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " 1\n", " 22.8\n", " 4\n", " 140.8\n", " 95\n", " 3.92\n", " 3.150\n", " 22.90\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " 2\n", " 21.4\n", " 4\n", " 121.0\n", " 109\n", " 4.11\n", " 2.780\n", " 18.60\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " 3\n", " 21.5\n", " 4\n", " 120.1\n", " 97\n", " 3.70\n", " 2.465\n", " 20.01\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " 4\n", " 22.8\n", " 4\n", " 108.0\n", " 93\n", " 3.85\n", " 2.320\n", " 18.61\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " 5\n", " 32.4\n", " 4\n", " 78.7\n", " 66\n", " 4.08\n", " 2.200\n", " 19.47\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " 6\n", " 26.0\n", " 4\n", " 120.3\n", " 91\n", " 4.43\n", " 2.140\n", " 16.70\n", " 0\n", " 1\n", " 5\n", " 2\n", " \n", " \n", " 7\n", " 27.3\n", " 4\n", " 79.0\n", " 66\n", " 4.08\n", " 1.935\n", " 18.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " 8\n", " 33.9\n", " 4\n", " 71.1\n", " 65\n", " 4.22\n", " 1.835\n", " 19.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " 9\n", " 30.4\n", " 4\n", " 75.7\n", " 52\n", " 4.93\n", " 1.615\n", " 18.52\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " 10\n", " 30.4\n", " 4\n", " 95.1\n", " 113\n", " 3.77\n", " 1.513\n", " 16.90\n", " 1\n", " 1\n", " 5\n", " 2\n", " \n", " \n", " 11\n", " 18.1\n", " 6\n", " 225.0\n", " 105\n", " 2.76\n", " 3.460\n", " 20.22\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " 12\n", " 19.2\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.30\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " 13\n", " 17.8\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.90\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " 14\n", " 21.4\n", " 6\n", " 258.0\n", " 110\n", " 3.08\n", " 3.215\n", " 19.44\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " 15\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.875\n", " 17.02\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " 16\n", " 19.7\n", " 6\n", " 145.0\n", " 175\n", " 3.62\n", " 2.770\n", " 15.50\n", " 0\n", " 1\n", " 5\n", " 6\n", " \n", " \n", " 17\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.620\n", " 16.46\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " 18\n", " 10.4\n", " 8\n", " 460.0\n", " 215\n", " 3.00\n", " 5.424\n", " 17.82\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " 19\n", " 14.7\n", " 8\n", " 440.0\n", " 230\n", " 3.23\n", " 5.345\n", " 17.42\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " 20\n", " 10.4\n", " 8\n", " 472.0\n", " 205\n", " 2.93\n", " 5.250\n", " 17.98\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " 21\n", " 16.4\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 4.070\n", " 17.40\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " 22\n", " 19.2\n", " 8\n", " 400.0\n", " 175\n", " 3.08\n", " 3.845\n", " 17.05\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " 23\n", " 13.3\n", " 8\n", " 350.0\n", " 245\n", " 3.73\n", " 3.840\n", " 15.41\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " 24\n", " 15.2\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.780\n", " 18.00\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " 25\n", " 17.3\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.730\n", " 17.60\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " 26\n", " 14.3\n", " 8\n", " 360.0\n", " 245\n", " 3.21\n", " 3.570\n", " 15.84\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " 27\n", " 15.0\n", " 8\n", " 301.0\n", " 335\n", " 3.54\n", " 3.570\n", " 14.60\n", " 0\n", " 1\n", " 5\n", " 8\n", " \n", " \n", " 28\n", " 15.5\n", " 8\n", " 318.0\n", " 150\n", " 2.76\n", " 3.520\n", " 16.87\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " 29\n", " 18.7\n", " 8\n", " 360.0\n", " 175\n", " 3.15\n", " 3.440\n", " 17.02\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " 30\n", " 15.2\n", " 8\n", " 304.0\n", " 150\n", " 3.15\n", " 3.435\n", " 17.30\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " 31\n", " 15.8\n", " 8\n", " 351.0\n", " 264\n", " 4.22\n", " 3.170\n", " 14.50\n", " 0\n", " 1\n", " 5\n", " 4\n", " \n", " \n", "\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", " mpg\n", " cyl\n", " disp\n", " hp\n", " drat\n", " wt\n", " qsec\n", " vs\n", " am\n", " gear\n", " carb\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <int64>\n", " <float64>\n", " <int64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " \n", " \n", " Lincoln Continental\n", " 10.4\n", " 8\n", " 460.0\n", " 215\n", " 3.00\n", " 5.424\n", " 17.82\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Cadillac Fleetwood\n", " 10.4\n", " 8\n", " 472.0\n", " 205\n", " 2.93\n", " 5.250\n", " 17.98\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Camaro Z28\n", " 13.3\n", " 8\n", " 350.0\n", " 245\n", " 3.73\n", " 3.840\n", " 15.41\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Duster 360\n", " 14.3\n", " 8\n", " 360.0\n", " 245\n", " 3.21\n", " 3.570\n", " 15.84\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Chrysler Imperial\n", " 14.7\n", " 8\n", " 440.0\n", " 230\n", " 3.23\n", " 5.345\n", " 17.42\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Maserati Bora\n", " 15.0\n", " 8\n", " 301.0\n", " 335\n", " 3.54\n", " 3.570\n", " 14.60\n", " 0\n", " 1\n", " 5\n", " 8\n", " \n", " \n", " Merc 450SLC\n", " 15.2\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.780\n", " 18.00\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " AMC Javelin\n", " 15.2\n", " 8\n", " 304.0\n", " 150\n", " 3.15\n", " 3.435\n", " 17.30\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Dodge Challenger\n", " 15.5\n", " 8\n", " 318.0\n", " 150\n", " 2.76\n", " 3.520\n", " 16.87\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Ford Pantera L\n", " 15.8\n", " 8\n", " 351.0\n", " 264\n", " 4.22\n", " 3.170\n", " 14.50\n", " 0\n", " 1\n", " 5\n", " 4\n", " \n", " \n", " Merc 450SE\n", " 16.4\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 4.070\n", " 17.40\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " Merc 450SL\n", " 17.3\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.730\n", " 17.60\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " Merc 280C\n", " 17.8\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.90\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " Valiant\n", " 18.1\n", " 6\n", " 225.0\n", " 105\n", " 2.76\n", " 3.460\n", " 20.22\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " Hornet Sportabout\n", " 18.7\n", " 8\n", " 360.0\n", " 175\n", " 3.15\n", " 3.440\n", " 17.02\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Merc 280\n", " 19.2\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.30\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " Pontiac Firebird\n", " 19.2\n", " 8\n", " 400.0\n", " 175\n", " 3.08\n", " 3.845\n", " 17.05\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Ferrari Dino\n", " 19.7\n", " 6\n", " 145.0\n", " 175\n", " 3.62\n", " 2.770\n", " 15.50\n", " 0\n", " 1\n", " 5\n", " 6\n", " \n", " \n", " Mazda RX4\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.620\n", " 16.46\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " Mazda RX4 Wag\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.875\n", " 17.02\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " Hornet 4 Drive\n", " 21.4\n", " 6\n", " 258.0\n", " 110\n", " 3.08\n", " 3.215\n", " 19.44\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " Volvo 142E\n", " 21.4\n", " 4\n", " 121.0\n", " 109\n", " 4.11\n", " 2.780\n", " 18.60\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " Toyota Corona\n", " 21.5\n", " 4\n", " 120.1\n", " 97\n", " 3.70\n", " 2.465\n", " 20.01\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " Merc 230\n", " 22.8\n", " 4\n", " 140.8\n", " 95\n", " 3.92\n", " 3.150\n", " 22.90\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " Datsun 710\n", " 22.8\n", " 4\n", " 108.0\n", " 93\n", " 3.85\n", " 2.320\n", " 18.61\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Merc 240D\n", " 24.4\n", " 4\n", " 146.7\n", " 62\n", " 3.69\n", " 3.190\n", " 20.00\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " Porsche 914-2\n", " 26.0\n", " 4\n", " 120.3\n", " 91\n", " 4.43\n", " 2.140\n", " 16.70\n", " 0\n", " 1\n", " 5\n", " 2\n", " \n", " \n", " Fiat X1-9\n", " 27.3\n", " 4\n", " 79.0\n", " 66\n", " 4.08\n", " 1.935\n", " 18.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Lotus Europa\n", " 30.4\n", " 4\n", " 95.1\n", " 113\n", " 3.77\n", " 1.513\n", " 16.90\n", " 1\n", " 1\n", " 5\n", " 2\n", " \n", " \n", " Honda Civic\n", " 30.4\n", " 4\n", " 75.7\n", " 52\n", " 4.93\n", " 1.615\n", " 18.52\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " Fiat 128\n", " 32.4\n", " 4\n", " 78.7\n", " 66\n", " 4.08\n", " 2.200\n", " 19.47\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Toyota Corolla\n", " 33.9\n", " 4\n", " 71.1\n", " 65\n", " 4.22\n", " 1.835\n", " 19.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", "\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", " Sepal_Length\n", " Sepal_Width\n", " Petal_Length\n", " Petal_Width\n", " Species\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <object>\n", " \n", " \n", " 13\n", " 4.3\n", " 3.0\n", " 1.1\n", " 0.1\n", " setosa\n", " \n", " \n", " 8\n", " 4.4\n", " 2.9\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 38\n", " 4.4\n", " 3.0\n", " 1.3\n", " 0.2\n", " setosa\n", " \n", " \n", " 42\n", " 4.4\n", " 3.2\n", " 1.3\n", " 0.2\n", " setosa\n", " \n", " \n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " \n", " \n", " 41\n", " 4.5\n", " 2.3\n", " 1.3\n", " 0.3\n", " setosa\n", " \n", " \n", " 118\n", " 7.7\n", " 2.6\n", " 6.9\n", " 2.3\n", " virginica\n", " \n", " \n", " 122\n", " 7.7\n", " 2.8\n", " 6.7\n", " 2.0\n", " virginica\n", " \n", " \n", " 135\n", " 7.7\n", " 3.0\n", " 6.1\n", " 2.3\n", " virginica\n", " \n", " \n", " 117\n", " 7.7\n", " 3.8\n", " 6.7\n", " 2.2\n", " virginica\n", " \n", " \n", " 131\n", " 7.9\n", " 3.8\n", " 6.4\n", " 2.0\n", " virginica\n", " \n", " \n", "\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", " Sepal_Length\n", " Sepal_Width\n", " Petal_Length\n", " Petal_Width\n", " Species\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <object>\n", " \n", " \n", " 131\n", " 7.9\n", " 3.8\n", " 6.4\n", " 2.0\n", " virginica\n", " \n", " \n", " 117\n", " 7.7\n", " 3.8\n", " 6.7\n", " 2.2\n", " virginica\n", " \n", " \n", " 135\n", " 7.7\n", " 3.0\n", " 6.1\n", " 2.3\n", " virginica\n", " \n", " \n", " 122\n", " 7.7\n", " 2.8\n", " 6.7\n", " 2.0\n", " virginica\n", " \n", " \n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " \n", " \n", " 118\n", " 7.7\n", " 2.6\n", " 6.9\n", " 2.3\n", " virginica\n", " \n", " \n", " 41\n", " 4.5\n", " 2.3\n", " 1.3\n", " 0.3\n", " setosa\n", " \n", " \n", " 42\n", " 4.4\n", " 3.2\n", " 1.3\n", " 0.2\n", " setosa\n", " \n", " \n", " 38\n", " 4.4\n", " 3.0\n", " 1.3\n", " 0.2\n", " setosa\n", " \n", " \n", " 8\n", " 4.4\n", " 2.9\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 13\n", " 4.3\n", " 3.0\n", " 1.1\n", " 0.1\n", " setosa\n", " \n", " \n", "\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": [ "
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", " mpg\n", " cyl\n", " disp\n", " hp\n", " drat\n", " wt\n", " qsec\n", " vs\n", " am\n", " gear\n", " carb\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <int64>\n", " <float64>\n", " <int64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " \n", " \n", " 0\n", " 24.4\n", " 4\n", " 146.7\n", " 62\n", " 3.69\n", " 3.190\n", " 20.00\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " 1\n", " 22.8\n", " 4\n", " 140.8\n", " 95\n", " 3.92\n", " 3.150\n", " 22.90\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " 2\n", " 21.4\n", " 4\n", " 121.0\n", " 109\n", " 4.11\n", " 2.780\n", " 18.60\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " 3\n", " 21.5\n", " 4\n", " 120.1\n", " 97\n", " 3.70\n", " 2.465\n", " 20.01\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " 4\n", " 22.8\n", " 4\n", " 108.0\n", " 93\n", " 3.85\n", " 2.320\n", " 18.61\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " 5\n", " 32.4\n", " 4\n", " 78.7\n", " 66\n", " 4.08\n", " 2.200\n", " 19.47\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " 6\n", " 26.0\n", " 4\n", " 120.3\n", " 91\n", " 4.43\n", " 2.140\n", " 16.70\n", " 0\n", " 1\n", " 5\n", " 2\n", " \n", " \n", " 7\n", " 27.3\n", " 4\n", " 79.0\n", " 66\n", " 4.08\n", " 1.935\n", " 18.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " 8\n", " 33.9\n", " 4\n", " 71.1\n", " 65\n", " 4.22\n", " 1.835\n", " 19.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " 9\n", " 30.4\n", " 4\n", " 75.7\n", " 52\n", " 4.93\n", " 1.615\n", " 18.52\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " 10\n", " 30.4\n", " 4\n", " 95.1\n", " 113\n", " 3.77\n", " 1.513\n", " 16.90\n", " 1\n", " 1\n", " 5\n", " 2\n", " \n", " \n", " 11\n", " 18.1\n", " 6\n", " 225.0\n", " 105\n", " 2.76\n", " 3.460\n", " 20.22\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " 12\n", " 19.2\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.30\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " 13\n", " 17.8\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.90\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " 14\n", " 21.4\n", " 6\n", " 258.0\n", " 110\n", " 3.08\n", " 3.215\n", " 19.44\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " 15\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.875\n", " 17.02\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " 16\n", " 19.7\n", " 6\n", " 145.0\n", " 175\n", " 3.62\n", " 2.770\n", " 15.50\n", " 0\n", " 1\n", " 5\n", " 6\n", " \n", " \n", " 17\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.620\n", " 16.46\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " 18\n", " 10.4\n", " 8\n", " 460.0\n", " 215\n", " 3.00\n", " 5.424\n", " 17.82\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " 19\n", " 14.7\n", " 8\n", " 440.0\n", " 230\n", " 3.23\n", " 5.345\n", " 17.42\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " 20\n", " 10.4\n", " 8\n", " 472.0\n", " 205\n", " 2.93\n", " 5.250\n", " 17.98\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " 21\n", " 16.4\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 4.070\n", " 17.40\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " 22\n", " 19.2\n", " 8\n", " 400.0\n", " 175\n", " 3.08\n", " 3.845\n", " 17.05\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " 23\n", " 13.3\n", " 8\n", " 350.0\n", " 245\n", " 3.73\n", " 3.840\n", " 15.41\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " 24\n", " 15.2\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.780\n", " 18.00\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " 25\n", " 17.3\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.730\n", " 17.60\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " 26\n", " 14.3\n", " 8\n", " 360.0\n", " 245\n", " 3.21\n", " 3.570\n", " 15.84\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " 27\n", " 15.0\n", " 8\n", " 301.0\n", " 335\n", " 3.54\n", " 3.570\n", " 14.60\n", " 0\n", " 1\n", " 5\n", " 8\n", " \n", " \n", " 28\n", " 15.5\n", " 8\n", " 318.0\n", " 150\n", " 2.76\n", " 3.520\n", " 16.87\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " 29\n", " 18.7\n", " 8\n", " 360.0\n", " 175\n", " 3.15\n", " 3.440\n", " 17.02\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " 30\n", " 15.2\n", " 8\n", " 304.0\n", " 150\n", " 3.15\n", " 3.435\n", " 17.30\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " 31\n", " 15.8\n", " 8\n", " 351.0\n", " 264\n", " 4.22\n", " 3.170\n", " 14.50\n", " 0\n", " 1\n", " 5\n", " 4\n", " \n", " \n", "\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", " mpg\n", " cyl\n", " disp\n", " hp\n", " drat\n", " wt\n", " qsec\n", " vs\n", " am\n", " gear\n", " carb\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <int64>\n", " <float64>\n", " <int64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " \n", " \n", " Lincoln Continental\n", " 10.4\n", " 8\n", " 460.0\n", " 215\n", " 3.00\n", " 5.424\n", " 17.82\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Cadillac Fleetwood\n", " 10.4\n", " 8\n", " 472.0\n", " 205\n", " 2.93\n", " 5.250\n", " 17.98\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Camaro Z28\n", " 13.3\n", " 8\n", " 350.0\n", " 245\n", " 3.73\n", " 3.840\n", " 15.41\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Duster 360\n", " 14.3\n", " 8\n", " 360.0\n", " 245\n", " 3.21\n", " 3.570\n", " 15.84\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Chrysler Imperial\n", " 14.7\n", " 8\n", " 440.0\n", " 230\n", " 3.23\n", " 5.345\n", " 17.42\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Maserati Bora\n", " 15.0\n", " 8\n", " 301.0\n", " 335\n", " 3.54\n", " 3.570\n", " 14.60\n", " 0\n", " 1\n", " 5\n", " 8\n", " \n", " \n", " Merc 450SLC\n", " 15.2\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.780\n", " 18.00\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " AMC Javelin\n", " 15.2\n", " 8\n", " 304.0\n", " 150\n", " 3.15\n", " 3.435\n", " 17.30\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Dodge Challenger\n", " 15.5\n", " 8\n", " 318.0\n", " 150\n", " 2.76\n", " 3.520\n", " 16.87\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Ford Pantera L\n", " 15.8\n", " 8\n", " 351.0\n", " 264\n", " 4.22\n", " 3.170\n", " 14.50\n", " 0\n", " 1\n", " 5\n", " 4\n", " \n", " \n", " Merc 450SE\n", " 16.4\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 4.070\n", " 17.40\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " Merc 450SL\n", " 17.3\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.730\n", " 17.60\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " Merc 280C\n", " 17.8\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.90\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " Valiant\n", " 18.1\n", " 6\n", " 225.0\n", " 105\n", " 2.76\n", " 3.460\n", " 20.22\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " Hornet Sportabout\n", " 18.7\n", " 8\n", " 360.0\n", " 175\n", " 3.15\n", " 3.440\n", " 17.02\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Merc 280\n", " 19.2\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.30\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " Pontiac Firebird\n", " 19.2\n", " 8\n", " 400.0\n", " 175\n", " 3.08\n", " 3.845\n", " 17.05\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Ferrari Dino\n", " 19.7\n", " 6\n", " 145.0\n", " 175\n", " 3.62\n", " 2.770\n", " 15.50\n", " 0\n", " 1\n", " 5\n", " 6\n", " \n", " \n", " Mazda RX4\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.620\n", " 16.46\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " Mazda RX4 Wag\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.875\n", " 17.02\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " Hornet 4 Drive\n", " 21.4\n", " 6\n", " 258.0\n", " 110\n", " 3.08\n", " 3.215\n", " 19.44\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " Volvo 142E\n", " 21.4\n", " 4\n", " 121.0\n", " 109\n", " 4.11\n", " 2.780\n", " 18.60\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " Toyota Corona\n", " 21.5\n", " 4\n", " 120.1\n", " 97\n", " 3.70\n", " 2.465\n", " 20.01\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " Merc 230\n", " 22.8\n", " 4\n", " 140.8\n", " 95\n", " 3.92\n", " 3.150\n", " 22.90\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " Datsun 710\n", " 22.8\n", " 4\n", " 108.0\n", " 93\n", " 3.85\n", " 2.320\n", " 18.61\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Merc 240D\n", " 24.4\n", " 4\n", " 146.7\n", " 62\n", " 3.69\n", " 3.190\n", " 20.00\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " Porsche 914-2\n", " 26.0\n", " 4\n", " 120.3\n", " 91\n", " 4.43\n", " 2.140\n", " 16.70\n", " 0\n", " 1\n", " 5\n", " 2\n", " \n", " \n", " Fiat X1-9\n", " 27.3\n", " 4\n", " 79.0\n", " 66\n", " 4.08\n", " 1.935\n", " 18.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Lotus Europa\n", " 30.4\n", " 4\n", " 95.1\n", " 113\n", " 3.77\n", " 1.513\n", " 16.90\n", " 1\n", " 1\n", " 5\n", " 2\n", " \n", " \n", " Honda Civic\n", " 30.4\n", " 4\n", " 75.7\n", " 52\n", " 4.93\n", " 1.615\n", " 18.52\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " Fiat 128\n", " 32.4\n", " 4\n", " 78.7\n", " 66\n", " 4.08\n", " 2.200\n", " 19.47\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Toyota Corolla\n", " 33.9\n", " 4\n", " 71.1\n", " 65\n", " 4.22\n", " 1.835\n", " 19.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", "\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", " Sepal_Length\n", " Sepal_Width\n", " Petal_Length\n", " Petal_Width\n", " Species\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <object>\n", " \n", " \n", " 13\n", " 4.3\n", " 3.0\n", " 1.1\n", " 0.1\n", " setosa\n", " \n", " \n", " 8\n", " 4.4\n", " 2.9\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 38\n", " 4.4\n", " 3.0\n", " 1.3\n", " 0.2\n", " setosa\n", " \n", " \n", " 42\n", " 4.4\n", " 3.2\n", " 1.3\n", " 0.2\n", " setosa\n", " \n", " \n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " \n", " \n", " 41\n", " 4.5\n", " 2.3\n", " 1.3\n", " 0.3\n", " setosa\n", " \n", " \n", " 118\n", " 7.7\n", " 2.6\n", " 6.9\n", " 2.3\n", " virginica\n", " \n", " \n", " 122\n", " 7.7\n", " 2.8\n", " 6.7\n", " 2.0\n", " virginica\n", " \n", " \n", " 135\n", " 7.7\n", " 3.0\n", " 6.1\n", " 2.3\n", " virginica\n", " \n", " \n", " 117\n", " 7.7\n", " 3.8\n", " 6.7\n", " 2.2\n", " virginica\n", " \n", " \n", " 131\n", " 7.9\n", " 3.8\n", " 6.4\n", " 2.0\n", " virginica\n", " \n", " \n", "\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", " Sepal_Length\n", " Sepal_Width\n", " Petal_Length\n", " Petal_Width\n", " Species\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <object>\n", " \n", " \n", " 131\n", " 7.9\n", " 3.8\n", " 6.4\n", " 2.0\n", " virginica\n", " \n", " \n", " 117\n", " 7.7\n", " 3.8\n", " 6.7\n", " 2.2\n", " virginica\n", " \n", " \n", " 135\n", " 7.7\n", " 3.0\n", " 6.1\n", " 2.3\n", " virginica\n", " \n", " \n", " 122\n", " 7.7\n", " 2.8\n", " 6.7\n", " 2.0\n", " virginica\n", " \n", " \n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " \n", " \n", " 118\n", " 7.7\n", " 2.6\n", " 6.9\n", " 2.3\n", " virginica\n", " \n", " \n", " 41\n", " 4.5\n", " 2.3\n", " 1.3\n", " 0.3\n", " setosa\n", " \n", " \n", " 42\n", " 4.4\n", " 3.2\n", " 1.3\n", " 0.2\n", " setosa\n", " \n", " \n", " 38\n", " 4.4\n", " 3.0\n", " 1.3\n", " 0.2\n", " setosa\n", " \n", " \n", " 8\n", " 4.4\n", " 2.9\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 13\n", " 4.3\n", " 3.0\n", " 1.1\n", " 0.1\n", " setosa\n", " \n", " \n", "\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": [ "
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", " mpg\n", " cyl\n", " disp\n", " hp\n", " drat\n", " wt\n", " qsec\n", " vs\n", " am\n", " gear\n", " carb\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <int64>\n", " <float64>\n", " <int64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " <int64>\n", " \n", " \n", " Lincoln Continental\n", " 10.4\n", " 8\n", " 460.0\n", " 215\n", " 3.00\n", " 5.424\n", " 17.82\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Cadillac Fleetwood\n", " 10.4\n", " 8\n", " 472.0\n", " 205\n", " 2.93\n", " 5.250\n", " 17.98\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Camaro Z28\n", " 13.3\n", " 8\n", " 350.0\n", " 245\n", " 3.73\n", " 3.840\n", " 15.41\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Duster 360\n", " 14.3\n", " 8\n", " 360.0\n", " 245\n", " 3.21\n", " 3.570\n", " 15.84\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Chrysler Imperial\n", " 14.7\n", " 8\n", " 440.0\n", " 230\n", " 3.23\n", " 5.345\n", " 17.42\n", " 0\n", " 0\n", " 3\n", " 4\n", " \n", " \n", " Maserati Bora\n", " 15.0\n", " 8\n", " 301.0\n", " 335\n", " 3.54\n", " 3.570\n", " 14.60\n", " 0\n", " 1\n", " 5\n", " 8\n", " \n", " \n", " Merc 450SLC\n", " 15.2\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.780\n", " 18.00\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " AMC Javelin\n", " 15.2\n", " 8\n", " 304.0\n", " 150\n", " 3.15\n", " 3.435\n", " 17.30\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Dodge Challenger\n", " 15.5\n", " 8\n", " 318.0\n", " 150\n", " 2.76\n", " 3.520\n", " 16.87\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Ford Pantera L\n", " 15.8\n", " 8\n", " 351.0\n", " 264\n", " 4.22\n", " 3.170\n", " 14.50\n", " 0\n", " 1\n", " 5\n", " 4\n", " \n", " \n", " Merc 450SE\n", " 16.4\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 4.070\n", " 17.40\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " Merc 450SL\n", " 17.3\n", " 8\n", " 275.8\n", " 180\n", " 3.07\n", " 3.730\n", " 17.60\n", " 0\n", " 0\n", " 3\n", " 3\n", " \n", " \n", " Merc 280C\n", " 17.8\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.90\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " Valiant\n", " 18.1\n", " 6\n", " 225.0\n", " 105\n", " 2.76\n", " 3.460\n", " 20.22\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " Hornet Sportabout\n", " 18.7\n", " 8\n", " 360.0\n", " 175\n", " 3.15\n", " 3.440\n", " 17.02\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Merc 280\n", " 19.2\n", " 6\n", " 167.6\n", " 123\n", " 3.92\n", " 3.440\n", " 18.30\n", " 1\n", " 0\n", " 4\n", " 4\n", " \n", " \n", " Pontiac Firebird\n", " 19.2\n", " 8\n", " 400.0\n", " 175\n", " 3.08\n", " 3.845\n", " 17.05\n", " 0\n", " 0\n", " 3\n", " 2\n", " \n", " \n", " Ferrari Dino\n", " 19.7\n", " 6\n", " 145.0\n", " 175\n", " 3.62\n", " 2.770\n", " 15.50\n", " 0\n", " 1\n", " 5\n", " 6\n", " \n", " \n", " Mazda RX4\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.620\n", " 16.46\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " Mazda RX4 Wag\n", " 21.0\n", " 6\n", " 160.0\n", " 110\n", " 3.90\n", " 2.875\n", " 17.02\n", " 0\n", " 1\n", " 4\n", " 4\n", " \n", " \n", " Hornet 4 Drive\n", " 21.4\n", " 6\n", " 258.0\n", " 110\n", " 3.08\n", " 3.215\n", " 19.44\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " Volvo 142E\n", " 21.4\n", " 4\n", " 121.0\n", " 109\n", " 4.11\n", " 2.780\n", " 18.60\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " Toyota Corona\n", " 21.5\n", " 4\n", " 120.1\n", " 97\n", " 3.70\n", " 2.465\n", " 20.01\n", " 1\n", " 0\n", " 3\n", " 1\n", " \n", " \n", " Merc 230\n", " 22.8\n", " 4\n", " 140.8\n", " 95\n", " 3.92\n", " 3.150\n", " 22.90\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " Datsun 710\n", " 22.8\n", " 4\n", " 108.0\n", " 93\n", " 3.85\n", " 2.320\n", " 18.61\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Merc 240D\n", " 24.4\n", " 4\n", " 146.7\n", " 62\n", " 3.69\n", " 3.190\n", " 20.00\n", " 1\n", " 0\n", " 4\n", " 2\n", " \n", " \n", " Porsche 914-2\n", " 26.0\n", " 4\n", " 120.3\n", " 91\n", " 4.43\n", " 2.140\n", " 16.70\n", " 0\n", " 1\n", " 5\n", " 2\n", " \n", " \n", " Fiat X1-9\n", " 27.3\n", " 4\n", " 79.0\n", " 66\n", " 4.08\n", " 1.935\n", " 18.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Lotus Europa\n", " 30.4\n", " 4\n", " 95.1\n", " 113\n", " 3.77\n", " 1.513\n", " 16.90\n", " 1\n", " 1\n", " 5\n", " 2\n", " \n", " \n", " Honda Civic\n", " 30.4\n", " 4\n", " 75.7\n", " 52\n", " 4.93\n", " 1.615\n", " 18.52\n", " 1\n", " 1\n", " 4\n", " 2\n", " \n", " \n", " Fiat 128\n", " 32.4\n", " 4\n", " 78.7\n", " 66\n", " 4.08\n", " 2.200\n", " 19.47\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", " Toyota Corolla\n", " 33.9\n", " 4\n", " 71.1\n", " 65\n", " 4.22\n", " 1.835\n", " 19.90\n", " 1\n", " 1\n", " 4\n", " 1\n", " \n", " \n", "\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", " Sepal_Length\n", " Sepal_Width\n", " Petal_Length\n", " Petal_Width\n", " Species\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <object>\n", " \n", " \n", " 13\n", " 4.3\n", " 3.0\n", " 1.1\n", " 0.1\n", " setosa\n", " \n", " \n", " 8\n", " 4.4\n", " 2.9\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 38\n", " 4.4\n", " 3.0\n", " 1.3\n", " 0.2\n", " setosa\n", " \n", " \n", " 42\n", " 4.4\n", " 3.2\n", " 1.3\n", " 0.2\n", " setosa\n", " \n", " \n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " \n", " \n", " 41\n", " 4.5\n", " 2.3\n", " 1.3\n", " 0.3\n", " setosa\n", " \n", " \n", " 118\n", " 7.7\n", " 2.6\n", " 6.9\n", " 2.3\n", " virginica\n", " \n", " \n", " 122\n", " 7.7\n", " 2.8\n", " 6.7\n", " 2.0\n", " virginica\n", " \n", " \n", " 135\n", " 7.7\n", " 3.0\n", " 6.1\n", " 2.3\n", " virginica\n", " \n", " \n", " 117\n", " 7.7\n", " 3.8\n", " 6.7\n", " 2.2\n", " virginica\n", " \n", " \n", " 131\n", " 7.9\n", " 3.8\n", " 6.4\n", " 2.0\n", " virginica\n", " \n", " \n", "\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", " Sepal_Length\n", " Sepal_Width\n", " Petal_Length\n", " Petal_Width\n", " Species\n", " \n", " \n", " \n", " \n", " \n", " <float64>\n", " <float64>\n", " <float64>\n", " <float64>\n", " <object>\n", " \n", " \n", " 131\n", " 7.9\n", " 3.8\n", " 6.4\n", " 2.0\n", " virginica\n", " \n", " \n", " 117\n", " 7.7\n", " 3.8\n", " 6.7\n", " 2.2\n", " virginica\n", " \n", " \n", " 135\n", " 7.7\n", " 3.0\n", " 6.1\n", " 2.3\n", " virginica\n", " \n", " \n", " 122\n", " 7.7\n", " 2.8\n", " 6.7\n", " 2.0\n", " virginica\n", " \n", " \n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " ...\n", " \n", " \n", " 118\n", " 7.7\n", " 2.6\n", " 6.9\n", " 2.3\n", " virginica\n", " \n", " \n", " 41\n", " 4.5\n", " 2.3\n", " 1.3\n", " 0.3\n", " setosa\n", " \n", " \n", " 42\n", " 4.4\n", " 3.2\n", " 1.3\n", " 0.2\n", " setosa\n", " \n", " \n", " 38\n", " 4.4\n", " 3.0\n", " 1.3\n", " 0.2\n", " setosa\n", " \n", " \n", " 8\n", " 4.4\n", " 2.9\n", " 1.4\n", " 0.2\n", " setosa\n", " \n", " \n", " 13\n", " 4.3\n", " 3.0\n", " 1.1\n", " 0.1\n", " setosa\n", " \n", " \n", "\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": [ "