I have two dataframes (both are datatype float). The first one is called Prices which contains only prices:
The second one is called Table_ScenarioPercentages which contains percentages where the prices need to be multiplied by:
So what I want to do is multiply the value of Period 20240201 (Prices) by Month 0 (Table_ScenarioPercentages), the value of Period 20240301 (Prices) by Month 1 (Table_ScenarioPercentages), etc.
I've tried:
Prices.iloc[:, 0]*Table_ScenarioPercentages.iloc[:, 0]
but this just gives a lot of NaN's and the wrong format:
Does someone know how to do this in Python?



TL;DR
Use
Prices['DATED BRENT']*Table_ScenarioPercentages['Supply Side Shock Up - Crude'].valuesAs per the docs on
pd.Series(italics mine):Since the indices for both dfs (
20240201, 20240301, ...and0, 1, ...) share 0 values, you end up with a new Series with the index values of both andNaNvalues as the result ofsome value * NaNor vice versa for each index value.If you want to multiply on index position, use
Series.valuesto get an ndarray (or use:Series.to_numpy). N.B. both Series need to have the same length in this case.Data sample
Index-based multiplication (cf. OP's undesired result)
Multiplication by index position (desired, with
Series.values)