0
Good afternoon colleagues I would like a help. In the code below i Gero a new column (accumulated) using cumsum. The result is a cumulative sum for each row. However I need to bring the accumulated by rows for each color column criteria. I tested it using the tuples, with if’s, but it got too slow to run millions of lines. Please help me with this.
Follows the code:
import pandas as pd
import numpy as np
df = pd.DataFrame({'cor': ['azul', 'preto', 'amarelo', 'azul', 'preto', 'amarelo', 'preto', 'azul', 'amarelo', 'azul', 'amarelo'],
'preco': [1,1,1,2,3,4,5,3,2,4,1]})
df2 = df.preco
df['acumulado'] = df2.cumsum()
df
##################################
Resultado:
cor preco acumulado
0 azul 1 1
1 preto 1 2
2 amarelo 1 3
3 azul 2 5
4 preto 3 8
5 amarelo 4 12
6 preto 5 17
7 azul 3 20
8 amarelo 2 22
9 azul 4 26
10 amarelo 1 27
Thank you.
Our , was excellent. Thank you very much!!!!
– Heber Araujo