Home > Blockchain >  Pandas groupby after groupby not working how?
Pandas groupby after groupby not working how?

Time:10-25

I have df so:

  col1 col2  col3
0    a    x     1
1    a    x     2
2    a    y     3
3    b    x     4
4    b    x     5
5    c    y     6

and used groupby col1 and now groupby col2 but error is

AttributeError: 'DataFrameGroupBy' object has no attribute 'groupby'. 
Did you mean: 'groups'?

What can I do for fixing? I need ax=3, ay=3, bx=9, cy=6

CodePudding user response:

You can pass a list to groupby if you have multiple indices. Try this:

df.groupby(["col1", "col2"])["col3"].sum()
  • Related