Build Gemini-Powered Datafame agent of natural language data with Pandas and Langchain

In this lesson, we will learn how we can combine the power of Gemini's Gemini models beside the panels of the pan. We will do all the exact and complex analyzes to analyze the Stal Titanic data. By combining the Conxafain's Experimental Pandas Datafiastal Dataafas Dataafas Dataafas DataFrame Agent, we will set up the “agent” that interprets the language of nature. It will test the data, compute statistics, resurrecting the connection, and produces visual understanding, without each function of each function. We will go with basic test measures (such as counting statistics or computer saves). We will be expanded to developed an advanced life such as survival levels of people and the age of age. Then we will compare the transformation of many DAFAfrAMAME data. Finally, we will create goals for scoring goals and the novel information patterns.
!pip install langchain_experimental langchain_google_genai pandas
import os
import pandas as pd
import numpy as np
from langchain.agents.agent_types import AgentType
from langchain_experimental.agents.agent_toolkits import create_pandas_dataframe_agent
from langchain_google_genai import ChatGoogleGenerativeAI
os.environ["GOOGLE_API_KEY"] = "Use Your Own API Key"
First, we include the required libraries, Langchain_Experintal, Langchain_Genai_genai, and Panda, to use PIP to enable the data agent and compilation of Google Gemini. Then import basic modules. Next, set up your Nature of Variable_api_key Nature, and we are ready to provide a Panda-powered Panda-powered Pandas agent for the interview.
def setup_gemini_agent(df, temperature=0, model="gemini-1.5-flash"):
llm = ChatGoogleGenerativeAI(
model=model,
temperature=temperature,
convert_system_message_to_human=True
)
agent = create_pandas_dataframe_agent(
llm=llm,
df=df,
verbose=True,
agent_type=AgentType.OPENAI_FUNCTIONS,
allow_dangerous_code=True
)
return agent
This helper asks for the llM powerful LLM client with our selected model and temperature. Then it refers to the Langchain Pandas Dandas Dataframe agent that can kill the harmful language questions (including dangerous “code”) against our data. Simply through our DataFrame to return the agent that is best for the interview.
def load_and_explore_data():
print("Loading Titanic Dataset...")
df = pd.read_csv(
"
)
print(f"Dataset shape: {df.shape}")
print(f"Columns: {list(df.columns)}")
return df
This work reveals the Titanic CSV directly from Pattas Guthubub Repo. Print and its size with column names to check immediately. Then returns the data data that is downloaded so that we can quickly start our assessment analysis.
def basic_analysis_demo(agent):
print("nBASIC ANALYSIS DEMO")
print("=" * 50)
queries = [
"How many rows and columns are in the dataset?",
"What's the survival rate (percentage of people who survived)?",
"How many people have more than 3 siblings?",
"What's the square root of the average age?",
"Show me the distribution of passenger classes"
]
for query in queries:
print(f"nQuery: {query}")
try:
result = agent.invoke(query)
print(f"Result: {result['output']}")
except Exception as e:
print(f"Error: {e}")
This form of demo kicks on the “Basic Analysis” by printing the header. Then it is placed with the usual test questions, such as data size, Survival Prices, Family Count, and class distribution, against our Titanic DataFrame agent. With each natural effect, it urges the agent. Later, he inserts its result and prints the results or mistake.
def advanced_analysis_demo(agent):
print("nADVANCED ANALYSIS DEMO")
print("=" * 50)
advanced_queries = [
"What's the correlation between age and fare?",
"Create a survival analysis by gender and class",
"What's the median age for each passenger class?",
"Find passengers with the highest fares and their details",
"Calculate the survival rate for different age groups (0-18, 18-65, 65+)"
]
for query in advanced_queries:
print(f"nQuery: {query}")
try:
result = agent.invoke(query)
print(f"Result: {result['output']}")
except Exception as e:
print(f"Error: {e}")
This work of “Adverbs” is printing the header, and run a series of complicated questions. It includes connections, make an experienced analysis, calculated median statistics, and it sets a detailed filter against our Gemino-Powered DataFrame agent. LOOP-Embarks that each of the environmental language answers, captures agent answers, and print results (or mistakes). Therefore, it shows how easily we can surround a variable AI to deeply deepen, separated by details in our part.
def multi_dataframe_demo():
print("nMULTI-DATAFRAME DEMO")
print("=" * 50)
df = pd.read_csv(
"
)
df_filled = df.copy()
df_filled["Age"] = df_filled["Age"].fillna(df_filled["Age"].mean())
agent = setup_gemini_agent([df, df_filled])
queries = [
"How many rows in the age column are different between the two datasets?",
"Compare the average age in both datasets",
"What percentage of age values were missing in the original dataset?",
"Show summary statistics for age in both datasets"
]
for query in queries:
print(f"nQuery: {query}")
try:
result = agent.invoke(query)
print(f"Result: {result['output']}")
except Exception as e:
print(f"Error: {e}")
This demo shows a path of a powerful gem in Gemini for many Dafaphrames. In this case, it includes original Titanic data and the version of the missing elders are not included. Therefore, we can ask the CROSS-DATASET questions (such as diversity, comparisons between the ages, and the percentage of the lost amount, as well as summarized statistics) are the easiest of natural languages.
def custom_analysis_demo(agent):
print("nCUSTOM ANALYSIS DEMO")
print("=" * 50)
custom_queries = [
"Create a risk score for each passenger based on: Age (higher age = higher risk), Gender (male = higher risk), Class (3rd class = higher risk), Family size (alone or large family = higher risk). Then show the top 10 highest risk passengers who survived",
"Analyze the 'deck' information from the cabin data: Extract deck letter from cabin numbers, Show survival rates by deck, Which deck had the highest survival rate?",
"Find interesting patterns: Did people with similar names (same surname) tend to survive together? What's the relationship between ticket price and survival? Were there any age groups that had 100% survival rate?"
]
for i, query in enumerate(custom_queries, 1):
print(f"nCustom Analysis {i}:")
print(f"Query: {query[:100]}...")
try:
result = agent.invoke(query)
print(f"Result: {result['output']}")
except Exception as e:
print(f"Error: {e}")
This method of kicking the time is “a custom analysis” by walking with three sophisticated, long steps. It creates a model of receiving passengers, issued and assessed by the bin and survival rates of mine and mining and money / age. Therefore, we can see how our Geminent Police Halls Bespoke, investigate something about natural language questions.
def main():
print("Advanced Pandas Agent with Gemini Tutorial")
print("=" * 60)
if not os.getenv("GOOGLE_API_KEY"):
print("Warning: GOOGLE_API_KEY not set!")
print("Please set your Gemini API key as an environment variable.")
return
try:
df = load_and_explore_data()
print("nSetting up Gemini Agent...")
agent = setup_gemini_agent(df)
basic_analysis_demo(agent)
advanced_analysis_demo(agent)
multi_dataframe_demo()
custom_analysis_demo(agent)
print("nTutorial completed successfully!")
except Exception as e:
print(f"Error: {e}")
print("Make sure you have installed all required packages and set your API key.")
if __name__ == "__main__":
main()
The main activity () serves as the first subject of the subject. It guarantees the establishment of our Gemini API key, luggage and explores the Titanic information, and starts the Change Agent. In that time it is based on basic order, advanced, Relti-DataFrame, the Demos for customary analysis. Finally, it is threatening all the work of work with trying / without block to hold and report errors before signing successfully completing.
df = pd.read_csv(")
agent = setup_gemini_agent(df)
agent.invoke("What factors most strongly predicted survival?")
agent.invoke("Create a detailed survival analysis by port of embarkation")
agent.invoke("Find any interesting anomalies or outliers in the data")
Finally, directly load the Titanic data, then our agent for part-powered Pandas, and turn off the fire from three examples. We point to important survival forecasters, break free from Durban, and open Animalies or merchants. We reach all of this without changing any of our demo activities.
At the conclusion, combining pandas with Gemini with Langchain DataFrame agent transforms data recognition from light writing code, clear language-language questions. Whether we have a summary statistics, customization scores, comparing many dafadadadaphrames, or digging into the beneficial survival of survivalism, the conversion is evident. With just a few setup lines, we find an effective Analytics Assistant to adapt to new questions in fly. It may be hidden patterns and accelerate our work flow.
See a letter of writing. All credit for this study goes to research for this project. Also, feel free to follow it Sane and don't forget to join ours 99k + ml subreddit Then sign up for Our newspaper.
Asphazzaq is a Markteach Media Inc. According to a View Business and Developer, Asifi is committed to integrating a good social intelligence. His latest attempt is launched by the launch of the chemistrylife plan for an intelligence, MarktechPost, a devastating intimate practice of a machine learning and deep learning issues that are clearly and easily understood. The platform is adhering to more than two million moon visits, indicating its popularity between the audience.




