Replies: 2 comments 5 replies
-
@ngmisl where do you run this code? |
Beta Was this translation helpful? Give feedback.
-
@ngmisl you can do that asking pandasai to that all of this for you in the prompt. For instance, adapting
The only problem here would be that in the latest weeks pandas-ai has been downpowered and the generated code wouldn't be executed because it'd contain import pandas as pd
import matplotlib.pyplot as plt
import base64
import io
import json
# create dataframe
data = {'country': ['United Kingdom', 'United States', 'Germany', 'Italy', 'France'],
'gdp': [2891615567872, 8469645243, 444827455, 6820579572, 5381911486],
'happiness_index': [6.66, 6.38, 7.07, 7.16, 6.38]}
df = pd.DataFrame(data)
# plot histogram
fig, ax = plt.subplots()
colors = ['r', 'g', 'b', 'c', 'm']
for i in range(len(df)):
ax.bar(df['country'][i], df['gdp'][i], color=colors[i])
ax.set_xlabel('Country')
ax.set_ylabel('GDP')
# encode to base64 and output in json format
buffer = io.BytesIO()
plt.savefig(buffer, format='png')
buffer.seek(0)
image_png = buffer.getvalue()
buffer.close()
graph = base64.b64encode(image_png).decode('utf-8')
result = {'graph': graph}
json_output = json.dumps(result)
print(json_output) Hope this helps. |
Beta Was this translation helpful? Give feedback.
-
I'm trying to catch the plot via
and displaying it via javascript on the front-end. But it seems pandas-ai does not pass the relevant data?
Is there a way to modify this?
Beta Was this translation helpful? Give feedback.
All reactions