PyTrendy
Welcome
PyTrendy is a robust solution for identifying and analyzing trends in time series. Unlike other packages, it detects uptrends and downtrends in a way that they are not falsely detected over periods of flat or noise segments.
It is a thoughtful algorithm with a focus on signal processing and post-processing. It aims to be the best package for trend detection in Python.
Why PyTrendy?
Trend detection has several use cases, such as analysing stock prices for investing, identifying demand trends in seasonality patterns to optimise inventory management, analysing google trends at scale for emerging movements in industries, and more.
However, one main use case is for identifying different periods of marketing activity at scale - to help with observationally measuring the effectiveness of digital marketing.
- By applying it to digital marketing spend by day (treatment), it can identify valid treatment (uptrends/downtrends) & placebo (flat) periods for observational causal inference.
- By applying to the response of an experiment design, it can also be used to identify periods of noise (such as sales promotions) to mitigate the risks of misleading indications.
Features

Installation
Install the package from PyPi.
pip install pytrendy
Alternatively, if you want the latest pre-release
pip install --pre pytrendy
Quickstart
Import pytrendy, and apply trend detection on daily time series data.
import pytrendy as pt
df = pt.load_data('series_synthetic')
results = pt.detect_trends(df, date_col='date', value_col='gradual', plot=True)
results.print_summary()
Detected:
- 3 Uptrends.
- 3 Downtrends.
- 3 Flats.
- 0 Noise.
The best detected trend is Down between dates 2025-05-09 - 2025-06-17
Full Results:
-------------------------------------------------------------------------------
direction start end days total_change change_rank
time_index
1 Up 2025-01-02 2025-01-24 22 14.013348 5
2 Down 2025-01-25 2025-02-05 11 -13.564214 6
3 Flat 2025-02-06 2025-02-09 3 NaN 7
4 Up 2025-02-10 2025-03-14 32 24.632035 3
5 Flat 2025-03-15 2025-03-17 2 NaN 8
6 Down 2025-03-18 2025-04-01 14 -22.721861 4
7 Up 2025-04-02 2025-05-08 36 72.611833 2
8 Down 2025-05-09 2025-06-17 39 -73.253968 1
9 Flat 2025-06-18 2025-06-30 12 NaN 9
-------------------------------------------------------------------------------
More information on how you can interpret the trend detection results are available in the Example Gallery.