I have a pandas dataframe as below:
How can I combine all the lists (in the \'val\' column) into a unique list (set), e.g. [val1, val2, val33, val9, v
[val1, val2, val33, val9, v
Convert that column into a DataFrame with .apply(pd.Series). If you stack the columns, you can call the unique method on the returned Series.
.apply(pd.Series)
unique
df Out[123]: val 0 [v1, v2] 1 [v3, v2] 2 [v4, v3, v2]
df['val'].apply(pd.Series).stack().unique() Out[124]: array(['v1', 'v2', 'v3', 'v4'], dtype=object)