consider this dataframe :
time name id volume_buy pricebuy valuebuy volumesell pricesell valuesell
0 1 a 1111 100 10 1000 0 0 0
1 2 b 2222 200 12 2400 0 0 0
2 3 c 3333 150 10 1500 0 0 0
3 4 d 4444 250 11 2750 0 0 0
4 5 a 1111 0 0 0 20 9 180
5 6 b 2222 0 0 0 60 12 720
6 7 c 3333 0 0 0 30 11 330
7 8 d 4444 0 0 0 80 10 800
8 9 a 1111 30 13 390 0 0 0
9 10 b 2222 0 0 0 20 12 240
10 11 c 3333 0 0 0 50 12 600
11 12 d 4444 0 0 0 70 10 700
12 13 a 1111 10 15 150 0 0 0
13 14 b 2222 0 0 0 50 13 650
14 15 c 3333 0 0 0 70 12 840
15 16 d 4444 0 0 0 20 14 280
16 17 a 1111 0 0 0 100 14 1400
17 18 b 2222 20 12 240 0 0 0
18 19 c 3333 20 13 260 0 0 0
19 20 d 4444 30 12 360 0 0 0
the grouped by format of the above DF is this :
total_volume_buy total_value_buy total_volume_sell total_value_sell remaining_shares
name
a 140 1540 120 1580 20
b 220 2640 130 1610 90
c 170 1760 150 1770 20
d 280 3110 170 1780 110
I want to calculate the purchase value of the remaining shares at the end of the period.
for example for person “a” is this :
(20-10)15 + (1013) = 280
*** the actual data has ten thousand rows
*** honestly I’m about to fire and lose my job so I would really appreciate if anyone help me.
grouped_sum[‘purchase value of the remaining shares’]=grouped_sum[‘remaining_shares’]*p
p is price which should be find within the related rows , and based of the remaining stocks.
Ali Ashoori is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.