{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Practical Data Visualization with Python - Part 2: Overview of Python Visualization Landscape" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Setup" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%%capture\n", "# capturing above because there are a few useless warnings that might pop up, version-depending\n", "\n", "# basic packages:\n", "import numpy as np\n", "import pandas as pd\n", "import datetime\n", "from scipy import stats\n", "\n", "# packages for viz:\n", "# plotly express\n", "import plotly_express as px\n", "# matplotlib\n", "import matplotlib.pyplot as plt\n", "# seaborn and default seaborn settings set for matplot lib charts\n", "import seaborn as sns; sns.set()\n", "# base plotly packages\n", "import plotly.figure_factory as ff\n", "import plotly.io as pio\n", "from plotly.offline import plot, iplot, init_notebook_mode\n", "from plotly.subplots import make_subplots\n", "# turns on plotly notebook mode\n", "init_notebook_mode()\n", "from plotly import graph_objs as go\n", "# altair\n", "import altair as alt\n", "# turns on altair renderer -- jlab is default\n", "alt.renderers.enable('jupyterlab')\n", "# bokeh\n", "from bokeh.plotting import figure, show, output_file, save\n", "from bokeh.io import output_notebook\n", "# plotnine\n", "from plotnine import *" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# there are a few warnings I want to silence throughout that are due to unimportant np deprecations \n", "np.warnings.filterwarnings('ignore')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'This notebook was last executed on 2019-08-08 18:37'" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# store the datetime of the most recent running of this notebook as a form of a log\n", "most_recent_run_datetime = datetime.datetime.now().strftime(\"%Y-%m-%d %H:%M\")\n", "f\"This notebook was last executed on {most_recent_run_datetime}\"" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | loan_id | \n", "orig_chn | \n", "seller_name | \n", "orig_rt | \n", "orig_amt | \n", "orig_trm | \n", "orig_dte | \n", "frst_dte | \n", "oltv | \n", "ocltv | \n", "... | \n", "occ_stat | \n", "state | \n", "zip_3 | \n", "mi_pct | \n", "product_type | \n", "cscore_c | \n", "mi_type | \n", "relocation_flg | \n", "cscore_min | \n", "orig_val | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "100020736692 | \n", "B | \n", "CALIBER HOME LOANS, INC. | \n", "4.875 | \n", "492000 | \n", "360 | \n", "12/2017 | \n", "02/2018 | \n", "75 | \n", "75 | \n", "... | \n", "I | \n", "CA | \n", "920 | \n", "NaN | \n", "FRM | \n", "NaN | \n", "NaN | \n", "N | \n", "757.0 | \n", "656000.000000 | \n", "
| 1 | \n", "100036136334 | \n", "R | \n", "OTHER | \n", "2.750 | \n", "190000 | \n", "180 | \n", "12/2017 | \n", "01/2018 | \n", "67 | \n", "67 | \n", "... | \n", "P | \n", "MD | \n", "206 | \n", "NaN | \n", "FRM | \n", "798.0 | \n", "NaN | \n", "N | \n", "797.0 | \n", "283582.089552 | \n", "
| 2 | \n", "100043912941 | \n", "R | \n", "OTHER | \n", "4.125 | \n", "68000 | \n", "360 | \n", "12/2017 | \n", "02/2018 | \n", "66 | \n", "66 | \n", "... | \n", "P | \n", "OH | \n", "432 | \n", "NaN | \n", "FRM | \n", "NaN | \n", "NaN | \n", "N | \n", "804.0 | \n", "103030.303030 | \n", "
| 3 | \n", "100057175226 | \n", "R | \n", "OTHER | \n", "4.990 | \n", "71000 | \n", "360 | \n", "12/2017 | \n", "02/2018 | \n", "95 | \n", "95 | \n", "... | \n", "P | \n", "NC | \n", "278 | \n", "30.0 | \n", "FRM | \n", "NaN | \n", "1.0 | \n", "N | \n", "696.0 | \n", "74736.842105 | \n", "
| 4 | \n", "100060715643 | \n", "R | \n", "OTHER | \n", "4.500 | \n", "180000 | \n", "360 | \n", "12/2017 | \n", "02/2018 | \n", "75 | \n", "75 | \n", "... | \n", "I | \n", "WA | \n", "983 | \n", "NaN | \n", "FRM | \n", "NaN | \n", "NaN | \n", "N | \n", "726.0 | \n", "240000.000000 | \n", "
5 rows × 27 columns
\n", "| \n", " | seller_name | \n", "cscore_min | \n", "
|---|---|---|
| 2803 | \n", "JPMORGAN CHASE BANK, NATIONAL ASSOCIATION | \n", "724.0 | \n", "
| 3208 | \n", "JPMORGAN CHASE BANK, NATIONAL ASSOCIATION | \n", "744.0 | \n", "
| 8514 | \n", "JPMORGAN CHASE BANK, NATIONAL ASSOCIATION | \n", "695.0 | \n", "
| 10496 | \n", "JPMORGAN CHASE BANK, NATIONAL ASSOCIATION | \n", "738.0 | \n", "
| 10788 | \n", "JPMORGAN CHASE BANK, NATIONAL ASSOCIATION | \n", "701.0 | \n", "
| \n", " | seller_name | \n", "cscore_min | \n", "oltv | \n", "
|---|---|---|---|
| 125481 | \n", "JPMORGAN CHASE BANK, NATIONAL ASSOCIATION | \n", "800.0 | \n", "40 | \n", "
| 119447 | \n", "QUICKEN LOANS INC. | \n", "806.0 | \n", "50 | \n", "
| 58048 | \n", "WELLS FARGO BANK, N.A. | \n", "711.0 | \n", "54 | \n", "
| 126908 | \n", "QUICKEN LOANS INC. | \n", "704.0 | \n", "24 | \n", "
| 118737 | \n", "QUICKEN LOANS INC. | \n", "624.0 | \n", "68 | \n", "
| \n", " | seller_name | \n", "cscore_min | \n", "oltv | \n", "manual_color | \n", "
|---|---|---|---|---|
| 125481 | \n", "JPMORGAN CHASE BANK, NATIONAL ASSOCIATION | \n", "800.0 | \n", "40 | \n", "green | \n", "
| 119447 | \n", "QUICKEN LOANS INC. | \n", "806.0 | \n", "50 | \n", "blue | \n", "
| 58048 | \n", "WELLS FARGO BANK, N.A. | \n", "711.0 | \n", "54 | \n", "red | \n", "
| 126908 | \n", "QUICKEN LOANS INC. | \n", "704.0 | \n", "24 | \n", "blue | \n", "
| 118737 | \n", "QUICKEN LOANS INC. | \n", "624.0 | \n", "68 | \n", "blue | \n", "
\\n\"+\n", " \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n", " \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n", " \"
\\n\"+\n", " \"\\n\"+\n",
" \"from bokeh.resources import INLINE\\n\"+\n",
" \"output_notebook(resources=INLINE)\\n\"+\n",
" \"\\n\"+\n",
" \"\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"
\\n\"+\n \"\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"\\n\"+\n \"