熊猫GPT
1.0.0
pandas-gpt
使用 ChatGPT 增强您的数据科学工作流程。
pandas-gpt
是一个 Python 库,可以使用 ChatGPT 提示对 pandas DataFrame 执行几乎所有操作。
pip install pandas-gpt
将OPENAI_API_KEY
环境变量设置为您的 OpenAI API 密钥,或使用以下代码片段:
import openai
openai . api_key = ''
此Google Colab 笔记本中提供了设置和使用示例。
import pandas as pd
import pandas_gpt
df = pd . DataFrame ( 'https://gist.githubusercontent.com/bluecoconut/9ce2135aafb5c6ab2dc1d60ac595646e/raw/c93c3500a1f7fae469cba716f09358cfddea6343/sales_demo_with_pii_and_all_states.csv' )
# Data transformation
df = df . ask ( 'drop purchases from Laurenchester, NY' )
df = df . ask ( 'add a new Category column with values "cheap", "regular", or "expensive"' )
# Queries
weekday = df . ask ( 'which day of the week had the largest number of orders?' )
top_10 = df . ask ( 'what are the top 10 most popular products, as a table' )
# Plotting
df . ask ( 'plot monthly and hourly sales' )
top_10 . ask ( 'horizontal bar plot with pastel colors' )
# Allow changes to original dataset
df . ask ( 'do something interesting' , mutable = True )
# Show source code before running
df . ask ( 'convert prices from USD to GBP' , verbose = True )
如果您想使用不同的 API 主机,例如 Azure OpenAI 服务:
import openai
openai . api_type = 'azure'
openai . api_base = ''
openai . api_version = ''
openai . api_key = ''
import pandas_gpt
# pandas_gpt.model = '' # Default is 'gpt-3.5-turbo'
pandas_gpt . completion_config = {
'engine' : '' ,
# 'deployment_id': '',
}
请注意,ChatGPT 的限制也适用于该库。我建议在沙盒环境(例如 Google Colab、Kaggle 或 GitPod)中使用pandas-gpt
。