1

I have a dataframe that looks like this:

Index   cpc             subclass    group       
0       F21S9/02        F21S        9/02    
1       F21S9/024       F21S        9/024   
2       F21V15/013      F21V        15/013  
3       F21V17/107      F21V        17/107  
4       F21V23/005      F21V        23/005  
5       F21V23/006      F21V        23/006  
6       F21V29/76       F21V        29/76   
7       F21V29/83       F21V        29/83   
8       F21V31/005      F21V        31/005  
9       F21W2131/103    F21W        2131/103    
10      F21Y2105/10     F21Y        2105/10 
11      F21Y2113/00     F21Y        2113/00 
12      F21Y2115/10     F21Y        2115/10 

I want to create a new dataframe that groups all groups together that have the same subclass, like this:

Index   subclass    groups
0       F21S        9/02, 9/024
1       F21V        15/013, 17/107, 23/005, 23/006, 29/76, 29/83, 31/005
2       F21W        2131/103
3       F21Y        2105/10 2113/00, 2115/10

I started to write some if loops with a counter to compare the subclass values at each index and combine their group, but that get really complicated. Is there an easier way to do this with pandas? Maybe groupby?

I tried df.groupby(['subclass']).values, but that gave me an error: AttributeError: Cannot access attribute 'values' of 'DataFrameGroupBy' objects, try using the 'apply' method

Britt
  • 539
  • 1
  • 7
  • 21
  • @ALollz yes it is, thank you. Should I delete this question? – Britt Jul 20 '18 at 13:25
  • No, I don't think you have to. If it gets marked as a duplicate then it will just focus more questions in that direction. It's a well written question. – ALollz Jul 20 '18 at 13:26

0 Answers0