Flashcards
How each SQL clause maps to pandas: filtering, GROUP BY, joins and merge pitfalls, window functions, CASE, NULL handling and reading from a database.
SQL SELECT id, amount FROM orders WHERE amount > 40 in pandas?
SELECT id, amount FROM orders WHERE amount > 40
Tap to flip
df.loc[df["amount"] > 40, ["id", "amount"]] # or df.query("amount > 40")[["id", "amount"]]
Combine conditions with & and | and wrap each in parentheses ((a > 1) & (b < 2)); and/or do not work on Series.
&
|
(a > 1) & (b < 2)
and
or
Tap to see the front