0
Hello, people, I have the dataframe below and I need to group and add the columns. For this I am using groupby, but in the result the labels are cancatenated, there is a way that this does not happen?
In the 'codes' column I would like for each row to repeat the code.
import pandas as pd
import numpy as np
codes=['2', '2', '2', '3','3','3', '2', '3']
ano_mes=['201809', '201809', '201809', '201809','201809','201809', '201810', '201810']
produto=['Meal', 'Meal', 'Meal', 'Food', 'Food', 'Food', 'Food', 'Food']
sales=[200,300,400,200,300,300,200, 150]
receita=[2,3,4,2,3,3,2,1.5]
df = pd.DataFrame({'codes': codes,
'ano_mes':ano_mes,
'produto': produto,
'sales': sales,
'receita': receita})
df_2 = df.groupby(['codes', 'ano_mes', 'produto']).sum()
Perfect, worked out! Super Thanks!
– Alan Teixeira
Show! If the answer helped you please mark as accepted by clicking there on the affirmative that is next to the voting arrows :)
– Matheus Delazeri
Done. Thank you!
– Alan Teixeira