I checked many questions from here but it is not totally the same as my problem.
Let's create a dummy dictionary to describe my problem.
dictionary = {12: {1,2,4,6,8,12,16,65,13,644,653,23}, 15:{10,20,30,23,56,6,8,}, 17:{4,7,11,12,19}, 20:{40,54,123,545,234}}
Here the keys are userid, values are location-id.
My goal is to create a dataframe like this
userid locationid
12 1
12 2
12 4
... ...
15 20
15 30
15 23
... ...
17 4
17 7
17 11
... ...
20 40
20 54
... ...
My solution
for dictkey in range(len(dictionary.keys())):
lids = list(np.array(list(dictionary.values())[dictkey]).item())
userid = np.array(list(dictionary.keys())[dictkey])
userid = userid.reshape(1,1)
df= pd.DataFrame(userid, columns =['userid'])
df['locationid'] = lids
but it doesn't work. How should I approach the problem? I could not solve
Note: Normally my real dataset is big.