langchain
langchain copied to clipboard
Make Pandas Agent return DataFrame object?
Currently I'm using a specific prompt suffix (". Assign the printed dataframe to a variable and return it as the final answer.") in the Pandas agent, which sometimes gives the result I'm looking for as a printed DataFrame. I've then written an output parser that turns this into a JSON which can then be loaded as a DataFrame.
The problem with this is the Pandas agent often doesn't output the DataFrame, instead printing the variable name or the last command used to get to that result, and also critically the output parser uses many tokens for the kinds of data I'm working with.
Is it possible to force the Pandas agent to return the output of its analysis as a Pandas DataFrame object?
@ArchieLuxton - Quick Question - How did you customize the prompt for the pandas agent ? Might sharing any code snippets ? Trying to figure this out for a while now.
Please provide a working code snipped for reproduction.
@jiyer2016 You can amend the prompt by adding / amending a prefix. The default is here: https://github.com/hwchase17/langchain/blob/master/langchain/agents/agent_toolkits/pandas/prompt.py
I'm also interested in this. It's opaque to the point I'm considering coding a whole new agent just to have access to the objects that the agents are manipulating.
Hi, @ArchieLuxton. I'm Dosu, and I'm helping the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.
From what I understand, you opened this issue requesting a modification to the Pandas agent to return the output as a Pandas DataFrame object instead of a string. There have been several comments on this issue, including jiyer2016 asking for code snippets on customizing the prompt, PawelFaron requesting a working code snippet for reproduction, PJBentham providing information on amending the prompt, and ivanmasf expressing interest in the issue.
Before we proceed, we would like to confirm if this issue is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on this issue. Otherwise, feel free to close the issue yourself, or the issue will be automatically closed in 7 days.
Thank you for your understanding and cooperation.