The reset_index()
is your friend in this case. See the example below:
Creating Test Dataframe
>>> import pandas as pd
>>> df = pd.DataFrame({"Escritorios": ["A", "A","A","A","A"], "Municipios": ["Aruja", "Poa", "Poa", "Aruja", "Poa"], "Acessos": [1, 2, 2, 1, 2]})
>>> df
Escritorios Municipios Acessos
0 A Aruja 1
1 A Poa 2
2 A Poa 2
3 A Aruja 1
4 A Poa 2
Grouping data
>>> df.groupby(["Escritorios", "Municipios"])["Acessos"].sum()
Escritorios Municipios
A Aruja 2
Poa 6
Name: Acessos, dtype: int64
Grouping data and using reset_index()
>>> df.groupby(["Escritorios", "Municipios"])["Acessos"].sum().reset_index()
Escritorios Municipios Acessos
0 A Aruja 2
1 A Poa 6
That is, just assign to a new dataframe and save to Excel
Could you please share a little more of the code? Like the
planta_df
is structured, what data is in it?– Matheus Delazeri