Last active
October 17, 2022 13:14
-
-
Save srang992/0a60ea4f221ad8197c24e7a44d92a766 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
def multi_count_df(data, data_cols): | |
dfs = [] | |
for col in data_cols: | |
count_data = data[col].value_counts().rename_axis(col).reset_index(name='count').head(5) | |
dfs.append(count_data) | |
return dfs | |
def count_df(data, data_col): | |
count_data = data[data_col].value_counts().rename_axis(data_col).reset_index(name='count') | |
return count_data | |
def multi_donut_charts(dfs, n_rows, n_cols, cols, colors, titles, figsize=(20,15),): | |
fig, axes = plt.subplots(nrows=n_rows, ncols=n_cols, figsize=figsize) | |
for ax, col, df, title in zip(axes.flatten(), cols, dfs, titles): | |
ax.pie(x='count', labels=col, data=df, autopct='%.1f%%', textprops={"fontsize": 14}, | |
wedgeprops=dict(width=0.33, linewidth=7), pctdistance=0.85, colors=colors) | |
ax.set_title(title, fontsize=18) | |
return fig | |
def modded_bar_plot(data, x_col, y_col, color_palette, title, fig_size=(7,5), | |
label_type='edge', font_size=15, font_style="italic", | |
font_weight="heavy", box_stat=False): | |
plt.figure(figsize=fig_size) | |
fig = sns.barplot(x=x_col, y=y_col, data=data, palette=color_palette) | |
fig.get_yaxis().set_ticks([]) | |
fig.set(xlabel=None, ylabel=None) | |
fig.bar_label(ax.containers[0], label_type=label_type) | |
fig.set_title(title, fontdict=dict(fontsize=font_size, fontstyle=font_style, | |
fontweight=font_weight)) | |
plt.box(on=box_stat) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment