п»ї# pandas-illustrated
[![pypi](https://img.shields.io/pypi/v/pandas-illustrated.svg)](https://pypi.python.org/pypi/pandas-illustrated)
[![python](https://img.shields.io/pypi/pyversions/pandas-illustrated.svg)](https://pypi.org/project/pandas-illustrated/)
![pytest](https://github.com/axil/pandas-illustrated/actions/workflows/python-package.yml/badge.svg)
![Coverage Badge](img/coverage.svg)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![License](https://img.shields.io/pypi/l/pandas-illustrated)](https://pypi.org/project/pandas-illustrated/)
This 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.
## Installation:
pip install pandas-illustrated
## Contents
Basic operations:
- `find(s, x, pos=False)`
- `findall(s, x, pos=False)`
- `insert(dst, pos, value, label, axis=0, ignore_index = False,
order=None, allow_duplicates=False, inplace=False)`
- `append(dst, value, label = lib.no_default, axis=0, ignore_index = False,
order=None, allow_duplicates: bool = False, inplace=False)`
- `drop(obj, items=None, like=None, regex=None, axis=None)`
- `move(obj, pos, label=None, column=None, index=None, axis=None, reset_index=False)`
- `join(dfs, on=None, how="left", suffixes=None)`
Visualization improvements:
- `patch_series_repr(footer=True)`
- `unpatch_series_repr()`
- `sidebyside(*dfs, names=[], index=True, valign="top")`
- `sbs = sidebyside`
MultiIndex helpers:
- `patch_mi_co()`
- `from_dict(d)`
- `from_kw(**kwargs)`
Locking columns order:
- `locked(obj, level=None, axis=None, categories=None, inplace=False)`
- `lock = locked with inplace=True`
- `vis_lock(obj, checkmark="вњ“")`
- `vis_patch()`
- `vis_unpatch()`
- `from_product(iterables, sortorder=None, names=lib.no_default, lock=True)`
MultiIndex manipulations:
- `get_level(obj, level_id, axis=None)`
- `set_level(obj, level_id, labels, name=lib.no_default, axis=None, inplace=False)`
- `move_level(obj, src, dst, axis=None, inplace=False, sort=False)`
- `insert_level(obj, pos, labels, name=lib.no_default, axis=None, inplace=False, sort=False)`
- `drop_level(obj, level_id, axis=None, inplace=False)`
- `swap_levels(obj, i: Axis = -2, j: Axis = -1, axis: Axis = None, inplace=False, sort=False)`
- `join_levels(obj, name=None, sep="_", axis=None, inplace=False)`
- `split_level(obj, names=None, sep="_", axis=None, inplace=False)`
- `rename_level(obj, mapping, level_id=None, axis=None, inplace=False)`
## Usage
### find and findall
By default `find(series, value)` looks for the first occurrence of the given *value* in a *series* and returns the corresponsing index label.
```python
>>> import pandas as pd
>>> import pdi
>>> s = pd.Series([4, 2, 4, 6], index=['cat', 'penguin', 'dog', 'butterfly'])
>>> pdi.find(s, 2)
'penguin'
>>> pdi.find(s, 4)
'cat'
```
When the value is not found raises a `ValueError`.
`findall(series, value)` returns a (possibly empty) index of all matching occurrences:
```python
>>> pdi.findall(s, 4)
Index(['cat', 'dog'], dtype='object')
```
With `pos=True` keyword argument `find()` and `findall()` return the positional index instead:
```python
>>> pdi.find(s, 2, pos=True)
1
>>> pdi.find(s, 4, pos=True)
0
```
There is a number of ways to find index label for a given value. The most efficient of them are:
```python
— s.index[s.tolist().index(x)] # faster for Series with less than 1000 elements
— s.index[np.where(s == x)[0][0]] # faster for Series with over 1000 elements
```
<img src="https://user-images.githubusercontent.com/170910/209191163-52b8cc6a-425d-41e0-a7f9-c2efb4a31bbb.png" width="600">
`find()` chooses optimal implementation depending on the series size; `findall()` always uses the `where` implementation.
### Improving Series Representation
Run `pdi.patch_series_repr()` to make Series look better:
<img src="https://user-images.githubusercontent.com/170910/211085821-544b42b0-561a-47e7-8f32-6f31a05ed978.png" width="600">
If you want to display several Series from one cell, call `display(s)` for each.
### Displaying several Pandas objects side vy side
To display several dataframes, series or indices side by side run `pdi.sidebyside(s1, s2, ...)`
<img src="img/sbs.png" width="450"/>
## Testing
Run `pytest` in the project root.
Raw data
{
"_id": null,
"home_page": "https://github.com/axil/pandas-illustrated",
"name": "pandas-illustrated",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "find,findall,insert,drop,levels,sidebyside,pandas",
"author": "Lev Maximov",
"author_email": "lev.maximov@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/fe/02/b1b2fe9c4238f487e042fad29acba8e6da7cb468edb96b726701289b3318/pandas-illustrated-0.6.tar.gz",
"platform": null,
"description": "\u043f\u00bb\u0457# pandas-illustrated\r\n\r\n[![pypi](https://img.shields.io/pypi/v/pandas-illustrated.svg)](https://pypi.python.org/pypi/pandas-illustrated)\r\n[![python](https://img.shields.io/pypi/pyversions/pandas-illustrated.svg)](https://pypi.org/project/pandas-illustrated/)\r\n![pytest](https://github.com/axil/pandas-illustrated/actions/workflows/python-package.yml/badge.svg)\r\n![Coverage Badge](img/coverage.svg)\r\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\r\n[![License](https://img.shields.io/pypi/l/pandas-illustrated)](https://pypi.org/project/pandas-illustrated/)\r\n\r\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.\r\n\r\n## Installation: \r\n\r\n pip install pandas-illustrated\r\n\r\n## Contents\r\n\r\nBasic operations:\r\n- `find(s, x, pos=False)`\r\n- `findall(s, x, pos=False)`\r\n- `insert(dst, pos, value, label, axis=0, ignore_index = False, \r\n order=None, allow_duplicates=False, inplace=False)`\r\n- `append(dst, value, label = lib.no_default, axis=0, ignore_index = False,\r\n order=None, allow_duplicates: bool = False, inplace=False)`\r\n- `drop(obj, items=None, like=None, regex=None, axis=None)`\r\n- `move(obj, pos, label=None, column=None, index=None, axis=None, reset_index=False)`\r\n- `join(dfs, on=None, how=\"left\", suffixes=None)`\r\n\r\nVisualization improvements:\r\n- `patch_series_repr(footer=True)`\r\n- `unpatch_series_repr()`\r\n- `sidebyside(*dfs, names=[], index=True, valign=\"top\")`\r\n- `sbs = sidebyside`\r\n\r\nMultiIndex helpers:\r\n- `patch_mi_co()`\r\n- `from_dict(d)`\r\n- `from_kw(**kwargs)`\r\n\r\nLocking columns order:\r\n- `locked(obj, level=None, axis=None, categories=None, inplace=False)`\r\n- `lock = locked with inplace=True`\r\n- `vis_lock(obj, checkmark=\"\u0432\u045a\u201c\")`\r\n- `vis_patch()`\r\n- `vis_unpatch()`\r\n- `from_product(iterables, sortorder=None, names=lib.no_default, lock=True)`\r\n\r\nMultiIndex manipulations:\r\n- `get_level(obj, level_id, axis=None)`\r\n- `set_level(obj, level_id, labels, name=lib.no_default, axis=None, inplace=False)`\r\n- `move_level(obj, src, dst, axis=None, inplace=False, sort=False)`\r\n- `insert_level(obj, pos, labels, name=lib.no_default, axis=None, inplace=False, sort=False)`\r\n- `drop_level(obj, level_id, axis=None, inplace=False)`\r\n- `swap_levels(obj, i: Axis = -2, j: Axis = -1, axis: Axis = None, inplace=False, sort=False)`\r\n- `join_levels(obj, name=None, sep=\"_\", axis=None, inplace=False)`\r\n- `split_level(obj, names=None, sep=\"_\", axis=None, inplace=False)`\r\n- `rename_level(obj, mapping, level_id=None, axis=None, inplace=False)`\r\n\r\n\r\n## Usage\r\n\r\n### find and findall\r\n\r\nBy default `find(series, value)` looks for the first occurrence of the given *value* in a *series* and returns the corresponsing index label.\r\n\r\n```python\r\n>>> import pandas as pd\r\n>>> import pdi\r\n\r\n>>> s = pd.Series([4, 2, 4, 6], index=['cat', 'penguin', 'dog', 'butterfly'])\r\n\r\n>>> pdi.find(s, 2)\r\n'penguin' \r\n\r\n>>> pdi.find(s, 4)\r\n'cat' \r\n```\r\n\r\nWhen the value is not found raises a `ValueError`.\r\n\r\n`findall(series, value)` returns a (possibly empty) index of all matching occurrences:\r\n\r\n```python\r\n>>> pdi.findall(s, 4)\r\nIndex(['cat', 'dog'], dtype='object')\r\n```\r\n\r\nWith `pos=True` keyword argument `find()` and `findall()` return the positional index instead:\r\n\r\n```python\r\n>>> pdi.find(s, 2, pos=True)\r\n1 \r\n\r\n>>> pdi.find(s, 4, pos=True)\r\n0\r\n```\r\nThere is a number of ways to find index label for a given value. The most efficient of them are:\r\n\r\n```python\r\n\u0432\u0402\u201d s.index[s.tolist().index(x)] # faster for Series with less than 1000 elements\r\n\u0432\u0402\u201d s.index[np.where(s == x)[0][0]] # faster for Series with over 1000 elements \r\n```\r\n\r\n<img src=\"https://user-images.githubusercontent.com/170910/209191163-52b8cc6a-425d-41e0-a7f9-c2efb4a31bbb.png\" width=\"600\">\r\n\r\n`find()` chooses optimal implementation depending on the series size; `findall()` always uses the `where` implementation.\r\n\r\n### Improving Series Representation\r\n\r\nRun `pdi.patch_series_repr()` to make Series look better:\r\n\r\n<img src=\"https://user-images.githubusercontent.com/170910/211085821-544b42b0-561a-47e7-8f32-6f31a05ed978.png\" width=\"600\">\r\n\r\nIf you want to display several Series from one cell, call `display(s)` for each.\r\n\r\n### Displaying several Pandas objects side vy side\r\n\r\nTo display several dataframes, series or indices side by side run `pdi.sidebyside(s1, s2, ...)`\r\n\r\n<img src=\"img/sbs.png\" width=\"450\"/>\r\n\r\n## Testing\r\n\r\nRun `pytest` in the project root.\r\n\r\n\r\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Helper functions from the Pandas Illustrated guide",
"version": "0.6",
"split_keywords": [
"find",
"findall",
"insert",
"drop",
"levels",
"sidebyside",
"pandas"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "acf516f466f2ec822785a540ed64b8ca4f5090cf58c05a1173405a909b96a4a6",
"md5": "cbc94c56bf3f5b01c10597f02f8ab908",
"sha256": "353d56485986a6e77f6b69382ce985513245ae13ec9b967e2a38d3c28fa9a81e"
},
"downloads": -1,
"filename": "pandas_illustrated-0.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "cbc94c56bf3f5b01c10597f02f8ab908",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 18262,
"upload_time": "2023-03-26T14:35:35",
"upload_time_iso_8601": "2023-03-26T14:35:35.811663Z",
"url": "https://files.pythonhosted.org/packages/ac/f5/16f466f2ec822785a540ed64b8ca4f5090cf58c05a1173405a909b96a4a6/pandas_illustrated-0.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "fe02b1b2fe9c4238f487e042fad29acba8e6da7cb468edb96b726701289b3318",
"md5": "c44f750b00110c5224855d514048e856",
"sha256": "cae78b65d513ef5c2c3533981ead204ed249d27ee513b4a44cb76ebb9c434847"
},
"downloads": -1,
"filename": "pandas-illustrated-0.6.tar.gz",
"has_sig": false,
"md5_digest": "c44f750b00110c5224855d514048e856",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 16814,
"upload_time": "2023-03-26T14:35:37",
"upload_time_iso_8601": "2023-03-26T14:35:37.483018Z",
"url": "https://files.pythonhosted.org/packages/fe/02/b1b2fe9c4238f487e042fad29acba8e6da7cb468edb96b726701289b3318/pandas-illustrated-0.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-03-26 14:35:37",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "axil",
"github_project": "pandas-illustrated",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "pandas-illustrated"
}