Git Product home page Git Product logo

Comments (3)

dosubot avatar dosubot commented on September 27, 2024 2

@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.*

from pandas-ai.

wuhuanyan avatar wuhuanyan commented on September 27, 2024

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.

image

image

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)

from pandas-ai.

xuyuanme avatar xuyuanme commented on September 27, 2024

This is related to issue #1092

from pandas-ai.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.