|
1 | | -# % Percentify % |
2 | | -[](https://pepy.tech/projects/percentify) |
| 1 | + |
| 2 | +<p align="center"> |
| 3 | + <img src="asset/Logo.png" alt="Percentify logo" height="52"> |
| 4 | +</p> |
| 5 | + |
| 6 | +[](https://pepy.tech/project/percentify) |
3 | 7 | [](https://pypi.org/project/percentify/) |
4 | 8 | [](https://pypi.org/project/percentify/) |
5 | 9 | [](LICENSE) |
| 10 | +[](https://data-centt.github.io/percentify/) |
6 | 11 | [](https://github.com/data-centt/percentify/actions/workflows/python-app.yml) |
7 | 12 |
|
8 | | -**Percentify** is a Python helper that turns *"part of a whole"* into a clean percentage. |
9 | | -Stop typing `(part / whole) * 100` and worrying about division by zero. |
10 | | - |
11 | | ---- |
12 | | - |
13 | | -## ✨ What It Does |
14 | | - |
15 | | -A zero-dependency Python toolkit for all things percentages: |
| 13 | +**Percentify is a data science library that turns the 20% of data science operations behind 80% of daily work into single, readable function calls.** |
16 | 14 |
|
17 | 15 |
|
18 | | -- **`percent`** — what percentage is `part` of `whole`? |
19 | | -- **`percent_change`** — how much did a value increase or decrease? |
20 | | -- **`percent_diff`** — how far apart are two values? |
21 | | -- **`percent_distribute`** — split a total into weighted shares. |
22 | | -- **`percent_format`** — turn any number into a clean `"25.0%"` string. |
| 16 | +Built on pandas and numpy, it pairs everyday hard to reach tools with lesser-known ones. Where a function wraps an existing library (pandas, scipy, statsmodels, scikit-learn), it names it, so you always know where to dig deeper. |
23 | 17 |
|
24 | | -All functions handle edge cases (division by zero, negative values) safely and let you control decimal precision. |
25 | | -======= |
26 | | -- Calculates what percentage one number is of another. |
27 | | -- Handles divide-by-zero safely (returns 0.0 instead of crashing). |
28 | | -- Lets you choose how many decimal places you want to round your answer to. |
29 | | -- Has zero dependencies — just pure Python. |
| 18 | +## 📖 Documentation |
30 | 19 |
|
| 20 | +**Full guide, every function, and live examples → [data-centt.github.io/percentify](https://data-centt.github.io/percentify/)** |
31 | 21 |
|
32 | 22 | ## 📦 Installation |
33 | | -``` |
| 23 | + |
| 24 | +```bash |
34 | 25 | pip install percentify |
35 | 26 | ``` |
36 | 27 |
|
37 | | -## Usage |
| 28 | +Requires `numpy` and `pandas`. |
38 | 29 |
|
39 | | -### `percent` — Part of a Whole |
40 | | -```python |
41 | | -from percentify import percent |
| 30 | +## Quick example |
42 | 31 |
|
43 | | -percent(50, 200) # → 25.0 |
44 | | -percent(1, 3) # → 33.33 |
45 | | -percent(5, 0) # → 0.0 (safe division by zero) |
46 | | -percent(7, 9, 4) # → 77.7778 (custom decimals) |
| 32 | +```python |
| 33 | +import pandas as pd |
| 34 | +from percentify import missing |
| 35 | + |
| 36 | +df = pd.DataFrame({ |
| 37 | + "salary": [50000, None, 60000, None], |
| 38 | + "age": [25, 30, None, 40], |
| 39 | + "city": ["NY", "LA", "SF", "LA"], |
| 40 | +}) |
| 41 | + |
| 42 | +missing(df) |
| 43 | +# column missing_pct |
| 44 | +# 0 salary 50.0 |
| 45 | +# 1 age 25.0 |
| 46 | +# 2 city 0.0 |
47 | 47 | ``` |
48 | 48 |
|
49 | | -### `percent_change` — Increase or Decrease |
50 | | -```python |
51 | | -from percentify import percent_change |
| 49 | +One import, one line. A clean, sorted DataFrame you can read or feed into the next step. |
52 | 50 |
|
53 | | -percent_change(100, 150) # → 50.0 (50% increase) |
54 | | -percent_change(200, 150) # → -25.0 (25% decrease) |
55 | | -percent_change(0, 100) # → 0.0 (safe when old is zero) |
56 | | -``` |
| 51 | +## What's inside |
57 | 52 |
|
58 | | -### `percent_diff` — Difference Between Two Values |
59 | | -```python |
60 | | -from percentify import percent_diff |
| 53 | +| Function | What it answers | |
| 54 | +|---|---| |
| 55 | +| `change` | Growth as numbers, columns, or a whole series | |
| 56 | +| `vif` | Which features are collinear? | |
| 57 | +| `missing` | How much of each column is missing? | |
| 58 | +| `cv` | How variable is each column, relative to its mean? | |
| 59 | +| `outliers` | What percentage of each column are outliers? | |
| 60 | +| `r_squared` | How well do predictions fit? | |
| 61 | +| `pca_variance` | How much variance does each principal component explain? | |
| 62 | +| `difference` | How far apart are two values or columns? | |
| 63 | +| `split` | How does a total divide across weights or groups? | |
| 64 | +| `display` | Format numbers or a column as clean "%" strings | |
61 | 65 |
|
62 | | -percent_diff(10, 20) # → 66.67 |
63 | | -percent_diff(50, 50) # → 0.0 |
64 | | -``` |
| 66 | +→ See the **[documentation](https://data-centt.github.io/percentify/)** for a worked, real-output example of every function. |
65 | 67 |
|
66 | | -### `percent_distribute` — Split a Total by Weights |
67 | | -```python |
68 | | -from percentify import percent_distribute |
| 68 | +## 🛟 Friendly by design |
69 | 69 |
|
70 | | -percent_distribute(200, [1, 3]) # → [50.0, 150.0] |
71 | | -percent_distribute(100, [1, 1, 1]) # → [33.33, 33.33, 33.33] |
72 | | -``` |
| 70 | +- **No cryptic tracebacks**; Hand a function a text column where numbers are needed and you get a clear PercentifyWarning, not an Arrow/NumPy stack trace. |
| 71 | +- **Sensible defaults**; Results come back sorted worst-first, and PCA is standardized out of the box. |
| 72 | +- **DataFrames everywhere**; so the output drops straight into your notebook, your next filter, or your model. |
73 | 73 |
|
74 | | -### `percent_format` — Format as a String |
75 | | -```python |
76 | | -from percentify import percent_format |
77 | 74 |
|
78 | | -percent_format(25.0) # → "25.0%" |
79 | | -percent_format(33.3333, 1) # → "33.3%" |
80 | | -percent_format(50, suffix=" percent") # → "50.0 percent" |
81 | | -``` |
| 75 | +## 🤝 Contributing |
82 | 76 |
|
83 | | -# 🤝 Contributing |
| 77 | +Contributions are welcome but they must follow the repo's guiding principle: |
| 78 | +> Keep each method as direct-to-output as possible. A percentify function should return the single most common answer in one line, and point users to the underlying library (pandas, scipy, statsmodels, scikit-learn) for the full, configurable version when the simplest output isn't what they're after. |
84 | 79 |
|
85 | | -Contributions are welcome! |
86 | | -- If you have an idea (extra helpers, bug fixes or an idea): |
87 | | -- Fork this repo |
| 80 | +If your idea keeps things that simple and direct: |
| 81 | +- Open an issue first to discuss it |
| 82 | +- Fork the repo |
88 | 83 | - Create a branch |
89 | 84 | - Commit your changes |
90 | 85 | - Open a pull request |
91 | 86 |
|
| 87 | +> Anything that adds knobs and options for their own sake, or duplicates what the parent libraries already do well, is out of scope; those cases should point to the source library instead. |
92 | 88 | I try to keep it compact on purpose, to discuss big new features first. |
0 commit comments