3

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 :)

Alex
  • 87
  • 1
  • 1
  • 7

1 Answers1

1

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)
kovashikawa
  • 1,121
  • 9
  • 15