LOOKUP using 2 dataframes in Python
If you have a dataframe df1 with two columns Id and CategoryId you can chain get_dummies and groupby, e.g. 

&gt;&gt;&gt; df2 = df1['CategoryId'].str.get_dummies().groupby(df1['Id']).max()
&gt;&gt;&gt; df2
    A  B  E  F
Id
1   1  1  0  0
2   1  0  1  1


It's not quite the format you wanted but it avoids the lookup.