langchain icon indicating copy to clipboard operation
langchain copied to clipboard

Make Pandas Agent return DataFrame object?

Open ArchieLuxton opened this issue 2 years ago • 3 comments

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 avatar May 02 '23 11:05 ArchieLuxton

@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.

jiyer2016 avatar May 03 '23 13:05 jiyer2016

Please provide a working code snipped for reproduction.

PawelFaron avatar May 04 '23 13:05 PawelFaron

@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

PJBentham avatar May 17 '23 16:05 PJBentham

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.

ivanmasf avatar Jun 04 '23 13:06 ivanmasf

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.

dosubot[bot] avatar Sep 15 '23 16:09 dosubot[bot]