はじめに
Amazonでの書籍の購買履歴をインプットに、ChatGPTでデータハンドリングを試してみます。
データインプット
さらに、分析の方向性も提案してくれます。
前処理
はじめにデータの前処理を行ってもらいます。
エラーを起こしながらも、それを含めて対処してくれました。
# Remove any potential quotes from the date column
data['注文日'] = data['注文日'].str.replace('"', '')
# Retry converting 注文日 to datetime
data['注文日'] = pd.to_datetime(data['注文日'], format='%Y/%m/%d', errors='coerce')
# Re-extract month, week, and day of week
data['月'] = data['注文日'].dt.month
data['週'] = data['注文日'].dt.isocalendar().week
data['曜日'] = data['注文日'].dt.day_name()
# Re-display the modified dataframe
data.head()
サンプルで内容を見てみましょう。
# Display the first 5 rows of the updated dataframe
data.head(5)
基礎統計の確認
- 年間の合計: 390,167円 / 185冊
- 月の平均:32,514円 / 約15.42冊
- 1週間平均:7,503円 / 約3.56冊