0

Let's suppose to have:

df = pd.DataFrame({'key': ['a','b','b','c','c'], 'x': [1,2,3,4,5]})

This dataframe:

  key  x
0   a  1
1   b  2
2   b  3
3   c  4
4   c  5

has one 'a' row, two 'b' rows and two 'c' rows. Now if I group the dataframe by key column and apply a function f printing out the name of each grouped dataframe I have:

df.groupby('key').apply(lambda x: print(x.name))

with this output:

a
a
b
c
Out[71]: 
Empty DataFrame
Columns: []
Index: []

why there are two prints of a?

Note my pandas version is 0.20.1

pd.__version__
Out[72]: '0.20.1'
enneppi
  • 1,029
  • 2
  • 15
  • 33

0 Answers0