[Python] For each NAME, calculate the average SNOW for each month

Discussão em 'Python' iniciado por Stack, Setembro 9, 2025.

  1. Stack

    Stack Membro Participativo

    import pandas as pd
    import numpy as np

    # Show the specified columns and save it to a new file
    col_list= ["STATION", "NAME", "DATE", "AWND", "SNOW"]
    df = pd.read_csv('Data.csv', usecols=col_list)
    df.to_csv('filteredData.csv')

    df['year'] = pd.DatetimeIndex(df['DATE']).year

    df2016 = df[(df.year==2016)]

    df_2016 = df2016.groupby(['NAME', 'DATE'])['SNOW'].mean()
    df_2016.to_csv('average2016.csv')


    [​IMG]


    1. How come my dates are not ordered correctly here? Row 12 should be on the top but it's on the bottom of May instead and same goes for row 25


    2. The average of SNOW per NAME/month is also not being displayed on my excel sheet. Why is that? Basically, I'm trying to calculate the average SNOW for May in ADA 0.7 SE, MI US. Then calculate the average SNOW for June in ADA 0.7 SE, MI US. etc..

    I've spent all day and this is all I have got... Any help will be appreciated. Thanks in advance.

    original data https://gofile.io/?c=1gpbyT

    Continue reading...

Compartilhe esta Página