forked from sinaptik-ai/pandas-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave_chart.py
More file actions
35 lines (28 loc) · 938 Bytes
/
save_chart.py
File metadata and controls
35 lines (28 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""Example of using PandasAI to generate and save a chart from a Pandas DataFrame"""
import os
from data.sample_dataframe import dataframe
import pandasai.pandas as pd
from pandasai import Agent
from pandasai.helpers import path
df = pd.DataFrame(dataframe)
try:
user_defined_path = path.find_project_root()
except ValueError:
user_defined_path = os.getcwd()
# Get your FREE API key signing up at https://pandabi.ai.
# You can also configure it in your .env file.
os.environ["PANDASAI_API_KEY"] = "your-api-key"
user_defined_path = os.path.join(user_defined_path, "exports", "charts")
agent = Agent(
df,
config={
"save_charts_path": user_defined_path,
"save_charts": True,
"verbose": True,
},
)
response = agent.chat(
"Plot the histogram of countries showing for each the gpd,"
" using different colors for each bar",
)
# Output: check out $pwd/exports/charts/{hashid}/chart.png