Petal Power Inventory - Learning Data Analysis with Pandas

Hi all,

Quick question on the Petal Power Inventory project under “Learning Data Analysis with Pandas.”

Task 6 of the project asks:

Add a column to inventory called in_stock which is True if quantity is greater than 0 and False if 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,
axis =1)

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?


Hello, @kennonjones930229784 welcome to the forums.

Check out this thread on the very same question:

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.