0
df.query('ZIP_(3-DIGIT) < 100')

returns:

ValueError: "ZIP_" is not a supported function

df.query('@ZIP_(3-DIGIT) < 100')

returns:

ValueError: "__pd_eval_local_ZIP_" is not a supported function

ZIP_(3-DIGIT) is int64

I can use df[df['ZIP_(3-DIGIT)'] < 100] to achieve the desired result, but I would like to learn what I was doing wrong.

df = pd.DataFrame({'ZIP_(3-DIGIT)': np.arange(0,10000)})
1
  • 200k rows by 25 columns Commented Sep 7, 2017 at 20:58

1 Answer 1

2

The issue is with the parentheses and hyphen in your column name.

Any column that you couldn't access with df + tab also can't be parsed by .query. I don't know pandas internals and can't answer your question beyond that level of depth.

For example if you had:

df = pd.DataFrame({'ZIP_3DIGIT': np.arange(0,10000)})

You could do:

print(df.ZIP_3DIGIT.head(3))
0    0
1    1
2    2
Name: ZIP_3DIGIT, dtype: int32

Now try this with your current name and things will not work.

So to use query, use rename and method chain query to that:

df.rename(columns={'ZIP_(3-DIGIT)' : 'ZIP_3DIGIT'}).query('ZIP_3DIGIT < 100')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.