Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pandas data frame
#1
Hi all, I would like to drop all unique entries based on a specific column value.
I give an example below
data = [[10105, 1], [10105, 1], [10105, 0], [20205, 0], [20205, 0], [20205, 1], [20205, 1],[80215, 1]] 

test=pd.DataFrame(data,columns=["ID","label"])

test
Out[65]: 
      ID  label
0  10105      1
1  10105      1
2  10105      0
3  20205      0
4  20205      0
5  20205      1
6  20205      1
7  80215      1
I would like to keep all rows except the last one since the ID value happens only once. All the other rows are good.

Any ideas ?
Thanks
Alex
Reply
#2
you already know groupby and .count
test.groupby('ID').count().index
# Int64Index([10105, 20205, 80215], dtype='int64', name='ID')

test.groupby('ID').count().values.flatten()
array([3, 4, 1], dtype=int64)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to filter data frame dynamically with the columns psahay 0 231 Aug-24-2020, 01:10 PM
Last Post: psahay
  Dropping Rows From A Data Frame Based On A Variable JoeDainton123 1 326 Aug-03-2020, 02:05 AM
Last Post: scidam
  How to shift data frame rows of specified column Mekala 0 496 Jul-21-2020, 02:42 PM
Last Post: Mekala
  HELP- DATA FRAME INTO TIME SERIES- BASIC bntayfur 0 280 Jul-11-2020, 09:04 PM
Last Post: bntayfur
  pandas read_csv can't handle missing data mrdominikku 0 407 Jul-09-2020, 12:26 PM
Last Post: mrdominikku
  Pandas data frame creation from Kafka Topic vboppa 0 253 Jul-01-2020, 04:23 PM
Last Post: vboppa
  Generate Test data (.csv) using Pandas Ashley 5 551 Jun-15-2020, 02:51 PM
Last Post: jefsummers
  Filter rows by multiple text conditions in another data frame i.e contains strings an Pan 0 503 Jun-09-2020, 06:05 AM
Last Post: Pan
  Read json array data by pandas vipinct 0 394 Apr-13-2020, 02:24 PM
Last Post: vipinct
  Displaying Result from Data Frame from Function eagle 1 481 Apr-08-2020, 11:58 PM
Last Post: eagle

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020