Issue
I'd like to have the indexes of duplicated column elements as a list. So far, the way I found is
test = ['a', 'a', 'b', 'c', 'b']
testdf = pd.DataFrame(test, columns=['test'])
np.asarray(np.where(list(testdf['test'].duplicated()))).tolist()[0]
# [1, 4]
Which seems ridiculously convoluted.
Any better way?
Solution
you can use .duplicated()
with .tolist()
testdf.index[testdf.test.duplicated()].tolist()
Answered By - bitflip
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.