I have a DataFrame that looks like this:
Date Last portfolioID FinancialInstrument
1 2018-03-28 64.67 1 Oil
2 2018-03-29 64.91 1 Oil
3 2018-04-02 62.85 1 Oil
4 2018-04-03 63.57 1 Oil
5 2018-04-04 63.56 1 Oil
6 2018-04-05 63.73 1 Oil
7 2018-04-06 61.93 1 Oil
8 2018-03-23 65.74 3 Oil
9 2018-03-26 65.49 3 Oil
10 2018-03-27 64.67 3 Oil
11 2018-03-28 64.67 3 Oil
12 2018-03-29 64.91 3 Oil
13 2018-04-02 62.85 3 Oil
14 2018-04-03 63.57 3 Oil
15 2018-04-04 63.56 3 Oil
16 2018-04-05 63.73 3 Oil
17 2018-04-06 61.93 3 Oil
18 2018-04-02 62.85 5 Oil
19 2018-04-03 63.57 5 Oil
20 2018-04-04 63.56 5 Oil
21 2018-04-05 63.73 5 Oil
22 2018-04-06 61.93 5 Oil
and a NumPy array that looks like this:
[ 152.69506795 76.05719501 127.28719173]
I group a DataFrame with portfolioID, where the first group correlates with the first value in the NumPy array and the second group with the second value in the NumPy array, etc. My question is: is there a way I can multiply a column Lastin a DataFrame with its corresponding NumPy array value?
This is what I have, but I get the error "Length must be equal."
shares- NumPy array:
for pid, group in data.groupby('portfolioID'):
lastCol = group.Last
clumN = lastCol.multiply(shares, axis=0)
source
share