0
fashion = [1,1,2,3,3,3,21,1,1,1,5,5,5,5,3,3,2,6]  
for key,group in groupby(fashion):
print(key,':',list(group))

I have written the above code to group by certain numbers and get a list. For example, I want an outcome such as :

1 : [1,1,1,1,1]
2 : [2,2]

Can someone please tell me what's wrong with my code?

Omer Qureshi
  • 113
  • 13

1 Answers1

0

fashion is neither a sorted list for itertools.groupby() nor a Pandas DataFrame. Please post the fully functioning code with clarification on if you are attempting to use Pandas for grouping a series or DataFrame.

How to make good reproducible pandas examples

Contains good advices for getting help with Pandas features.

Rich Andrews
  • 1,590
  • 8
  • 12