1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Rolling average for forward values keeps breaking

Discussão em 'Python' iniciado por Stack, Setembro 11, 2024.

  1. Stack

    Stack Membro Participativo

    dataset sample: https://pastebin.com/DeLhAsKL

    if df['Actual_v_Predicted'] == "Predicted", it is meant to do a rolling mean average of the last 7 values and forward fill the ratio column, however, this keeps breaking after reaching 01/07/2025.

    the way I've done this atm is

    df['ratio'] = np.where(df['Actual_v_Predicted'] == "Predicted", np.nan,df['ratio'] )
    df['ratio'] = df['ratio'].fillna(df['ratio'].rolling(window=7, min_periods=1).mean())


    I'm not sure why its breaking, but any help would be appreciated.

    Continue reading...

Compartilhe esta Página