March 24, 2021 at 12:00 am
Comments posted to this topic are about the item Querying the Pandas DataFrame
March 24, 2021 at 5:09 am
Sorry to bump in but is there any reason that speaks against or for using either of these options over the other?
print(df.query('Grade >= 73'))
print(df[df['Grade'] >= 73])
I want to be the very best
Like no one ever was
March 25, 2021 at 1:41 am
To be honest, I'm not really sure if there is a performance difference. The query method tends to be simpler and easier to read for many folks, but I think it comes down to a matter of opinion and personal preference.
At one point in time, before Pandas 0.25, column names that contained spaces couldn't be used with the query method, so this might have been considered a disadvantage. We can now escape them by using backticks.
I did find this link from one of the Pandas developers talking about this very topic.
https://github.com/pandas-dev/pandas/issues/6508#issuecomment-283181667
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply