Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the periodicity (if it exists) of a Pandas Time Series?

My question is:

Let's say I have a Pandas Time Series, so Dates as index and a numerical column. I would like to know what is the easiest way to find its periodicity, or an approximation.

Can someone explain to me what the different steps to solve this problem would be?

Thanks in advance for your help,

Alex :)

like image 238
Alex Avatar asked Jan 22 '26 02:01

Alex


1 Answers

It is quite simple actually, not many steps required since pandas already do that for you with pd.infer_freq().

Just a small example in your case we can have somenthing like this:

import pandas as pd
import numpy as np

df = pd.DataFrame({'date': pd.date_range(start='2020-01-01', end='2021-12-31', freq='D'),
                   'number': np.random.uniform(size=731)})

df.set_index(df.date, inplace=True)

pd.infer_freq(df.index)
like image 117
kovashikawa Avatar answered Jan 23 '26 20:01

kovashikawa