Quick question on the Petal Power Inventory project under “Learning Data Analysis with Pandas.” https://www.youtube.com/watch?v=oD1UOfUoUc0&feature=youtu.be
Task 6 of the project asks:
Add a column to
in_stock which is
quantity is greater than 0 and
quantity equals 0.
My solution was the following (which gave the correct output)
inventory[‘in_stock’] = inventory.quantity.apply(lambda x: True if x > 0 else False)
However, the YouTube walk through provides the solution as:
inventory['in_stock] = inventory.apply(lambda row: True if row.quantity > 0 else False,
What would be the reason (if any) to use the solution provided by the video walkthrough? Or, asked another way, what’s wrong with my code even though it gives the right answer?