{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2fdf0f63-d515-4cb8-b3e0-62cac7852b12",
   "metadata": {
    "tags": [
     "hide"
    ]
   },
   "outputs": [],
   "source": [
    "import seaborn as sns\n",
    "sns.set_theme(style=\"whitegrid\")\n",
    "titanic = sns.load_dataset(\"titanic\")"
   ]
  },
  {
   "cell_type": "raw",
   "id": "af16d745-734a-4f11-9f8f-fa54deadfb12",
   "metadata": {},
   "source": [
    "Show the count of value for a single categorical variable:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6e9d0485-870d-4841-9c84-6e0bacbde7db",
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.countplot(titanic, x=\"class\")"
   ]
  },
  {
   "cell_type": "raw",
   "id": "173f47c4-d5fb-4fc0-bdbd-ec228419d451",
   "metadata": {},
   "source": [
    "Group by a second variable:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "26f73c00-a2b3-45c3-b3cd-2babe0a81894",
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.countplot(titanic, x=\"class\", hue=\"survived\")"
   ]
  },
  {
   "cell_type": "raw",
   "id": "377bfb01-64a2-4f07-b06b-fb1a4f7c3b12",
   "metadata": {},
   "source": [
    "Normalize the counts to show percentages:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7267aefc-f2bc-4a64-956a-bb25013ca9ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.countplot(titanic, x=\"class\", hue=\"survived\", stat=\"percent\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py310",
   "language": "python",
   "name": "py310"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
