TidyBear
A tidier approach to pandas.
This package was originally a collection of functions, routines, and processes that I found myself often repeating. It has since evolved into a desire to work my way through the tidyverse to reimplement my favorite tidy features in python. This project is not aimed at creating a better experience for every pandas task, but rather just a different one that sometimes feels more natural to me. I hope something here can be useful to you.
Installation
pip install tidybear
Usage
import pandas as pd
import tidybear as tb
Verbs
# rename columns
tb.rename(data, old="new")
# select columns
tb.select(data, ["col1", "col2"])
# count number of rows across multiple columns
tb.count(data, ["col1", "col2"])
# pivot long to wide or wide to long
tb.pivot_longer(data, ["val1", "val2"], names_to="val_type")
tb.pivot_wider(data, names_from="val_type", values_from="value")
# slice rows
tb.slice_max(data, order_by="val1", n=10)
tb.slice_min(data, order_by="val1", n=10, groupby="col1")
# join dataframes
tb.left_join(data1, data2, "colA") # use "colA" as key
tb.right_join(data1, data2, col1A="col1B") # use "col1A" from left and "col1B" from right
tb.cross_join(data1, data2)
Groupby and Summarise API
with tb.GroupBy(df, "group_var") as g:
g.n()
g.sum("value", name="total_value")
g.n_distinct("ids", name="n_unique_ids")
summary = g.summarise()
TidySelectors
everything()- Select all columnslast_col- Select last columnfirst_col- Select first columncontains(pattern)- Select columns that contain the literal stringmatches(pattern)- Select columns that match the regular expression patternstarts_with(pattern)- Select columns that start with the literal stringends_with- Select all columns that end with the literal srtingnum_range- Select all columns that match a numeric range like x01, x02, x03
These can be used in a variety of tidybear verbs
from tidybear.selectors import contains, everything
# select all columns that contain "foo"
tb.select(data, contains("foo"))
# pivot all columns to long format
tb.pivot_longer(data, everything())
You can also negate these, so if you wanted everything except one columns, you could do:
from tidybear.selectors import last_col
tb.select(data, -last_col())
Coming Soon (maybe)
- Method chaining
- Tribbles!
Metadata
Release files for tidybear 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tidybear-0.0.5.tar.gz | 10.7 kB | Without provenance | Details for tidybear-0.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tidybear-0.0.5-py3-none-any.whl | Python 3 | none | any | Details for tidybear-0.0.5-py3-none-any.whl |
Total release size: 23.3 kB
Release files / tidybear-0.0.5.tar.gz
| Download URL | tidybear-0.0.5.tar.gz |
|---|---|
| Size | 10.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4c8253abf52bd4e20f20b00db9f88bdb0cb38d44100b991091a7b8be5effd055
|
|
BLAKE2b-256 checksum How to use checksums |
2dd2bf902e59d8d61f89d3cc93a89af19e52306f7b7a99895ac39eac93a9418b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.12
|
Release files / tidybear-0.0.5-py3-none-any.whl
| Download URL | tidybear-0.0.5-py3-none-any.whl |
|---|---|
| Size | 12.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
31943bb152982a32e9bed8f9cccc948d717431c4a45e401b3c8f03c6c2b98026
|
|
BLAKE2b-256 checksum How to use checksums |
013392cb11fd861518553a08f0874812cde52abb531f6dc02e9a42ec4cc05fab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.12
|
Security for tidybear 0.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.