Here I have this dataframe and I am trying to remove the duplicate elements from each array in column 2 as follows and resultant array in Column 3.
Column1 Column 2 Column3
0 [ABC|QWER|12345, ABC|QWER|12345] [ABC|QWER|12345]
1 [TBC|WERT|567890,TBC|WERT|567890] [TBC|WERT|567890]
2 [ERT|TYIO|9845366, ERT|TYIO|9845366,ERT|TYIO|5] [ERT|TYIO|9845366, ERT|TYIO|5]
3 NaN NaN
4 [SAR|QWPO|34564557,SAR|QWPO|3456455] [SAR|QWPO|34564557,SAR|QWPO|3456455]
5 NaN NaN
6 [SE|WERT|12233412] [SE|WERT|12233412]
7 NaN NaN
I m using following codes but its showing the error of malformed node or string.Please help to solve this.
import ast
def ddpe(a):
return list(dict.fromkeys(ast.literal_eval(a)))
df['column3'] = df['column2'].apply(ddpe)