熊貓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
。