I have a DataFrame which look like:
_|a |b |c
x|1 |1 |1
y|2 |2 |3
z|3 |2 |1
I want the result to be:
{
1: [(x,a),(x,b),(x,c),(z,c)}
2: [(y,a),(y,b),(z,b)]
3: [(y,c),(z,a)]
}
I dont care if the result is a dictionary or another dataframe
You can use GroupBy.groups
here
g = df.stack()
g.groupby(g).groups
{
1: [('x', 'a'), ('x', 'b'), ('x', 'c'), ('z', 'c')],
2: [('y', 'a'), ('y', 'b'), ('z', 'b')],
3: [('y', 'c'), ('z', 'a')]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With