Skip to content

Commit

Permalink
adding other category
Browse files Browse the repository at this point in the history
  • Loading branch information
justine-gehring committed Sep 21, 2023
1 parent 2bcf996 commit 1bd710d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion moderne_visualizations_misc/comment_language_distribution.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,18 @@
" #get counts of each language\n",
" language_counts = dict(df[\"language\"].value_counts())\n",
"\n",
" #remove all the smaller percentages of languages and merge them into a category called other\n",
" sum_value = sum(language_counts.values())\n",
" language_counts_w_other = {\"other\":0}\n",
"\n",
" for lang, value in language_counts.items():\n",
" if value/sum_value<=0.05:\n",
" language_counts_w_other[\"other\"]=language_counts_w_other[\"other\"]+value\n",
" else:\n",
" language_counts_w_other[lang]=value\n",
" # plot\n",
" fig, ax = plt.subplots()\n",
" ax.pie(language_counts.values(), labels=language_counts.keys(), colors=colors.qualitative(), frame=False, autopct='%1.1f%%')\n",
" ax.pie(language_counts_w_other.values(), labels=language_counts_w_other.keys(), colors=colors.qualitative(), frame=False, autopct='%1.1f%%')\n",
" plt.axis('off')\n",
" plt.tight_layout()\n",
" plt.show()\n",
Expand Down

0 comments on commit 1bd710d

Please sign in to comment.