# Cleaning the index values and aggregating the counts of ingredients top_ingredient_counts = {} for ingredient, count in top_ingredient_series_sorted.items(): top_ingredient_cleaned = ingredient.replace('[', '').replace(']', '').replace("'", "") if top_ingredient_cleaned in top_ingredient_counts: top_ingredient_counts[top_ingredient_cleaned] += count else: top_ingredient_counts[top_ingredient_cleaned] = count top_ingredient_series_cleaned = pd.Series(top_ingredient_counts, dtype = int) print(top_ingredient_series_cleaned)