扫一扫分享
# 使用 pip
pip install "pandasai>=3.0.0b2"
# 使用 poetry
poetry add "pandasai>=3.0.0b2"
import pandasai as pai
from pandasai_openai.openai import OpenAI
llm = OpenAI("OPEN_AI_api_KEY")
pai.config.set({
"llm": llm
})
# 示例 DataFrame
df = pai.DataFrame({
"country": ["United States", "United Kingdom", "France", "Germany", "Italy", "Spain", "Canada", "Australia", "Japan", "China"],
"revenue": [5000, 3200, 2900, 4100, 2300, 2100, 2500, 2600, 4500, 7000]
})
# 提问
df.chat('Which are the top 5 countries by sales?')
# 员工数据
employees_data = {
'EmployeeID': [1, 2, 3, 4, 5],
'Name': ['John', 'Emma', 'Liam', 'Olivia', 'William'],
'Department': ['HR', 'Sales', 'IT', 'Marketing', 'Finance']
}
# 薪资数据
salaries_data = {
'EmployeeID': [1, 2, 3, 4, 5],
'Salary': [5000, 6000, 4500, 7000, 5500]
}
employees_df = pai.DataFrame(employees_data)
salaries_df = pai.DataFrame(salaries_data)
# 关联查询
pai.chat("Who gets paid the most?", employees_df, salaries_df)
df.chat(
"Plot the histogram of countries showing for each one the revenue. Use different colors for each bar",
)
仅供个人学习参考/导航指引使用,具体请以第三方网站说明为准,本站不提供任何专业建议。如果地址失效或描述有误,请联系站长反馈~感谢您的理解与支持!
手机预览