Created
April 12, 2023 15:37
-
-
Save srang992/0ca3695d99da461fb9a64cf57cc261c8 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
import itertools | |
def count_df(data,data_col): | |
choco_count = data[data_col].value_counts().rename_axis(data_col).reset_index(name='count') | |
choco_data_with_counts = pd.merge(left=data, right=choco_count, left_on=data_col, right_on=data_col) | |
return choco_data_with_counts | |
def number_indicator(val, title_text, row_num, col_num): | |
return go.Indicator(mode = 'number', | |
value = val, | |
number = {'valueformat':'0,f'}, | |
title = {'text':title_text}, | |
domain = {'row':row_num,'column':col_num}) | |
def sort_sliced_dict(main_dict, is_reverse=True, item_count=None): | |
sorted_dict = {k:v for k, v in sorted(main_dict.items(), key=lambda item: item[1], reverse=is_reverse)} | |
if item_count is not None: | |
sorted_dict = dict(itertools.islice(sorted_dict.items(), item_count)) | |
return sorted_dict |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment