Find answers from the community

Updated 6 months ago

Pandas

At a glance

The community member is using subquestion query with pandasquery and is encountering an error when the query is "What date is today?". The generated code is returning an error because the datetime module is not being imported. The community member has already imported datetime in the main code, but it is not being recognized in the subquestion query. Another community member suggests that if the datetime module is imported before running the query, it may work. The community member also mentions that they have tested using Pandas AI and it can run the task smoothly, but they are unsure if Pandas AI can be used as a tool for the subquestion query.

hello, please help. Im currently using subquestion query with pandasquery as tools. but when the query is "What date is today?" the pandas generate code returning error, here the generate code

Pandas Instructions:
Plain Text
df[(df['DATE'] == datetime.date.today()) & (df['AIRPORT'] == 'CGK')]['realization_passenger'].sum()

df[(df['DATE'] == datetime.date.today()) & (df['AIRPORT'] == 'CGK')]['realization_passenger'].sum()
Traceback (most recent call last):
File "/Users/digitalservicet3/miniforge3/lib/python3.10/site-packages/llama_index/query_engine/pandas_query_engine.py", line 60, in default_output_processor
raise e
File "/Users/digitalservicet3/miniforge3/lib/python3.10/site-packages/llama_index/query_engine/pandas_query_engine.py", line 58, in default_output_processor
return str(eval(module_end_str, {"np": np}, local_vars))
File "<string>", line 1, in <module>
NameError: name 'datetime' is not defined
Pandas Output: There was an error running the output as Python code. Error message: name 'datetime' is not defined

error is because it not generate the import first. how im suppose to do to solve that error,
thankyou
L
d
2 comments
Yea that's tricky πŸ€” if you import datetime before running the query, does it work?

The pandas engine is still a little beta tbh
yah, it's already import at a main code. but still not recognize in the running sub question query. oiya the llamahub also can connect to pandas ai, I have already test pandas ai and it can run that task smoothly, but can pandas ai be a tools to be called on subquestion query?
Add a reply
Sign up and join the conversation on Discord