Practice / nulls and conditions

Not Paid in Cash

easy

The Daily Grind's card reader was down for part of Tuesday, so some orders in the till log have no payment method recorded at all. The owner wants every order that was not paid in cash, and she is clear about the unknowns: an order with no payment method on record might not have been cash, so it belongs in the list.

You have the till_log DataFrame:

Your task: return every order whose paid_by is not "cash", including the orders where paid_by is null. Keep only the columns order_id, drink, and paid_by.

Assign your answer DataFrame to result. Row order doesn't matter.

till_loginput DataFrame

Schema
columntype
order_idlong
drinkstring
paid_bystring
tipdouble
Sample rows
order_iddrinkpaid_bytip
2001oat lattecard1
2002drip coffeecash0
2003caramel macchiatocardnull
2004flat whitenull1.5
2005cold brewcardnull
2006mochacash0
2007espressovoucher0.5
2008lattecashnull
Expected output shape
order_iddrinkpaid_by· 5 rows
›Hint

F.col("paid_by") != "cash" is null, not true, for an order whose payment method is null, and filter drops it. Combine the test with F.col("paid_by").isNull() using | so the unknowns are kept too.

›Lesson refresher

This problem builds on Null Is Not a Value (~4 min). Pop it open in a new tab if you want a quick recap.

Loading editor…
Hit Run to execute your code and see the output here.