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!
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With