{"id":22445763,"url":"https://github.com/axil/pandas-illustrated","last_synced_at":"2025-08-01T20:31:13.516Z","repository":{"id":65494473,"uuid":"581228813","full_name":"axil/pandas-illustrated","owner":"axil","description":"A collection of Pandas helper functions.","archived":false,"fork":false,"pushed_at":"2023-04-04T10:03:22.000Z","size":271,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-08T14:16:03.843Z","etag":null,"topics":["data-analysis","data-science","pandas","pandas-dataframe","pandas-library","python"],"latest_commit_sha":null,"homepage":"https://betterprogramming.pub/pandas-illustrated-the-definitive-visual-guide-to-pandas-c31fa921a43?sk=50184a8a8b46ffca16664f6529741abc","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/axil.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.txt","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-12-22T16:02:27.000Z","updated_at":"2024-10-27T18:34:12.000Z","dependencies_parsed_at":"2023-02-17T23:00:42.264Z","dependency_job_id":null,"html_url":"https://github.com/axil/pandas-illustrated","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axil%2Fpandas-illustrated","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axil%2Fpandas-illustrated/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axil%2Fpandas-illustrated/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axil%2Fpandas-illustrated/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/axil","download_url":"https://codeload.github.com/axil/pandas-illustrated/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228402260,"owners_count":17914230,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-analysis","data-science","pandas","pandas-dataframe","pandas-library","python"],"created_at":"2024-12-06T03:16:46.295Z","updated_at":"2024-12-06T03:16:46.728Z","avatar_url":"https://github.com/axil.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿# pandas-illustrated\n\n[![pypi](https://img.shields.io/pypi/v/pandas-illustrated.svg)](https://pypi.python.org/pypi/pandas-illustrated)\n[![python](https://img.shields.io/pypi/pyversions/pandas-illustrated.svg)](https://pypi.org/project/pandas-illustrated/)\n![pytest](https://github.com/axil/pandas-illustrated/actions/workflows/python-package.yml/badge.svg)\n![Coverage Badge](img/coverage.svg)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![License](https://img.shields.io/pypi/l/pandas-illustrated)](https://pypi.org/project/pandas-illustrated/)\n\nThis repo contains code for a number of helper functions mentioned in the [Pandas Illustrated](https://betterprogramming.pub/pandas-illustrated-the-definitive-visual-guide-to-pandas-c31fa921a43?sk=50184a8a8b46ffca16664f6529741abc) guide.\n\n## Installation: \n\n    pip install pandas-illustrated\n\n## Contents\n\nBasic operations:\n- `find(s, x, pos=False)`\n- `findall(s, x, pos=False)`\n- `insert(dst, pos, value, label, axis=0, ignore_index = False, \n    order=None, allow_duplicates=False, inplace=False)`\n- `append(dst, value, label = lib.no_default, axis=0, ignore_index = False,\n    order=None, allow_duplicates: bool = False, inplace=False)`\n- `drop(obj, items=None, like=None, regex=None, axis=None)`\n- `move(obj, pos, label=None, column=None, index=None, axis=None, reset_index=False)`\n- `join(dfs, on=None, how=\"left\", suffixes=None)`\n\nVisualization improvements:\n- `patch_series_repr(footer=True)`\n- `unpatch_series_repr()`\n- `sidebyside(*dfs, names=[], index=True, valign=\"top\")`\n- `sbs = sidebyside`\n\nMultiIndex helpers:\n- `patch_mi_co()`\n- `from_dict(d)`\n- `from_kw(**kwargs)`\n\nLocking columns order:\n- `locked(obj, level=None, axis=None, categories=None, inplace=False)`\n- `lock = locked with inplace=True`\n- `vis_lock(obj, checkmark=\"✓\")`\n- `vis_patch()`\n- `vis_unpatch()`\n- `from_product(iterables, sortorder=None, names=lib.no_default, lock=True)`\n\nMultiIndex manipulations:\n- `get_level(obj, level_id, axis=None)`\n- `set_level(obj, level_id, labels, name=lib.no_default, axis=None, inplace=False)`\n- `move_level(obj, src, dst, axis=None, inplace=False, sort=False)`\n- `insert_level(obj, pos, labels, name=lib.no_default, axis=None, inplace=False, sort=False)`\n- `drop_level(obj, level_id, axis=None, inplace=False)`\n- `swap_levels(obj, i: Axis = -2, j: Axis = -1, axis: Axis = None, inplace=False, sort=False)`\n- `join_levels(obj, name=None, sep=\"_\", axis=None, inplace=False)`\n- `split_level(obj, names=None, sep=\"_\", axis=None, inplace=False)`\n- `rename_level(obj, mapping, level_id=None, axis=None, inplace=False)`\n\n\n## Usage\n\n### find and findall\n\nBy default `find(series, value)` looks for the first occurrence of the given *value* in a *series* and returns the corresponsing index label.\n\n```python\n\u003e\u003e\u003e import pandas as pd\n\u003e\u003e\u003e import pdi\n\n\u003e\u003e\u003e s = pd.Series([4, 2, 4, 6], index=['cat', 'penguin', 'dog', 'butterfly'])\n\n\u003e\u003e\u003e pdi.find(s, 2)\n'penguin' \n\n\u003e\u003e\u003e pdi.find(s, 4)\n'cat' \n```\n\nWhen the value is not found raises a `ValueError`.\n\n`findall(series, value)` returns a (possibly empty) index of all matching occurrences:\n\n```python\n\u003e\u003e\u003e pdi.findall(s, 4)\nIndex(['cat', 'dog'], dtype='object')\n```\n\nWith `pos=True` keyword argument `find()` and `findall()` return the positional index instead:\n\n```python\n\u003e\u003e\u003e pdi.find(s, 2, pos=True)\n1 \n\n\u003e\u003e\u003e pdi.find(s, 4, pos=True)\n0\n```\nThere is a number of ways to find index label for a given value. The most efficient of them are:\n\n```python\n— s.index[s.tolist().index(x)]       # faster for Series with less than 1000 elements\n— s.index[np.where(s == x)[0][0]]    # faster for Series with over 1000 elements  \n```\n\n\u003cimg src=\"https://user-images.githubusercontent.com/170910/209191163-52b8cc6a-425d-41e0-a7f9-c2efb4a31bbb.png\" width=\"600\"\u003e\n\n`find()` chooses optimal implementation depending on the series size; `findall()` always uses the `where` implementation.\n\n### Improving Series Representation\n\nRun `pdi.patch_series_repr()` to make Series look better:\n\n\u003cimg src=\"https://user-images.githubusercontent.com/170910/211085821-544b42b0-561a-47e7-8f32-6f31a05ed978.png\" width=\"600\"\u003e\n\nIf you want to display several Series from one cell, call `display(s)` for each.\n\n### Displaying several Pandas objects side vy side\n\nTo display several dataframes, series or indices side by side run `pdi.sidebyside(s1, s2, ...)`\n\n\u003cimg src=\"img/sbs.png\" width=\"450\"/\u003e\n\n## Testing\n\nRun `pytest` in the project root.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxil%2Fpandas-illustrated","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faxil%2Fpandas-illustrated","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxil%2Fpandas-illustrated/lists"}