Performing a function on the existing columns - Pandas

Hi,

I would like to ask the following, extracted from the course - Analyse Data with Python - Modifying Dataframes

Below is a code to compute Sales Tax in a new column
df['Sales Tax'] = df.Price * 0.075

Using similar concept, why can’t I find Sales Margin using
df['Sales Tax'] = df.Price - df.Cost ?

The suggested solution is **df['Margin'] = df['Price'] - df['Cost to Manufacture']** but I do not understand why we cannot subtract column values by
df['Sales Tax'] = df.Price - df.Cost.

Would appreciate an explanation! Thank you very much!

There is no column called “Cost” on that table.
The column name is “Cost to Manufacture”, so, in order to access this, you need to use the square brackets [‘Cost to Manufacture’]. You can not access it with the dot notation “df.Cost to Manufacture” as there are empty spaces on the name.

If the column was called “Cost_to_Manufacture”, you would be able to call with df.Cost_to_Manufacture or df[‘Cost_to_Manufacture’].

Also note that Sales Tax is different from Margin.
In this exercise, we create a new column called Margin, while giving it the values.

A link to your problem would be helpful