0

Here is a working example

# create dataframe
df = pd.DataFrame({"a":range(10), "b":[1,1,1,2,2,2,3,3,4,1]})
# group by 'b' column and print every group
df.groupby("b").apply(lambda x:print(x))

Here is the result, as you can see, the first 2 group contains the same elements. How do I correct this?

   a  b
0  0  1
1  1  1
2  2  1
9  9  1

   a  b
0  0  1
1  1  1
2  2  1
9  9  1

   a  b
3  3  2
4  4  2
5  5  2

   a  b
6  6  3
7  7  3

   a  b
8  8  4
scott huang
  • 2,478
  • 4
  • 21
  • 36

0 Answers0