Can we perform operations between more than two columns of a dataframe?


#1

Question

In the lesson, we only performed operations between at most two columns of a dataframe. Can we perform operations between more than two columns?

Answer

Yes, you can perform operations between two or more columns. In fact, there is no limit to how many columns you can perform functions on.

For example, say we had a dataframe containing columns for
price, tax, and quantity.

We could perform an operation using all three of these columns:
df['total'] = (df.price + (df.price * df.tax)) * df.quantity