create_csv_agent: How to save a dataframe once information has been extracted using create_csv_agent.

### Issue you'd like to raise.

So, I am working on a project that involves data extraction from csv files and involves creating charts and graphs from them.

below is a snippet of code for the agent that I have created : 

```python
tools = [
    python_repl_tool,
    csv_ident_tool,
    csv_extractor_tool,
]

# Adding memory to our agent
from langchain.agents import ZeroShotAgent
from langchain.memory import ConversationBufferMemory

prefix = """Have a conversation with a human, answering the following questions as best you can. You have access to the following tools:"""
suffix = """Begin!"

{chat_history}
Question: {input}
{agent_scratchpad}"""

prompt = ZeroShotAgent.create_prompt(
    tools=tools, 
    prefix=prefix, 
    suffix=suffix, 
    input_variables=["input", "chat_history", "agent_scratchpad"]
)

memory = ConversationBufferMemory(memory_key="chat_history")

# Creating our agent
from langchain.chains import LLMChain
from langchain.llms import OpenAI
from langchain.agents import AgentExecutor

llm_chain = LLMChain(llm=OpenAI(temperature=0), prompt=prompt)
agent = ZeroShotAgent(llm_chain=llm_chain, tools=tools, verbose=True)
agent_chain = AgentExecutor.from_agent_and_tools(agent=agent, tools=tools, verbose=True, memory=memory)
``` 

Where csv_ident tool is a custom tool I created to identify csv file in a prompt.
Example:
prompt : What is the mean of age in data.csv?
completion : data.csv

csv_extractor_tool is as follows : 

```python
def csv_extractor(json_request: str):
    '''
    Useful for extracting data from a csv file.
    
    Takes a JSON dictionary as input in the form:
        { "prompt":"<question>", "path":"<file_name>" }

    Example:
        { "prompt":"Find the maximum age in xyz.csv", "path":"xyz.csv" }

    Args:
        request (str): The JSON dictionary input string.

    Returns:
        The required information from csv file.
    '''
    arguments_dictionary = json.loads(json_request)
    question = arguments_dictionary["prompt"]
    file_name = arguments_dictionary["path"]
    csv_agent = create_csv_agent(llm=llm,path=file_name,verbose=True)
    return csv_agent.run(question)

request_format = '{{"prompt":"<question>","path":"<file_name>"}}'
description = f'Useful for working with a csv file. Input should be JSON in the following format: {request_format}'

csv_extractor_tool = Tool(
    name="csv_extractor",
    func=csv_extractor,
    description=description,
    verbose=True,
)
``` 

So I am creating a csv_agent and passing the prompt and path to it. This handles the data extraction type tasks easily, but I produces poor results while making plots. 

Till now I have tried creating a new LLMChain in which I passed prompt comprising of several examples as given below:

```
input :{{"prompt":"Load data.csv and find the mean of age column.","path":"data.csv"}}
completion :import pandas as pd
df = pd.read_csv('data.csv')
df = df['Age'].mean()
print(df)
df.to_csv('.\\bin\\file.csv')
``` 

But this does not work as the LLM cannot know beforehand what are the exact column name and generating such a code is short-sighted and produces errors.

I have also tried taking a callbacks based approach where in the on_tool_end() function I was trying to save the dataframe.

Is there any way to make csv_agent save the dataframe in a bin folder after it is done extracting the information, which I can pass to my custom plot creating tool.

### Suggestion:

_No response_