mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-05 17:35:28 +03:00
5.3 KiB
5.3 KiB
In [1]:
from langchain.agents import create_csv_agentIn [2]:
from langchain.llms import OpenAIIn [3]:
agent = create_csv_agent(OpenAI(temperature=0), 'titanic.csv', verbose=True)In [4]:
agent.run("how many rows are there?")Out [4]:
[1m> Entering new AgentExecutor chain...[0m [32;1m[1;3mThought: I need to count the number of rows Action: python_repl_ast Action Input: len(df)[0m Observation: [36;1m[1;3m891[0m Thought:[32;1m[1;3m I now know the final answer Final Answer: There are 891 rows in the dataframe.[0m [1m> Finished chain.[0m
'There are 891 rows in the dataframe.'
In [5]:
agent.run("how many people have more than 3 sibligngs")Out [5]:
[1m> Entering new AgentExecutor chain...[0m [32;1m[1;3mThought: I need to count the number of people with more than 3 siblings Action: python_repl_ast Action Input: df[df['SibSp'] > 3].shape[0][0m Observation: [36;1m[1;3m30[0m Thought:[32;1m[1;3m I now know the final answer Final Answer: 30 people have more than 3 siblings.[0m [1m> Finished chain.[0m
'30 people have more than 3 siblings.'
In [6]:
agent.run("whats the square root of the average age?")Out [6]:
[1m> Entering new AgentExecutor chain...[0m [32;1m[1;3mThought: I need to calculate the average age first Action: python_repl_ast Action Input: df['Age'].mean()[0m Observation: [36;1m[1;3m29.69911764705882[0m Thought:[32;1m[1;3m I can now calculate the square root Action: python_repl_ast Action Input: math.sqrt(df['Age'].mean())[0m Observation: [36;1m[1;3mname 'math' is not defined[0m Thought:[32;1m[1;3m I need to import the math library Action: python_repl_ast Action Input: import math[0m Observation: [36;1m[1;3m[0m Thought:[32;1m[1;3m I can now calculate the square root Action: python_repl_ast Action Input: math.sqrt(df['Age'].mean())[0m Observation: [36;1m[1;3m5.449689683556195[0m Thought:[32;1m[1;3m I now know the final answer Final Answer: 5.449689683556195[0m [1m> Finished chain.[0m
'5.449689683556195'
In [ ]: