Skip to content Skip to sidebar Skip to footer

Conditional Mean By Rolling

Data flag 2017-01-01 17.2 False 2017-01-02 17.0 False 2017-01-03 16.8 False 2017-01-04 18.3

Solution 1:

You can use pandas.rolling_mean() while subsetting the dataframe to only include entries where df.flag is false (the ~ operator inverts the truth of the boolean series, getting all values where df.flag is False).

pandas.rolling_mean(df[~df.flag], window=30)

Post a Comment for "Conditional Mean By Rolling"