def fl_base(df,file_name): columns = ['historic_odds_1','historic_odds_2','historic_odds_3','historic_odds_4','odds'] mean_cols = df[columns].mean(axis=1) df = df.query( f" (mean_cols > 0) and ((@df['minute_traded']/mean_cols)*100 >= 1000) and (@df['minute_traded'] >= 1000) " ).reset_index(drop=True) return df
name 'mean_cols' is not defined
mean_cols is being created before calling
df.query, why is it saying that it has not defined?
The query documentation states:
You can refer to variables in the environment by prefixing them with an ‘@’ character like @a + b.
mean_cols is your variable and not a
column name in
df = df.query( f" (@mean_cols > 0) and ((minute_traded/@mean_cols)*100 >= 1000) and (minute_traded >= 1000) " ).reset_index(drop=True)
minute_traded is the
mean_cols as stated earlier is the variable.