scores = 1- (pois['category'].value_counts(normalize=True)) * 3 scores_dict = dict(zip(scores.index,scores.values * 100)) pois['weight'] = pois['category'].map(scores_dict) grouped_df = pois.groupby("h3").agg( counts=('category','count'), score = ('weight','sum') ).sort_values(by='counts',ascending=False) grouped_df.head()