I would like to make a table that evaluates whether a user is in a group or not. How can I get my dictionary sorted like in the example I have down below? I would like the index and columns populated automatically by the key and value.
d = {
'user1': ['group1', 'group2', 'group3'],
'user2': ['group1', 'group2'],
'user3': ['group2']}
df = pd.DataFrame.from_dict(d,orient='index')
print(df)
Current result
user1 user2 user3
0 group1 group1 group2
1 group2 group2 NaN
2 group3 NaN NaN
Desired result - I would like the rows based on the key and the columns based on the values.
group1 group2 group3
user1 Y Y Y
user2 Y Y N
user3 N Y N