Hello everybody,

I have a general question on why something worked for me even though the instructor in the video did it differently.

Here is the link for the project: Modifying DataFrames with Pandas | Codecademy

I did NOT use a lambda function for this new column in a data frame yet still got the same results, why did this work without lambda

my code:
inventory[‘total_value’] = inventory.price * inventory.quantity

solution code:
inventory[‘total_value’] = inventory.apply(lambda row: row.quantity * row.price,axis=1)

thanks in advance!

It passed/the box was checked?
That’s interesting that it still worked b/c one would think you’d want to do the calculations row by row (rather than by column), thus the axis=1 in the function and add those results to the new column.

Edit: I looked at my code from that lesson (which was circa 2017 & was originally written in Python2) & I had written the same thing as you had. So, maybe the back end code allowed for either bit of code to pass. :woman_shrugging: