buildfastwithaibuildfastwithai
AI WorkshopsAll blogsPartner with usFDE Program
Unrot mascotGet yourselfupskilled in AIfor free.Get the appNext live workshopFree AI WorkshopLive session, recording includedReserve a seat

Newsletter

Stay ahead

AI tools and tips. No spam.

Share
Back to blogs
Tutorials
Coding

Data Analysis with PandasAI: An Intelligent Way to Explore Data

By Satvik Paramkusham
December 11, 2024
3 min read
Share:
Data Analysis with PandasAI: An Intelligent Way to Explore Data
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.
LLM AGENTSRAG PIPELINESTOOL CALLINGDEPLOYMENT
Let's build

Start building AI agents with Build Fast

Explore ProgramJoin Waitlist

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.

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.

Cohort program

Claude MasteryCowork & Code

Explore programJoin waitlistNo coding needed

Resources

  • PandasAI GitHub Repository
  • OpenAI API Documentation
  • Build Fast with AI Pandas GitHub Repo

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

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 

Satvik Paramkusham
Written by

Satvik Paramkusham

Founder at Build Fast with AI. AI Engineer, educator, and researcher passionate about agentic AI workflows, LLM application architecture, and training the next generation of AI builders.

Share:

Partner with Build Fast with AI

Guest posts, sponsored articles, tool reviews and in-blog CTAs. See what we offer and get in touch.

Partner with us

Topics

  • Claude AI
  • Best AI Models
  • AI Coding Tools
  • AI Agent Frameworks
  • Agentic AI
  • Open-Source LLMs
  • RAG & Vector Databases
  • AI Industry News

Popular guides

  • 100 Best AI Photo Editing Prompts
  • 75 Best ChatGPT Images 2.5 Prompts
  • 100 Best AI Video Prompts
  • Best AI Models 2026, Tested
  • Claude AI Complete Guide
  • What Is MCP?

Build Fast with AI

  • Build Fast with AI
  • AI Workshops
  • Corporate Training
  • FDE Program
  • Partner with Us
  • Contact
© 2026 Intellify Edventures Private Limited. All rights reserved.
    You Might Also Like
    ChatGPT Images 2.6: Features, Pricing and Review
    Tutorials
    ChatGPT Images 2.6: Features, Pricing and Review

    ChatGPT Images 2.6 review covering Flare vs Sunburst, GIFs, SVG output, image editing, API pricing and practical prompts for creators.

    50 Best Diwali AI Photo Prompts 2026 for Gemini, ChatGPT & Nano Banana
    Tools
    50 Best Diwali AI Photo Prompts 2026 for Gemini, ChatGPT & Nano Banana

    Create stunning Diwali photos with 50 copy-paste AI prompts for Gemini, ChatGPT and Nano Banana. Try realistic portraits, couple photos, saree looks, diyas, rangoli and festive posters.