In the Petal Power Project here:
Petal Power Project
Youtube video solution
On task 5 they ask
Another customer emails to ask what types of seeds are sold at the Brooklyn location. Select all rows where
location is equal to
product_type is equal to
seeds and save them to the variable
The solution is:
seed_request = inventory[(inventory['location'] == 'Brooklyn') & (inventory['product_type'] == 'seeds')]
My first attempt was:
seed_request = inventory.apply(lambda row: row if (row['location'] == 'Brooklyn') & (row['product_type'] == 'seeds') else False, axis = 1)
And I got the below result:
Do you know why this is not working ?
Is that the full results of the code?
It doesn’t work b/c the syntax is a little mixed up. What is the purpose of
(Plus, it’s not really necessary b/c you can find the info from the table w/o a lambda function.)
(what to return if TRUE) >
if this (
if statement goes here) >
else (what to return if the statement is
Whereas the solution code you posted checks those two conditions (is Brooklyn? and do they have seeds in stock?) and the results are either
So, how would you re-write your lambda function so it’d work?
(I’m wondering if one could use it and still pass the background tests of the project?)