Closed wuhuanyan closed 2 months ago
@wuhuanyan Hello there! I'm here to help you with any bugs, questions, or contributions. Let me know how I can assist you!
To resolve the "No such file or directory" error when trying to save or not save a chart image using pandasai, you can ensure that the directory exists before attempting to save the file. Here is an example of how you can modify your code:
import os
import pandas as pd
from pandasai import SmartDataframe
from os.path import dirname, join
from os import environ
from datetime import datetime
api_key = environ.get('PANDASAI_API_KEY')
if api_key is None:
api_key = '' # todo
environ.setdefault('PANDASAI_API_KEY', api_key)
base_path = dirname(__file__)
files_path = join(base_path, "files")
csv_path = join(base_path, "car.csv")
data = pd.read_csv(csv_path)
# Define the path where you want to save the chart image
save_charts_path = join(base_path, 'exports', 'charts', datetime.now().strftime('%Y-%m-%d'))
# Ensure the directory exists
os.makedirs(save_charts_path, exist_ok=True)
ai_data = SmartDataframe(data, config={
'open_charts': True, # or False
'save_char
<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
I have ensured that the saved directory has been created. Alternatively, if I set the "save_charts" parameter to "False", it should not be affected by the existence of the directory. But it will still throw an error stating that the directory does not exist.
import os
import pandas as pd
from pandasai import SmartDataframe
from os.path import dirname, join
from os import environ
from datetime import datetime
api_key = environ.get('PANDASAI_API_KEY')
if api_key is None:
api_key = '' # todo
environ.setdefault('PANDASAI_API_KEY', api_key)
base_path = dirname(__file__)
files_path = join(base_path, "files")
csv_path = join(base_path, files_path, "car.csv")
data = pd.read_csv(csv_path)
# Define the path where you want to save the chart image
save_charts_path = join(base_path, 'exports', 'charts', datetime.now().strftime('%Y-%m-%d'))
# Ensure the directory exists
os.makedirs(save_charts_path, exist_ok=True)
ai_data = SmartDataframe(data)
respone = ai_data.chat('生成马力与油耗关系图?')
print(respone)
This is related to issue #1092
System Info
OS version: win 10 22h2 Python version: 3.12.3 The current version of pandasai being used: 2.1.1
🐛 Describe the bug
Originally, these codes were working properly. But since I specified running parameters such as "open_charts" and "save_charts"*, I found that the parameters seemed to be ineffective. I kept throwing errors afterwards, even deleting all the parameters and deleting the "charts" and "exports" folders(The folder will be rebuilt), but it still didn't work properly. car.csv
*Code marked with an asterisk: