Selecting
| SQL | pandas |
|---|---|
select * from t | df |
select a, b from t | df[["a", "b"]] |
select distinct a from t | df["a"].drop_duplicates() |
select * from t limit 10 | df.head(10) |
Filtering
select * from orders where amount > 100 and status = 'paid';orders[(orders["amount"] > 100) & (orders["status"] == "paid")]Each condition needs its own brackets — & binds tighter than > in Python.
Grouping
select customer_id, count(*) as n, sum(amount) as total
from orders group by customer_id;orders.groupby("customer_id").agg(n=("amount", "size"), total=("amount", "sum"))Joining
| SQL | pandas |
|---|---|
inner join | df.merge(other, on="id") |
left join | df.merge(other, on="id", how="left") |
full outer join | df.merge(other, on="id", how="outer") |
Window functions
sum(amount) over (partition by customer_id order by order_date)orders.sort_values("order_date").groupby("customer_id")["amount"].cumsum()The one that catches everyone
GROUP BY in SQL drops the other columns. groupby in pandas moves the key
into the index — add .reset_index() to get a flat frame back.