0

I have a dataframe like

import pandas as pd

student_dict = {
"ID":[101,102,103,104,105,101,102,103,104,105,106,107],
"Student":["AAA","BBB","CCC","DDD","EEE","AAA","BBB","CCC","DDD","EEE","YYY","ZZZ"],
"Mark":[50,100,99,60,80,50,100,99,60,80,100,80],
"Address":["St.AAA","St.BBB","St.CCC","St.DDD","St.EEE","St.AAA","St.BBB","St.CCC","St.DDD","St.EEE","St.AYE","St.ZZZ"],
"PhoneNo":[1111111111,2222222222,3333333333,4444444444,5555555555,1111111111,2222222222,3333333333,4444444444,5555555555,6666666666,7777777777]
}

df = pd.DataFrame(student_dict)
#print(df)
rmv = df.drop_duplicates()
print(rmv)

    ID Student  Mark Address     PhoneNo
0  101     AAA    50  St.AAA  1111111111
1  102     BBB   100  St.BBB  2222222222
2  103     CCC    99  St.CCC  3333333333
3  104     DDD    60  St.DDD  4444444444
4  105     EEE    80  St.EEE  5555555555
5  101     AAA    50  St.AAA  1111111111
6  102     BBB   100  St.BBB  2222222222
7  103     CCC    99  St.CCC  3333333333
8  104     DDD    60  St.DDD  4444444444
9  105     EEE    80  St.EEE  5555555555
10 106     YYY   100  St.AYE  6666666666
11 107     ZZZ    80  St.ZZZ  7777777777

Most of the rows are duplicates, except ID 106 & ID 107

I tried df.drop_duplicates()

     ID Student  Mark Address     PhoneNo
0   101     AAA    50  St.AAA  1111111111
1   102     BBB   100  St.BBB  2222222222
2   103     CCC    99  St.CCC  3333333333
3   104     DDD    60  St.DDD  4444444444
4   105     EEE    80  St.EEE  5555555555
10  106     YYY   100  St.AYE  6666666666
11  107     ZZZ    80  St.ZZZ  7777777777

it removed the duplicates.

But I need only the odd rows like,

 ID Student  Mark Address     PhoneNo
106     YYY   100  St.AYE  6666666666
107     ZZZ    80  St.ZZZ  7777777777

is there any way to find the odd rows from a dataframe without passing any values(like ID,Student... from the student_dict) Or is there any inbuild function to find these odd rows?

Aks3
  • 71
  • 5

1 Answers1

2
df = df.drop_duplicates(keep=False)
print(df)

     ID Student  Mark Address     PhoneNo
10  106     YYY   100  St.AYE  6666666666
11  107     ZZZ    80  St.ZZZ  7777777777
Jason Baker
  • 3,170
  • 2
  • 12
  • 15