Hello I am trying to multiply a dataframe with a row from another dataframe.
df1
| Date | ABC | DEF | XYZ |
|---|---|---|---|
| 2020-01-31 | 3 | 4 | 2 |
| 2020-02-31 | 1 | 3 | 5 |
| 2020-03-31 | 4 | 2 | 6 |
| 2020-04-31 | 2 | 2 | 7 |
df2
| Year | ABC | DEF | XYZ |
|---|---|---|---|
| 2020 | .5 | .4 | .3 |
Is there a way to multiple DF2 across all values of DF1 to get DF3 like below.
df3
| Date | ABC | DEF | XYZ |
|---|---|---|---|
| 2020-01-31 | 1.5 | 1.6 | .6 |
| 2020-02-31 | .5 | 1.2 | 1.5 |
| 2020-03-31 | 2 | .8 | 1.8 |
| 2020-04-31 | 1 | .8 | 2.1 |
I have tried
df3.loc[:,['ABC','DEF','XYZ']] = df1.mul(df2, level=1,axis='columns')
But with that I end up with df3 being full of NaN.
df3 = df1.set_index("Date").mul(df2.to_numpy())?