I have the following DataFrame:
df = pd.DataFrame({
'From':['a','b','c','d'],
'To':['h','m','f','f'],
'week':[1,2,3,3]
})
I want to use column 'To' and 'week' as keys to map to value 'From', create a dictionary like {(1,'h'):'a',(2,'m'):'b',(3,'f'):['c','d']}, is there a way to do this? I tried to use
dict(zip([tuple(x) for x in df[['week','To']].to_numpy()], df['From']))
but it only gives me {(1,'h'):'a',(2,'m'):'b',(3,'f'):'d'}
. If there are multiple 'From's for the same ('week', 'To'), I want to put it in a list or set. Thanks!!
