I am trying to add a new column to a data below, in which columns Algorithm1,2 & 3 are derived from Text column. I want to count each element in the 3 columns and create new column to only have elements which have count > 1
df = pd.DataFrame({'T':['AAABBX','AAABBX','AAABBX'],
'Algorithm1': ['AX','AB','AAB'],
'Algorithm2' : ['BX','AAX','AB'],
'Algorithm3' : ['AX','AB','AAX']})
This is how the final output should look like with columns values AB, AX & AAX as they have frequency > 1
df2 = pd.DataFrame({'T':['AAABBX','AAABBX','AAABBX'],
'Algorithm1': ['AX','AB','AAB'],
'Algorithm2' : ['BX','AAX','AB'],
'Algorithm3' : ['AX','AB','AAX'],
'Majority': ['AB','AX','AAX']})