A tidier approach to pandas
Project description
TidyBear
A tidy approach to pandas.
Groupby and Summarise
import numpy as np
import pandas as pd
import tidybear as tb
df = pd.DataFrame({
"gr": list("AAABBBB"),
"x": [1, 2, 3, 7, 8, 8, 9],
"y": [4, 5, 6, 1, 1, 1, 1],
"z": [2, 4, 6, 0, 1, 2, 2]
})
with tb.GroupBy(df, "gr") as g:
# built in statistcs
g.n()
g.sum("x", decimals=3)
# multiple aggs to a single column
g.agg("x", ["mean", "median"], decimals=3)
# same agg across multiple columns using built in
g.mean(["y", "z"], decimals=3)
# multiple aggs across multiple columns
g.agg(["y", "z"], ["median", "std"], decimals=1)
# send a lambda function to agg
g.agg("x", lambda x: len(x.unique()), name="n_distinct_x1")
# Use 'temp' keyword to return series and use it later
max_val = g.max("x", temp=True)
min_val = g.min("x", temp=True)
# create a custom stat directly
g.stat("midpoint", (max_val + min_val) / 2)
summary = g.summarise()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tidybear-0.0.2.tar.gz
(4.5 kB
view details)
Built Distribution
File details
Details for the file tidybear-0.0.2.tar.gz
.
File metadata
- Download URL: tidybear-0.0.2.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a58440a021a1be212f3a2bbc60bb98bc731bc1b7fc9b2eaa2ba94fdf09c45f3 |
|
MD5 | 2e27e378cefdda34e9f42fa30699180c |
|
BLAKE2b-256 | 203c2f1ba91c8c95099cf806b9ad2a034b7cf0235bab2743278f8dc467754a54 |
File details
Details for the file tidybear-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: tidybear-0.0.2-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e54c83c442431ba77d086cb0011b017b21b0d4748f747d1bd5cd6c8ea839694 |
|
MD5 | 453e78e3f8951d67f251370bc6f25766 |
|
BLAKE2b-256 | 8b8bc0a891e76990e3d3645643d018e8ba2ef93b340f9879c4ec6f7c77b112d0 |