Condense and map using Pandas

Question:

I wish to collapse the data, by grouping and removing duplicates.

Data

stat  ID    type

y     AA    a1
y     AA    a1
y     AA    a1
y     AA    a1
n     BB    b2
n     BB    b2
n     BB    b2
n     BB    b2
y     CC    x1
y     CC    x1

Desired

ID    type
AA    a1
BB    b2
CC    x1

Doing

Groupby and remove duplicates

df1 = df.drop_duplicates(subset = ['ID'])

Any suggestion is appreciated.

Asked By: Lynn

||

Answers:

You can df[['ID', 'type']].drop_duplicates()

Answered By: politinsa
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.