Find answers from the community

Updated 11 months ago

Might seem like a stupid question, but

At a glance
Might seem like a stupid question, but how do I not get the output in form of pandas instruction? Instead I want it in normal text form
Plain Text
import pandas as pd
# Assuming you have the llama_index package installed and properly set up
from llama_index.core.query_engine import PandasQueryEngine

from llama_index.core import PromptTemplate



df = pd.read_csv("./lessreal-data.csv", delimiter=';', skip_blank_lines=True)

# Initialize the query engine with the dataframe
query_engine = PandasQueryEngine(df=df, verbose=True)
prompts = query_engine.get_prompts()


new_prompt = PromptTemplate(
    """You will fetch me anime quotes from {query_str}"""
)
query_engine.update_prompts({"pandas_prompt": new_prompt})


# Perform a query to get a quote from Sena Kashiwazaki
response = query_engine.query(
    "Give me a quote from Tooi",
)

print(f"<b>{response}</b>")

Was looking at CSVReader on llamahub, but for some reason couldn't navigate and read the docs on it rn. Not sure if it's only me
W
v
9 comments
You can add more instruction in your prompt and also if you could provide the output that youa re currently getting that will help to understand more on this.
Plain Text
python3 script.py
> Pandas Instructions:

I'm sorry, but I couldn't find any specific quotes from a character named Tooi in any anime series. Can you provide more context or details about the character or the anime they are from?
Plain Text
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/llama_index/core/query_engine/pandas/output_parser.py", line 39, in default_output_processor
    tree = ast.parse(output)
           ^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.7/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<unknown>", line 1
    I'm sorry, but I couldn't find any specific quotes from a character named Tooi in any anime series. Can you provide more context or details about the character or the anime they are from?
     ^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax
> Pandas Output: There was an error running the output as Python code. Error message: invalid syntax (<unknown>, line 1)
<b>There was an error running the output as Python code. Error message: invalid syntax (<unknown>, line 1)</b>
PandasQueryEngine
Plain Text
Convert natural language to Pandas python code.
Is there any alternative to this
You can use CSVreader and prepare the documents to be directly used rather than using it via pandas.


Are you using OpenAI?
yes OpenAI. For some reason, I can't see the docs on csvreader @ https://llamahub.ai/
Thanks for the help! Appreciate it
Add a reply
Sign up and join the conversation on Discord