0

Say I have a pandas DataFrame of a certain shape that looks like:

ID      Text                                  Class
1       A series of escapades the adage ...   1
1       A series of escapades the adage ...   2
1       A series                              2
1       A series                              2
1       A series                              2
1       A series                              2
2       A                                     2
2       series                                2
2       A                                     2
2       A                                     2

I would like to create a new Dataframe that has the form:

ID      Text                                  Class
1       A series of escapades the adage ...   1
2       A                                     2

That gets the first of every 'ID' and gets ride of the rest. How can I do this? I am still new to pandas and numpy so I'm still trying to understand how to manipulate data to my liking.

Thank you for the help!

NikNack
  • 11
  • 4
  • From the accepted answer of the linked duplicate -> `df1 = df.groupby('ID', as_index=False).first()` or from the other linked `df1 = df[~df['ID'].duplicated()].copy()` – Henry Ecker Aug 12 '21 at 01:03

0 Answers0