sample_to_work_on = df.query("'Plaza ID'==5 & Date>'2016-12-30' & Date<'2017-05-01'")
sample_to_work_on.head()
dataframe islike this:
Plaza ID Date Hour Direction # Vehicles - E-ZPass # Vehicles - VToll
0 21 2022-08-06 0 I 2820 649
1 21 2022-08-06 1 I 2124 474
2 21 2022-08-06 2 I 1617 391
3 21 2022-08-06 3 I 1228 358
4 21 2022-08-06 4 I 1604 368
**when i try this statement on query() function on my data it gives me a type error : **
264 try:
--> 265 return x.isin(y)
266 except AttributeError:
AttributeError: 'list' object has no attribute 'isin'
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
Cell In[10], line 1
----> 1 sample_to_work_on = df.query("'Plaza ID'==5 & Date>'2016-12-30' & Date<'2017-05-01'")
3 sample_to_work_on.head()
File c:\Users\eren\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\util\_decorators.py:331, in deprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper(*args, **kwargs)
325 if len(args) > num_allow_args:
326 warnings.warn(
327 msg.format(arguments=_format_argument_list(allow_args)),
328 FutureWarning,
329 stacklevel=find_stack_level(),
330 )
--> 331 return func(*args, **kwargs)
...
270 except AttributeError:
271 pass
--> 272 return x in y
TypeError: argument of type 'int' is not iterable
why is this happening and any idea to prevent this ? my goal is to retrieve data which has plaza id of 5 and that spesific dates in the query
i tried to rewrite statement for 5 times and it gave me the same error there was no problem with date retrieving but plaza id makes it a problem
Since the column name
Plaza IDcontains a whitespace, I suggest you to use the backtick (`).From @World Wide DBA answer on the utility of backsticks in SQL :
Alternatively, use
loc: