They both do the same thing.
inventory['total_value'] = inventory.price * inventory.quantity creates a new column, setting each value in the column to the value of
inventory.price * inventory.quantity for each row.
inventory['total_value'] = inventory.apply(lambda row: row.price * row.quantity, axis=1) is telling Pandas to create the new column
total_value, and then to apply the
lambda function along the column. (
axis=1 means apply the function to the column, so it calculates
price * quantity for each row in the column.)
Not sure if my explanation will help, but essentially they both will have the same result - they’re just different ways of getting there.