Created
April 13, 2023 04:18
-
-
Save srang992/698096ce47deef1736c4b3d1ab41bd0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# split those ingredients values | |
choco_data['ingredients'] = choco_data['ingredients'].str.strip(' ') | |
choco_data['num_ingredients'] = choco_data['ingredients'].str.split('-', expand=True)[0] | |
choco_data['main_ingredients'] = choco_data['ingredients'].str.split('-', expand=True)[1] | |
choco_data['main_ingredients'] = choco_data['main_ingredients'].str.strip(' ') | |
# encoding the values | |
ingre_encode = choco_data['main_ingredients'].str.get_dummies(sep=',') | |
# concatenating lecithin column with the main data. Containing lecithin denoted by 1 | |
# and otherwise 0 | |
choco_data_lecithin = pd.concat([choco_data, ingre_encode['L']], axis=1) | |
choco_data_lecithin.rename(columns={'L': 'ingredient_L'}, inplace=True) | |
# split the chocolate data into two parts - chocolate containing lecithin and | |
# chocolate doesn't contain lecithin. | |
choco_has_lecithin = choco_data_lecithin[choco_data_lecithin['ingredient_L'] == 1] | |
choco_has_no_lecithin = choco_data_lecithin[choco_data_lecithin['ingredient_L'] == 0] | |
# calculating the average for both chocolates | |
rating_by_choco_has_lecithin = choco_has_lecithin['rating'].mean() | |
rating_by_choco_has_no_lecithin = choco_has_no_lecithin['rating'].mean() | |
# plotting the graph | |
fig = go.Figure() | |
fig.add_trace(number_indicator(val=rating_by_choco_has_lecithin, | |
title_text="Average Rating of Bars having Lecithin", | |
row_num=0, col_num=0)) | |
fig.add_trace(number_indicator(val=rating_by_choco_has_no_lecithin, | |
title_text="Average Rating of Bars having no Lecithin", | |
row_num=0, col_num=1)) | |
fig.update_layout(grid={'rows': 1, 'columns': 2, 'pattern': 'independent'}) | |
fig.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment