VOOZH about

URL: https://www.buildfastwithai.com/blogs/data-analysis-with-pandasai-an-intelligent-way-to-explore-data

⇱ Data Analysis with PandasAI: An Intelligent Way to Explore Data


Mentorship

Agentic AI Launchpad

Go from user to builder in 6 weeks.

Explore Program
Share:

Introduction to Data Analysis with PandasAI

PandasAI is an innovative Python library that enhances traditional data analysis with the power of natural language processing (NLP). It allows you to query pandas DataFrames using natural language queries, making data exploration more intuitive and accessible.

In this blog, you'll learn how to:

  1. Set up PandasAI in your environment.
  2. Create a Smart DataFrame.
  3. Perform basic and advanced data analysis using natural language.
  4. Visualize data insights with intelligent queries.

Let's dive in!

1. Installation and Setup

First, let's install the PandasAI library. You can do this using pip:

!pip install -qU pandasai pandas

We also need to install the pandas library if it's not already installed:

pip install pandas

2. Creating a Smart DataFrame

To use PandasAI, you'll need a Smart DataFrame (a pandas DataFrame enhanced with AI capabilities). Here's a step-by-step guide to creating one.

Import Libraries

import pandas as pd
from pandasai import PandasAI
from pandasai.llm.openai import OpenAI

Initialize the PandasAI Engine

You'll need an OpenAI API key to use the language model. Initialize PandasAI with your key as follows:

llm = OpenAI(api_token="YOUR_OPENAI_API_KEY")
pandas_ai = PandasAI(llm)

Sample Data

Let's create a simple DataFrame with sales data:

data = {
    "Product": ["Laptop", "Mouse", "Keyboard", "Monitor", "Headphones"],
    "Sales": [120, 340, 150, 80, 300],
    "Revenue": [120000, 3400, 15000, 8000, 30000]
}
df = pd.DataFrame(data)
print(df)

Output:

     Product  Sales  Revenue
0     Laptop    120   120000
1      Mouse    340     3400
2   Keyboard    150    15000
3    Monitor     80     8000
4  Headphones   300    30000

3. Basic Data Analysis with Natural Language

Now that we have a Smart DataFrame, let's perform some basic analysis using natural language queries.

Example Query 1: "What is the total revenue?"

pandas_ai.run(df, prompt="What is the total revenue?")

Output:

The total revenue is $180,400.

Example Query 2: "Which product has the highest sales?"

pandas_ai.run(df, prompt="Which product has the highest sales?")

Output:

The product with the highest sales is Mouse with 340 units sold.

4. Advanced Queries and Visualizations

PandasAI can also generate visualizations based on your queries.

Example Query: "Show a bar chart of sales by product."

pandas_ai.run(df, prompt="Show a bar chart of sales by product.")

Output:

A bar chart will be generated showing sales figures for each product.

Example Query: "What is the average revenue?"

pandas_ai.run(df, prompt="What is the average revenue?")

Output:

The average revenue is $36,080.
🚀 Cohort Waitlist Open
Go From AI User to AI Builder

Don't just use ChatGPT. Learn to build custom LLM agents, RAG pipelines, and full-stack Agentic AI apps in our intensive 6-week program.

6 Weeks Live Mentorship
Deploy 5+ Real-world Apps
Weekly App Templates & Code
No Coding Experience Required
Explore Program
Join 1,000+ graduatesFree Registration

Conclusion

PandasAI simplifies data analysis by allowing you to interact with your datasets using natural language. This is especially useful for those who may not be familiar with Python or pandas syntax but still need to extract insights from data.

Key Takeaways

  • Ease of Use: Natural language queries make data analysis accessible.
  • Integration: Works seamlessly with pandas DataFrames.
  • Visualization: Automatically generates charts based on queries.

Next Steps

  • Experiment with your own datasets.
  • Combine PandasAI with other libraries like matplotlib and seaborn for enhanced visualizations.
  • Explore more complex queries and custom prompts.

Resources

--------------------------------------------------------------------------

Stay Updated:- Follow Build Fast with AI pages for all the latest AI updates and resources.

Experts predict 2025 will be the defining year for Gen AI implementation.Want to be ahead of the curve?

Join Build Fast with AI’s Gen AI Launch Pad 2025 - your accelerated path to mastering AI tools and building revolutionary applications.

👉 Limited Spots, join the waitlist now: www.buildfastwithai.com/genai-course 

Enjoyed this article? Share it →
Share:
You Might Also Like
👁 7 AI Tools That Changed Development (December 2025 Guide)
Tools
7 AI Tools That Changed Development (December 2025 Guide)

7 AI tools reshaping development: Google Workspace Studio, DeepSeek V3.2, Gemini 3 Deep Think, Kling 2.6, FLUX.2, Mistral 3, and Runway Gen-4.5.

👁 Claude Design: Complete Guide for Non-Designers (2026)
Tutorials
Claude Design: Complete Guide for Non-Designers (2026)

Anthropic launched Claude Design on April 17, 2026. Turn text prompts into prototypes, pitch decks & UI mockups — no Figma needed. Full guide inside.