Unleashing Power of Conversational Data Analysis with PandasAI
In today’s data-driven environment, decision-making is centered on data analysis. Tools like Pandas have become essential for anyone looking to glean insights from data, whether they be data scientists, business analysts, or just average people. But when dealing with enormous datasets, data analysis can be time-consuming and challenging. This is where PandasAI saves the day by completely changing how we conduct data analysis.
SQL has been used for years by analysts to query and analyze data. But creating complicated queries to analyze data takes a lot of practice. With the use of OpenAI’s ChatGPT, which can automatically develop, update, debug, and optimize data analysis approaches, learning and writing SQL is now simpler than with the traditional approach.
What is PandasAI?
PandasAI is a cutting-edge addition to the well-known Python package, Pandas. It blends the intelligence of Pandas with artificial intelligence, enhancing the effectiveness and efficiency of data processing. With PandasAI, you can complete jobs with a few straightforward instructions instead of writing complex code and taking a lot of time-consuming manual processes.
“PandasAI is a Python library that integrates generative artificial intelligence capabilities into pandas, making dataframes conversational”, defined by pandas-ai.com.
PandasAI turns pandas into a conversational tool that lets you ask your data questions in everyday language. For instance, you can ask PandasAI to deliver a DataFrame that only contains the rows in a DataFrame where a column’s value is larger than 5, and it will do so.
How PandasAI Work?
Python code is generated by PandasAI using a generative AI model. When you ask a question to PandasAI, the model will first try to comprehend your query. The Python code necessary to provide a response will then be generated. The code will then be run at the end, and the results will be sent to you.
Getting stated with PandasAI to analyze Titanic Dataset
Install PandasAI library.
!pip install pandasai |
Importing required libraries.
import pandas as pd import seaborn as sns from pandasai import SmartDataframe |
Setting up your OpenAI API Key
OPENAI_API_KEY = “YOUR API KEY” llm = OpenAI(api_token=OPENAI_API_KEY) |
To get your OpenAI API key you need have active OpenAI account. Click here to know how to get you API key from OpenAI.
Load titanic dataset and setting SmartDataFrame object.
df = sns.load_dataset(‘titanic’) sdf = SmartDataframe(df, config={“llm”: llm}) |
Finally, using the chat method of SmartDataFrame object provide prompts (or conversational sentences) to get results from the dataset.
sdf.chat(“Top ten highest fare”) |
sdf.chat(“group by pclass variable”) |
sdf.chat(“how many women died and how many men died”) |
This is how you can be creative to provide prompts to get the results. PandasAI is revolutionizing data analysis. It streamlines the procedure, making it more accessible and effective by combining the abilities of pandas with artificial intelligence. PandasAI can assist you in maximizing the potential of your data regardless of your level of experience with data analysis.