I wish to convert a large dataframe row of repeated strings to a non repeated list via dict.fromkeys()
. I have a simple df here for demonstration.
Input:
df = pd.DataFrame({'A':['X'],'B':['X'],'C':['X'],'D':['Y'],'E':['Y'],'F':['Y']})
df_list = df.values.tolist()
l= list(dict.fromkeys(df_list))
Output: df,df_list,error
A B C D E F
0 X X X Y Y Y
[['X', 'X', 'X', 'Y', 'Y', 'Y']]
l= list(dict.fromkeys(df_list))
TypeError: unhashable type: 'list'
Desired Output:
list of x,y
I recognise that the problem is due to a list within a list....perhaps there is a direct way of extracting non repeated elements from the dataframe row?