I'm trying to convert some categorical values from a defaultdict(list) into columns of a pandas dataframe. For example, here is the dict I have:
{"user1": ["id1", "id2"], "user2": ["id2", "id3"]}
and the expected output is having user1 and user2 as rows, and id1, id2, id3 as columns and the value is 1 if that id appeared in the user's list and 0 otherwise.
I have created a dictionary and use a nested for loop to go through the unique user and ids and create the output but this is really slow. I was wondering what is a more efficient way of doing this?