[Python] Grouping Time-series Data Interannual

Discussão em 'Python' iniciado por Stack, Abril 17, 2025.

  1. Stack

    Stack Membro Participativo

    I've been using groupby() for a bit but am running into a problem with grouping inter-annual (i.e., spanning two or more years).

    I've got a simple dataframe that I want to group by 365D intervals beginning from a specific start date.

    date data
    2018-03-14 0.000000
    2018-03-15 0.000000
    2018-03-16 0.000006
    2018-03-19 -0.000469
    2018-03-20 -0.001312
    ... ...
    2025-04-10 0.082415
    2025-04-11 0.002901
    2025-04-14 0.005738
    2025-04-15 0.007664
    2025-04-16 0.012883
    1848 rows × 1 columns


    I'm assuming it can be solved with pd.Grouper or pd.TimeGrouper but am having trouble sorting it out.

    I'm familiar using pd.date_range(start, end, freq=DateOffset(days=365)), but I can't make my way back using pd.Grouper.

    Python 3.11.12

    Continue reading...

Compartilhe esta Página