Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (17.6k points)

I would like to have:

df[['income_1', 'income_2']] * df['mtaz_proportion']

return those columns multiplied by df['mtaz_proportion']

so that I can set

df[['mtaz_income_1', 'mtaz_income_2']] = 

df[['income_1', 'income_2']] * df['mtaz_proportion']

but instead I get:

income_1    income_2    0   1   2   3   4   5   6   7   8   9   10  11  12  13  14  15  16  17  

0   NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ...

1   NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ...

2   NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ...

etc...

what simple thing am I missing?

Thank you!

1 Answer

0 votes
by (41.4k points)

Using multiply method and then set axis="index":

df[["A", "B"]].multiply(df["C"], axis="index")

If you want to learn more about Data Science, visit data science tutorial and data science certification by Intellipaat.

Browse Categories

...