Giter Site home page Giter Site logo

Comments (1)

dosubot avatar dosubot commented on September 27, 2024 2

Hey there, @ReeveWu! I'm here to help you with any bugs, questions, or contributions you have. Let's squash those bugs together! 🤖

The issue you're encountering is due to the Agent class in pandasai not handling unhashable types like lists in DataFrame columns. The error message "unhashable type: 'list'" indicates that the Agent class is trying to process the list data type in a way that requires hashing, which is not possible for lists.

To work around this issue, you can preprocess the DataFrame to convert the list columns into a format that can be handled by the Agent class. One common approach is to convert the lists into strings or another hashable type.

Here's an example of how you can modify your DataFrame before passing it to the Agent:

import pandas as pd
import os
from pandasai import Agent, Config
from pandasai.llm import OpenAI

data = {
    'Employee_ID': [101, 102, 103, 104],
    'Employee_Name': ['Alice', 'Bob', 'Charlie', 'Diana'],
    'Projects': [['Project A', 'Project B'], ['Project C'], ['Project D', 'Project E', 'Project F'], ['Project G']],
    'Salary': [70000, 80000, 75000, 90000]
}

df = pd.DataFrame(data)

# Convert list columns to strings
df['Projects'] = df['Projects'].apply(lambda x: ', '.join(x))

agent = Agent(
    dfs=df, 
    config=Config(llm=OpenAI(api_token=os.getenv("OAI_API_KEY"), model="gpt-4o"))
)

print(agent.chat('Tell me the average salary of the employees'))

This code converts the Projects column from lists to comma-separated strings, which should be hashable and thus avoid the "unhashable type: 'list'" error.

If you need to perform more complex analysis on the list data, you might need to implement additional preprocessing steps or custom handling within your analysis logic.

To continue talking to Dosu, mention @dosu.

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.