I have a dataframe of the form :
element1 | element2 | element3
'dog' 'cat' 'pig'
'dog' 'weasel' 'parrot'
'dog' 'cat' 'pig'
'cat' 'dog' 'pig'
'buffalo' 'cow' 'snake'
where all elements are strings. How can I count the number of occurrences of each triplet (from every row) and set it as an additional column ? The desired result should be:
element1 | element2 | element3 | count |
'dog' 'cat' 'pig' 2
'dog' 'weasel' 'parrot' 1
'cat' 'dog' 'pig' 1
'buffalo' 'cow' 'snake' 1
where duplicate rows are also removed.