I have the following dataframe
import pandas as pd
df = pd.DataFrame({'var1':['A','B','C','C'],
'var2':[1,2,3,3],
'var3':['x','y','y','z']})
What I would like to do, is to get the unique values of many columns and also have next to them the name of column for which the unique value belongs to.
Ideally the resulting dataframe should look like this:
dff = pd.DataFrame({'col': ['var1','var1','var1', 'var2','var2','var2','var3','var3','var3'],
'value': ['A','B','C', 1,2,3,'x','y','z']})
I cam get the unique values using pd.unique(df[['var1','var2','var3']].values.ravel('K'))
but dont know a neat way to also append the column name next them