I think you need groupby with nunique :
print (df)
Id ActivityId ActivityCode
0 1 2 3
1 1 2 4
2 1 3 2
3 2 8 7
df = df.groupby('Id')['ActivityId'].nunique()
print (df)
Id
1 2
2 1
Name: ActivityId, dtype: int64
And for dict
add Series.to_dict:
d = df.groupby('Id')['ActivityId'].nunique().to_dict()
print (d)
{1: 2, 2: 1}