Pandas AI
What is Pandas AI
PandasAI is a extension of Python pandas library that allows user to interact with panda data frames through natural language text. It leverages the ChatGPT API (OpenAI) and requires API key from OpenAI. By utilizing OpenAI’s API, Pandas AI generates Python panda codes and execute them in background.
Experiment with Pandas AI
- Install pandas AI python library
pip install pandasai
- import pandas libraries
import pandas as pd
import numpy as np
from pandasai import PandasAI
from pandasai.llm.openai import OpenAI
- Create a data frame with dummy data
student_dict = {
"name": [ "Kavin", "Balaji", "Ranjith", "Prabhakar", "Kathirvel", "Gobinath", "Prakash", "Periyasamy", "Vasanth", "Ruban", "Ragu", ],
"mark_tamil": [ 95, 90, 80, 65, 90, 72, 76, 89, 40, 89, 25, ],
"mark_english": [ 85,60,70,65,91,72,66,89,30,89,25,],
"mark_maths": [ 75,50,60,85,91,92,66,89,60,89,45,],
}
df = pd.DataFrame(student_dict)
df.head()
- Configure OpenAPI key ```
llm = OpenAI(api_token="Open API Key")
pandas_ai = PandasAI(llm, conversational=False)
- Prompt pandas API
response = pandas_ai(df, "Who is having the highiest total")
print(response)
response = pandas_ai(df, "Draw the bar chart for total marks")
print(response)
- Output