Cleaning the index values and aggregating the counts of ingredients
Tue May 21 2024 15:39:30 GMT+0000 (Coordinated Universal Time)
Saved by
@Uncoverit
#python
# 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)
content_copyCOPY
Comments