Replies: 1 comment 11 replies
-
Hey @tlallema! I'm here to help you with any issues you're facing. Let's figure this out together! To modify the context/system in the LangChain prompt to work directly with pandas dataframes without converting them to CSV strings, you can use the import pandas as pd
from langchain_core.prompts import ChatPromptTemplate
from langchain_experimental.tools import PythonAstREPLTool
from langchain.output_parsers.pandas_dataframe import PandasDataFrameOutputParser
from langchain_openai import ChatOpenAI
# Load your dataframe
df = pd.read_csv("titanic.csv")
# Create the tool with the dataframe in its local scope
tool = PythonAstREPLTool(locals={"df": df})
# Create the system prompt
system = f"""You have access to a pandas dataframe `df`. \
Here is the output of `df.head().to_markdown()`: {df.head().to_markdown()}
This setup allows the LangChain prompt to work directly with pandas dataframes by including the dataframe's head in the system prompt and using the |
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
I'm trying to build a prompt with langchain which could use dataframes (here dataframe from sql tables). This prompt works fine when giving name of files (csv or xls). It returns chart based on the underlying data (using Plotly library). However I do no succeed to do it with pandas dataframes. any idea how I should modify the context/system in the prompt (not going through the Create_pandas_dataframe) ?
System Info
last langchain version, python 3.9
Beta Was this translation helpful? Give feedback.
All reactions