'Refactoring DataFrame "query" condition so it can use a dataframe in the condition itself
I'm trying to understand more about the limitations of "query" condition of a DataFrame, and how to workaround them
so without using "query" I have this
df[df['diff'] <= pd.Timedelta(days=7)]['user_id'].unique()
I can refactor to code to use the "query" operator if I put each value in its own variable. Wondering if "query" itself can be used in another way, without put everything into a variable
diff=df['diff']
timediff=pd.Timedelta(days=7)
df=df.query("@diff <=@timediff")['user_id'].unique()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|