I\'m starting with input data like this
df1 = pandas.DataFrame( { \"Name\" : [\"Alice\", \"Bob\", \"Mallory\", \"Mallory\", \"Bob\" , \"Mallory\"] ,
Below solution may be simpler:
df1.reset_index().groupby( [ "Name", "City"],as_index=False ).count()