# 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)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter