データサイエンス100本ノックでSQLとPythonを勉強していきます。
S-024: レシート明細テーブル(receipt)に対し、顧客ID(customer_id)ごとに最も新しい売上日(sales_ymd)を求め、10件表示せよ。
SQLだと以下のようになります。
%%sql select customer_id, max(sales_ymd) from receipt group by customer_id limit 10;
Pythonだと以下のようになります。
df_receipt.groupby('customer_id').sales_ymd.max().reset_index().head(10)