[Python] Grouping data by specific years in python

Discussão em 'Python' iniciado por Stack, Julho 13, 2025.

  1. Stack

    Stack Membro Participativo

    I want to create a dataframe that is grouped by region and date which shows the average age of a region during specific years. so my columns would look something like

    region, year, average age


    So far I have:

    # specify aggregation functions to column 'age'
    ageAverage = {'age':{'average age':'mean'}}

    # groupby and apply functions
    ageDataFrame = data.groupby(['Region', data.Date.dt.year]).agg(ageAverage)


    This works great, but how can I make it so that I only group data from specific years? say for example between 2010 and 2015?

    Continue reading...

Compartilhe esta Página