Issue
I'm trying to query a Pandas dataframe like this:
inv = pd.read_csv(infile)
inv.columns = ['County', 'Site', 'Role', 'Hostname']
clist = inv.County.unique() # Get list of counties
for county in clist: # for each county
csub = inv.query('County == county') # create a county subset
# ... do stuff on subset
But I get an error:
pandas.core.computation.ops.UndefinedVariableError: name 'county' is not defined
I'm sure it's a trivial error, but I can't figure it out. How do I pass a variable to the query method?
Solution
According to the documentation, you can reference variables using @
:
csub = inv.query('County == @county')
Answered By - Philip Ciunkiewicz
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.