0

The following code does not give an error, but is ignoring the .count() part as per the picture below. It is returning 1 column, when I expected 2? any idea why? thanks.

df = df.filter(['StartsWith'])
df = df.groupby(['StartsWith']).count()
df

enter image description here

Chadee Fouad
  • 2,630
  • 2
  • 23
  • 29
  • 1
    Looks like you chopped off half of the picture. `GroupBy` sets your column which you want to group by on as index. Use `df.groupby(['StartsWith']).count().reset_index()` to get your `StarstWith` back as column. – Erfan Dec 23 '19 at 16:59
  • df.groupby(['StartsWith']).size().reset_index() – BENY Dec 23 '19 at 17:01
  • See marked duplicate, in particular [this answer](https://stackoverflow.com/a/38703649/9209546). – jpp Dec 23 '19 at 17:24
  • @Erfan no I didn't chop off anything..that was the exact output. However, your comment about the index was quite helpful. When I changed df.filter(['StartsWith']) with df.filter(['StartsWith','Source']) the output showed the count. Thanks! :-) – Chadee Fouad Dec 23 '19 at 17:26

1 Answers1

0

Try to replace .count() by .size().

Rui Figueiredo
  • 110
  • 1
  • 5