Reputation: 111
Suppose I have a pandas DataFrame with two columns named 'A' and 'B'.
Now suppose I also have a dictionary with keys 'A' and 'B', and the dictionary points to a scalar. That is, dict['A'] = 1.2 and similarly for 'B'.
Is there a simple way to multiply each column of the DataFrame by these scalars?
Cheers!
Upvotes: 4
Views: 10415
Reputation: 105551
As Wouter said, the recommended method is to convert the dict to a pandas.Series and multiple the two objects together:
result = df * pd.Series(myDict)
Upvotes: 5