Querying the Pandas DataFrame

  • Comments posted to this topic are about the item Querying the Pandas DataFrame

  • 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

  • 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 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply