Skip to content

Commit 9c8feef

Browse files
committed
Add support for charts (sinaptik-ai#24)
1 parent 5cdab44 commit 9c8feef

7 files changed

+418
-4
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
Pandas AI is a Python library that adds generative artificial intelligence capabilities to Pandas, the popular data analysis and manipulation tool. It is designed to be used in conjunction with Pandas, and is not a replacement for it.
99

1010
<!-- Add images/pandas-ai.png -->
11+
1112
![PandasAI](images/pandas-ai.png?raw=true)
1213

1314
## Demo
@@ -68,6 +69,17 @@ The above code will return the following:
6869
14516000
6970
```
7071

72+
You can also ask PandasAI to draw a graph:
73+
74+
```python
75+
pandas_ai.run(
76+
df,
77+
"Plot the histogram of countries showing for each the gpd, using different colors for each bar",
78+
)
79+
```
80+
81+
![Chart](images/histogram-chart.png?raw=true)
82+
7183
You can find more examples in the [examples](examples) directory.
7284

7385
## Environment Variables

examples/from_dataframe.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""Example of using PandasAI with a Pandas DataFrame"""
22

3+
from data.sample_dataframe import dataframe
34
import pandas as pd
45
from pandasai import PandasAI
56
from pandasai.llm.openai import OpenAI
6-
from .data.sample_dataframe import dataframe
77

88
df = pd.DataFrame(dataframe)
99

examples/show_chart.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""Example of using PandasAI to generate a chart from a Pandas DataFrame"""
2+
3+
from data.sample_dataframe import dataframe
4+
import pandas as pd
5+
from pandasai import PandasAI
6+
from pandasai.llm.openai import OpenAI
7+
8+
df = pd.DataFrame(dataframe)
9+
10+
llm = OpenAI()
11+
pandas_ai = PandasAI(llm)
12+
response = pandas_ai.run(
13+
df,
14+
"Plot the histogram of countries showing for each the gpd, using different colors for each bar",
15+
)
16+
print(response)
17+
# Output: check out images/histogram-chart.png

examples/with_privacy_enforced.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""Example of using PandasAI with a Pandas DataFrame"""
22

3+
from data.sample_dataframe import dataframe
34
import pandas as pd
45
from pandasai import PandasAI
56
from pandasai.llm.openai import OpenAI
6-
from .data.sample_dataframe import dataframe
77

88
df = pd.DataFrame(dataframe)
99

images/histogram-chart.png

24.9 KB
Loading

poetry.lock

+386-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ python-dotenv = "^1.0.0"
1313
pandas = "^2.0.1"
1414
astor = "^0.8.1"
1515
openai = "^0.27.5"
16+
matplotlib = "^3.7.1"
1617

1718

1819
[tool.poetry.group.dev.dependencies]

0 commit comments

Comments
 (0)