Skip to main content

Lowess Grouped

Apply groupwise lowess smoothing to a dataframe.

Smooth data for each category using the lowess (aka loess) algorithm. You can use this code for all forms of data that should be smoothed independently by group:

lowess-grouped-example Figure 1: Smoothed temperature data for each region

Usage

Install the package (Python 3.8 or higher):

pip install lowess-grouped

Import the package and call the function lowess_grouped with your dataframe df. Use the parameter frac to control the strength of the smoothing:

from lowess_grouped.lowess_grouped import lowess_grouped

df_smoothed = lowess_grouped(df, 
                             x_name="year", 
                             y_name="temperature_anomaly",
                             group_name="region_name", 
                             frac=0.05)

For a detailed example, refer to the notebook temperature-example.ipynb.

Testcases

Tests are defined in the folder tests. To run them manually, follow these steps:

  1. Download the source code from GitHub.

  2. Install package locally by executing the following command in the project folder:

    pip install -e .
    

    You might need to upgrade your version of pip for this to work:

    pip install --upgrade pip
    
  3. Run the tests:

    python ./tests/test_lowess_grouped.py -v
    

Motivation

Smoothing data can greatly improve the interpretability of visualizations. One commonly used method is lowess, also knows as loess, sometimes also referred as Savitzky–Golay filter.

However, the built-in lowess function in Statsmodels (a popular statistics package) applies smoothing to the entire dataframe. This can lead to undesirable results when you need independent smoothing for multiple groups (e.g., temperature data by regions).

This package was developed to address this limitation and provide some convenience, like getting a dataframe with column names back, instead of unnamed numpy arrays. Internally it still uses Statsmodels.

Attribution

This project builds upon the lowess function from statsmodels. The temperature data used in the example notebook and testcases is from Berkley Earth, and licensed under Creative Commons BY-NC 4.0 International.

Metadata

Release files for lowess-grouped 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lowess-grouped 0.0.7
File Size Uploaded
lowess_grouped-0.0.7.tar.gz 423.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lowess-grouped 0.0.7
File Interpreter ABI Platform
lowess_grouped-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 428.9 kB

Release files / lowess_grouped-0.0.7.tar.gz

Download URL lowess_grouped-0.0.7.tar.gz
Size 423.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4e66b95b1843a7779fc179525cc9906f61a20c5e7b3591cb36ef6e345cecdbc1
BLAKE2b-256 checksum
How to use checksums
1dcc888f93ddaf7db7c2a39b3f7388607c66d2427278498640a0892fb7c95c8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / lowess_grouped-0.0.7-py3-none-any.whl

Download URL lowess_grouped-0.0.7-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
55c4ab9ab14217d6050ad501ac337eb67b27e8a8c488af34f6e46cf2a8c6deba
BLAKE2b-256 checksum
How to use checksums
40304ef124e06dbd47acdf44fc277cb94923f3104f0a38f765bfe88db5095c7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page