python - How do I keep an ID in a pandas DF that has duplicates only if all of its records in another column have the same value? -
i want keep research id if of test grades same, if not cannot rely on integrity of data , must discard id.
i tried creating dictionary, research id below, l4 saved value.
researchid testgrade 1026379 l4 1026379 l2 1026379 l4 1026379 l4 1026379 l4
you groupby research id , keep ids length of unique test grades equal 1, using filter.
df.groupby('researchid').filter(lambda g: len(g.testgrade.unique()) == 1)
Comments
Post a Comment