I'd like to print unique values in each column of a grouped dataframe and the following code snippet doesn't work as expected:
df = pd.DataFrame({'a' : [1, 2, 1, 2], 'b' : [5, 5, 5, 5], 'c' : [11, 12, 13, 14]})
print(
df.groupby(['a']).apply(
lambda df: df.apply(
lambda col: col.unique(), axis=0))
)
I'd expect it to print
1 [5] [11, 13]
2 [5] [12, 14]
While there are other ways of doing so, I'd like to understand what's wrong with this approach. Any ideas?