Skip to content Skip to sidebar Skip to footer

Compare The Two Rows String For Same Id And Get The Unique String Values In Pandas

Input: df1 = pd.DataFrame([[101, 'DC1', ' AHT - QA + + AHT - Required Disclosures + payment'], [101, 'EM5', ' AHT - QA + AHT - Required Disclosures + + Off + ST

Solution 1:

You can try:

df1['unique_task_done']=df1['Task_done'].mask(df1['Task_done'].duplicated(keep=False),'same task')  
mask=df1['unique_task_done'].str.count(' + ')

Finally:

df1.loc[mask.ge(2),'unique_task_done']=df1.loc[mask.ge(2),'unique_task_done'].str.split('+').str[mask.max():].str.join('+')

Now If you print df1 you will get your output

Post a Comment for "Compare The Two Rows String For Same Id And Get The Unique String Values In Pandas"