{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2019-01-11T02:25:31.017751Z", "start_time": "2019-01-11T02:25:29.745525Z" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/vnd.plotly.v1+html": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Data science imports\n", "import pandas as pd\n", "import numpy as np\n", "\n", "# Options for pandas\n", "pd.options.display.max_columns = 20\n", "\n", "# Display all cell outputs\n", "from IPython.core.interactiveshell import InteractiveShell\n", "InteractiveShell.ast_node_interactivity = 'all'\n", "\n", "import plotly.plotly as py\n", "import plotly.graph_objs as go\n", "import cufflinks\n", "from plotly.offline import iplot\n", "cufflinks.go_offline()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2019-01-11T02:25:31.035299Z", "start_time": "2019-01-11T02:25:31.029778Z" } }, "outputs": [], "source": [ "def ecdf(df, x, grouper=None):\n", " \"\"\"\n", " Calculate empirical cumulative distribution function of a distribution\n", " \n", " :param df: dataframe\n", " :param x: string name of column\n", " :param grouper: string for column to groupby\n", " \n", " \"\"\"\n", " df = df.copy()\n", " \n", " if grouper is not None:\n", " new_dfs = []\n", " for group, grouped_data in df.groupby(grouper):\n", " grouped_data.sort_values(x, ascending=True, inplace=True)\n", " n = len(grouped_data)\n", " grouped_data['y'] = np.arange(1, n + 1, step = 1) / n\n", " new_dfs.append(grouped_data)\n", " return pd.concat(new_dfs)\n", " \n", " # Sort by the column for distribution\n", " df.sort_values(x, ascending=True, inplace=True)\n", " n = len(df)\n", " # Calculate percentiles\n", " df['y'] = np.arange(1, n + 1, step=1) / n\n", " return df" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2019-01-11T02:25:32.904642Z", "start_time": "2019-01-11T02:25:32.876203Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
yeargeo_namegeoincome
02013Alabama04000US0143253.0
12013Alaska04000US0270760.0
22013Arizona04000US0449774.0
32013Arkansas04000US0540768.0
42013California04000US0661094.0
\n", "
" ], "text/plain": [ " year geo_name geo income\n", "0 2013 Alabama 04000US01 43253.0\n", "1 2013 Alaska 04000US02 70760.0\n", "2 2013 Arizona 04000US04 49774.0\n", "3 2013 Arkansas 04000US05 40768.0\n", "4 2013 California 04000US06 61094.0" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "wages = pd.read_csv('data/us_state_wages.csv')\n", "wages.head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2019-01-04T03:12:15.780682Z", "start_time": "2019-01-04T03:12:15.735378Z" } }, "outputs": [], "source": [ "wages.tail()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2019-01-11T02:25:43.603147Z", "start_time": "2019-01-11T02:25:43.068604Z" } }, "outputs": [ { "data": { "text/plain": [ "(Scatter({\n", " 'marker': {'color': 'rgba(255, 153, 51, 1.0)', 'line': {'width': 1.3}, 'opacity': 0.8, 'size': 12, 'symbol': 'circle'},\n", " 'mode': 'markers+lines',\n", " 'name': '2015',\n", " 'textfont': {'color': '#4D5663'},\n", " 'uid': 'cbec7bad-c388-403a-87c2-bdd7258b9336',\n", " 'x': array([19350., 39665., 41371., 41751., 43623., 43740., 44963., 45047., 45219.,\n", " 45483., 46868., 46879., 47169., 47507., 47583., 48173., 49255., 49331.,\n", " 49429., 49576., 49620., 50255., 50957., 51243., 51847., 52205., 52997.,\n", " 53183., 53207., 53357., 53599., 55176., 56852., 57181., 57574., 58840.,\n", " 59269., 60509., 60629., 60727., 61062., 61492., 61818., 65015., 66779.,\n", " 68563., 69515., 70331., 70848., 72093., 72515., 74551.]),\n", " 'y': array([0.00480769, 0.03365385, 0.05769231, 0.06730769, 0.10096154, 0.10576923,\n", " 0.14423077, 0.16346154, 0.16826923, 0.17788462, 0.22596154, 0.23076923,\n", " 0.24519231, 0.26442308, 0.26923077, 0.28365385, 0.35096154, 0.35576923,\n", " 0.36538462, 0.375 , 0.38461538, 0.40384615, 0.4375 , 0.44711538,\n", " 0.47115385, 0.49519231, 0.53365385, 0.54807692, 0.55288462, 0.5625 ,\n", " 0.57211538, 0.61538462, 0.64423077, 0.65384615, 0.66346154, 0.69711538,\n", " 0.71634615, 0.75480769, 0.75961538, 0.76442308, 0.78365385, 0.79807692,\n", " 0.80288462, 0.84615385, 0.86538462, 0.89423077, 0.90865385, 0.91826923,\n", " 0.92788462, 0.96153846, 0.96634615, 0.99519231])\n", " }), Scatter({\n", " 'marker': {'color': 'rgba(55, 128, 191, 1.0)', 'line': {'width': 1.3}, 'opacity': 0.8, 'size': 12, 'symbol': 'circle'},\n", " 'mode': 'markers+lines',\n", " 'name': '2016',\n", " 'textfont': {'color': '#4D5663'},\n", " 'uid': '194626a5-9613-4ec4-8bc1-aa5406a8b76a',\n", " 'x': array([19606., 40528., 42336., 42644., 44758., 44811., 45652., 45674., 46574.,\n", " 46898., 48038., 48256., 48380., 48900., 49174., 49593., 50433., 50674.,\n", " 50803., 50826., 51037., 51340., 52078., 53094., 53270., 53571., 54384.,\n", " 54570., 54610., 54727., 54895., 56104., 58387., 59114., 59143., 59196.,\n", " 60741., 61017., 62518., 62520., 62848., 63217., 63783., 66149., 68485.,\n", " 70954., 71755., 71977., 72935., 73702., 74444., 76067.]),\n", " 'y': array([0.00961538, 0.03846154, 0.07211538, 0.07692308, 0.12019231, 0.12980769,\n", " 0.18269231, 0.1875 , 0.20673077, 0.23557692, 0.27884615, 0.29326923,\n", " 0.30288462, 0.33173077, 0.34134615, 0.37980769, 0.41346154, 0.42307692,\n", " 0.42788462, 0.43269231, 0.44230769, 0.45673077, 0.48557692, 0.53846154,\n", " 0.55769231, 0.56730769, 0.58653846, 0.59615385, 0.60096154, 0.60576923,\n", " 0.61057692, 0.625 , 0.67788462, 0.70192308, 0.70673077, 0.71153846,\n", " 0.76923077, 0.77884615, 0.80769231, 0.8125 , 0.81730769, 0.82211538,\n", " 0.82692308, 0.86057692, 0.88942308, 0.93269231, 0.94230769, 0.95192308,\n", " 0.97115385, 0.98076923, 0.99038462, 1. ])\n", " }), Scatter({\n", " 'marker': {'color': 'rgba(50, 171, 96, 1.0)', 'line': {'width': 1.3}, 'opacity': 0.8, 'size': 12, 'symbol': 'circle'},\n", " 'mode': 'markers+lines',\n", " 'name': '2013',\n", " 'textfont': {'color': '#4D5663'},\n", " 'uid': '713dac66-c535-44e4-ba38-02fa3b64915b',\n", " 'x': array([19624., 39031., 40768., 41043., 43036., 43253., 44298., 44779., 44874.,\n", " 44927., 45339., 46230., 46334., 46767., 46956., 47380., 48248., 48308.,\n", " 48411., 48453., 49179., 49495., 49774., 50229., 51332., 51672., 51843.,\n", " 51900., 52413., 52548., 52800., 53741., 54267., 56361., 56797., 57406.,\n", " 58003., 58433., 58821., 59478., 59836., 59878., 61094., 63907., 64916.,\n", " 65830., 66866., 67402., 69461., 70760., 71629., 73538.]),\n", " 'y': array([0.01442308, 0.02403846, 0.04326923, 0.04807692, 0.08173077, 0.08653846,\n", " 0.11057692, 0.125 , 0.13461538, 0.13942308, 0.17307692, 0.19230769,\n", " 0.20192308, 0.22115385, 0.24038462, 0.25961538, 0.28846154, 0.29807692,\n", " 0.30769231, 0.3125 , 0.34615385, 0.37019231, 0.38942308, 0.39903846,\n", " 0.45192308, 0.46153846, 0.46634615, 0.48076923, 0.50480769, 0.50961538,\n", " 0.52884615, 0.57692308, 0.58173077, 0.62980769, 0.63942308, 0.65865385,\n", " 0.66826923, 0.68269231, 0.69230769, 0.72596154, 0.73076923, 0.74038462,\n", " 0.78846154, 0.83173077, 0.84134615, 0.85096154, 0.87019231, 0.875 ,\n", " 0.90384615, 0.92307692, 0.9375 , 0.97596154])\n", " }), Scatter({\n", " 'marker': {'color': 'rgba(128, 0, 128, 1.0)', 'line': {'width': 1.3}, 'opacity': 0.8, 'size': 12, 'symbol': 'circle'},\n", " 'mode': 'markers+lines',\n", " 'name': '2014',\n", " 'textfont': {'color': '#4D5663'},\n", " 'uid': 'f6311eb6-d130-4322-872c-a224ee1cb597',\n", " 'x': array([19686., 39464., 41264., 41576., 43342., 43511., 44621., 44968., 44991.,\n", " 45033., 46235., 46693., 46766., 47212., 47334., 47764., 48737., 48804.,\n", " 48849., 49087., 49342., 49928., 50338., 50521., 51872., 52205., 52400.,\n", " 52576., 52716., 52738., 53115., 54447., 55579., 56423., 57166., 58252.,\n", " 58687., 59448., 59846., 60231., 60294., 60828., 61489., 64792., 65986.,\n", " 67846., 68201., 69235., 69899., 71829., 72062., 74149.]),\n", " 'y': array([0.01923077, 0.02884615, 0.05288462, 0.0625 , 0.09134615, 0.09615385,\n", " 0.11538462, 0.14903846, 0.15384615, 0.15865385, 0.19711538, 0.21153846,\n", " 0.21634615, 0.25 , 0.25480769, 0.27403846, 0.31730769, 0.32211538,\n", " 0.32692308, 0.33653846, 0.36057692, 0.39423077, 0.40865385, 0.41826923,\n", " 0.47596154, 0.49038462, 0.5 , 0.51442308, 0.51923077, 0.52403846,\n", " 0.54326923, 0.59134615, 0.62019231, 0.63461538, 0.64903846, 0.67307692,\n", " 0.6875 , 0.72115385, 0.73557692, 0.74519231, 0.75 , 0.77403846,\n", " 0.79326923, 0.83653846, 0.85576923, 0.87980769, 0.88461538, 0.89903846,\n", " 0.91346154, 0.94711538, 0.95673077, 0.98557692])\n", " }))" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "figure = df.iplot(x='income', y='y', mode='markers+lines', categories='year', hline=[0.5],\n", " xTitle='income', yTitle='percentile', title='ECDF of Wages in US states', asFigure=True)\n", "figure.data" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2019-01-11T02:25:46.488061Z", "start_time": "2019-01-11T02:25:46.483854Z" } }, "outputs": [ { "data": { "text/plain": [ "(layout.Shape({\n", " 'line': {'color': '#db4052', 'dash': 'solid', 'width': 1},\n", " 'type': 'line',\n", " 'x0': 0,\n", " 'x1': 1,\n", " 'xref': 'paper',\n", " 'y0': 0.5,\n", " 'y1': 0.5,\n", " 'yref': 'y'\n", " }),)" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "figure.layout.shapes" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2019-01-11T02:25:42.051300Z", "start_time": "2019-01-11T02:25:41.846021Z" } }, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "linkText": "Export to plot.ly", "plotlyServerURL": "https://plot.ly", "showLink": true }, "data": [ { "marker": { "color": "rgba(255, 153, 51, 1.0)", "line": { "width": 1.3 }, "opacity": 0.8, "size": 12, "symbol": "circle" }, "mode": "markers+lines", "name": "2015", "textfont": { "color": "#4D5663" }, "type": "scatter", "x": [ 19350, 39665, 41371, 41751, 43623, 43740, 44963, 45047, 45219, 45483, 46868, 46879, 47169, 47507, 47583, 48173, 49255, 49331, 49429, 49576, 49620, 50255, 50957, 51243, 51847, 52205, 52997, 53183, 53207, 53357, 53599, 55176, 56852, 57181, 57574, 58840, 59269, 60509, 60629, 60727, 61062, 61492, 61818, 65015, 66779, 68563, 69515, 70331, 70848, 72093, 72515, 74551 ], "y": [ 0.004807692307692308, 0.03365384615384615, 0.057692307692307696, 0.0673076923076923, 0.10096153846153846, 0.10576923076923077, 0.14423076923076922, 0.16346153846153846, 0.16826923076923078, 0.1778846153846154, 0.22596153846153846, 0.23076923076923078, 0.24519230769230768, 0.2644230769230769, 0.2692307692307692, 0.28365384615384615, 0.35096153846153844, 0.3557692307692308, 0.36538461538461536, 0.375, 0.38461538461538464, 0.40384615384615385, 0.4375, 0.44711538461538464, 0.47115384615384615, 0.4951923076923077, 0.5336538461538461, 0.5480769230769231, 0.5528846153846154, 0.5625, 0.5721153846153846, 0.6153846153846154, 0.6442307692307693, 0.6538461538461539, 0.6634615384615384, 0.6971153846153846, 0.7163461538461539, 0.7548076923076923, 0.7596153846153846, 0.7644230769230769, 0.7836538461538461, 0.7980769230769231, 0.8028846153846154, 0.8461538461538461, 0.8653846153846154, 0.8942307692307693, 0.9086538461538461, 0.9182692307692307, 0.9278846153846154, 0.9615384615384616, 0.9663461538461539, 0.9951923076923077 ] }, { "marker": { "color": "rgba(55, 128, 191, 1.0)", "line": { "width": 1.3 }, "opacity": 0.8, "size": 12, "symbol": "circle" }, "mode": "markers+lines", "name": "2016", "textfont": { "color": "#4D5663" }, "type": "scatter", "x": [ 19606, 40528, 42336, 42644, 44758, 44811, 45652, 45674, 46574, 46898, 48038, 48256, 48380, 48900, 49174, 49593, 50433, 50674, 50803, 50826, 51037, 51340, 52078, 53094, 53270, 53571, 54384, 54570, 54610, 54727, 54895, 56104, 58387, 59114, 59143, 59196, 60741, 61017, 62518, 62520, 62848, 63217, 63783, 66149, 68485, 70954, 71755, 71977, 72935, 73702, 74444, 76067 ], "y": [ 0.009615384615384616, 0.038461538461538464, 0.07211538461538461, 0.07692307692307693, 0.1201923076923077, 0.12980769230769232, 0.18269230769230768, 0.1875, 0.20673076923076922, 0.23557692307692307, 0.27884615384615385, 0.2932692307692308, 0.30288461538461536, 0.3317307692307692, 0.34134615384615385, 0.3798076923076923, 0.41346153846153844, 0.4230769230769231, 0.42788461538461536, 0.4326923076923077, 0.4423076923076923, 0.4567307692307692, 0.4855769230769231, 0.5384615384615384, 0.5576923076923077, 0.5673076923076923, 0.5865384615384616, 0.5961538461538461, 0.6009615384615384, 0.6057692307692307, 0.6105769230769231, 0.625, 0.6778846153846154, 0.7019230769230769, 0.7067307692307693, 0.7115384615384616, 0.7692307692307693, 0.7788461538461539, 0.8076923076923077, 0.8125, 0.8173076923076923, 0.8221153846153846, 0.8269230769230769, 0.8605769230769231, 0.8894230769230769, 0.9326923076923077, 0.9423076923076923, 0.9519230769230769, 0.9711538461538461, 0.9807692307692307, 0.9903846153846154, 1 ] }, { "marker": { "color": "rgba(50, 171, 96, 1.0)", "line": { "width": 1.3 }, "opacity": 0.8, "size": 12, "symbol": "circle" }, "mode": "markers+lines", "name": "2013", "textfont": { "color": "#4D5663" }, "type": "scatter", "x": [ 19624, 39031, 40768, 41043, 43036, 43253, 44298, 44779, 44874, 44927, 45339, 46230, 46334, 46767, 46956, 47380, 48248, 48308, 48411, 48453, 49179, 49495, 49774, 50229, 51332, 51672, 51843, 51900, 52413, 52548, 52800, 53741, 54267, 56361, 56797, 57406, 58003, 58433, 58821, 59478, 59836, 59878, 61094, 63907, 64916, 65830, 66866, 67402, 69461, 70760, 71629, 73538 ], "y": [ 0.014423076923076924, 0.02403846153846154, 0.04326923076923077, 0.04807692307692308, 0.08173076923076923, 0.08653846153846154, 0.11057692307692307, 0.125, 0.1346153846153846, 0.13942307692307693, 0.17307692307692307, 0.19230769230769232, 0.20192307692307693, 0.22115384615384615, 0.2403846153846154, 0.25961538461538464, 0.28846153846153844, 0.2980769230769231, 0.3076923076923077, 0.3125, 0.34615384615384615, 0.3701923076923077, 0.3894230769230769, 0.39903846153846156, 0.4519230769230769, 0.46153846153846156, 0.46634615384615385, 0.4807692307692308, 0.5048076923076923, 0.5096153846153846, 0.5288461538461539, 0.5769230769230769, 0.5817307692307693, 0.6298076923076923, 0.6394230769230769, 0.6586538461538461, 0.6682692307692307, 0.6826923076923077, 0.6923076923076923, 0.7259615384615384, 0.7307692307692307, 0.7403846153846154, 0.7884615384615384, 0.8317307692307693, 0.8413461538461539, 0.8509615384615384, 0.8701923076923077, 0.875, 0.9038461538461539, 0.9230769230769231, 0.9375, 0.9759615384615384 ] }, { "marker": { "color": "rgba(128, 0, 128, 1.0)", "line": { "width": 1.3 }, "opacity": 0.8, "size": 12, "symbol": "circle" }, "mode": "markers+lines", "name": "2014", "textfont": { "color": "#4D5663" }, "type": "scatter", "x": [ 19686, 39464, 41264, 41576, 43342, 43511, 44621, 44968, 44991, 45033, 46235, 46693, 46766, 47212, 47334, 47764, 48737, 48804, 48849, 49087, 49342, 49928, 50338, 50521, 51872, 52205, 52400, 52576, 52716, 52738, 53115, 54447, 55579, 56423, 57166, 58252, 58687, 59448, 59846, 60231, 60294, 60828, 61489, 64792, 65986, 67846, 68201, 69235, 69899, 71829, 72062, 74149 ], "y": [ 0.019230769230769232, 0.028846153846153848, 0.052884615384615384, 0.0625, 0.09134615384615384, 0.09615384615384616, 0.11538461538461539, 0.14903846153846154, 0.15384615384615385, 0.15865384615384615, 0.1971153846153846, 0.21153846153846154, 0.21634615384615385, 0.25, 0.2548076923076923, 0.27403846153846156, 0.3173076923076923, 0.32211538461538464, 0.3269230769230769, 0.33653846153846156, 0.3605769230769231, 0.3942307692307692, 0.40865384615384615, 0.4182692307692308, 0.47596153846153844, 0.49038461538461536, 0.5, 0.5144230769230769, 0.5192307692307693, 0.5240384615384616, 0.5432692307692307, 0.5913461538461539, 0.6201923076923077, 0.6346153846153846, 0.6490384615384616, 0.6730769230769231, 0.6875, 0.7211538461538461, 0.7355769230769231, 0.7451923076923077, 0.75, 0.7740384615384616, 0.7932692307692307, 0.8365384615384616, 0.8557692307692307, 0.8798076923076923, 0.8846153846153846, 0.8990384615384616, 0.9134615384615384, 0.9471153846153846, 0.9567307692307693, 0.9855769230769231 ] } ], "layout": { "legend": { "bgcolor": "#F5F6F9", "font": { "color": "#4D5663" } }, "paper_bgcolor": "#F5F6F9", "plot_bgcolor": "#F5F6F9", "shapes": [ { "line": { "color": "#db4052", "dash": "solid", "width": 1 }, "type": "line", "x0": 0, "x1": 1, "xref": "paper", "y0": 0.5, "y1": 0.5, "yref": "y" } ], "title": "ECDF of Wages in US states", "titlefont": { "color": "#4D5663" }, "xaxis": { "gridcolor": "#E1E5ED", "showgrid": true, "tickfont": { "color": "#4D5663" }, "title": "income", "titlefont": { "color": "#4D5663" }, "zerolinecolor": "#E1E5ED" }, "yaxis": { "gridcolor": "#E1E5ED", "showgrid": true, "tickfont": { "color": "#4D5663" }, "title": "percentile", "titlefont": { "color": "#4D5663" }, "zerolinecolor": "#E1E5ED" } } }, "text/html": [ "
" ], "text/vnd.plotly.v1+html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "df = ecdf(wages, 'income')\n", "df['year'] = df['year'].astype(str)\n", "df.iplot(x='income', y='y', mode='markers+lines', categories='year', hline=[0.5],\n", " xTitle='income', yTitle='percentile', title='ECDF of Wages in US states')" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "ExecuteTime": { "end_time": "2019-01-11T02:26:04.448652Z", "start_time": "2019-01-11T02:26:04.297191Z" } }, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "linkText": "Export to plot.ly", "plotlyServerURL": "https://plot.ly", "showLink": true }, "data": [ { "marker": { "color": "rgba(255, 153, 51, 1.0)", "line": { "width": 1.3 }, "opacity": 0.8, "size": 12, "symbol": "circle" }, "mode": "markers+lines", "name": "2013", "textfont": { "color": "#4D5663" }, "type": "scatter", "uid": "9b299a0d-097e-4039-8a59-6979e70b4b03", "x": [ 19624, 39031, 40768, 41043, 43036, 43253, 44298, 44779, 44874, 44927, 45339, 46230, 46334, 46767, 46956, 47380, 48248, 48308, 48411, 48453, 49179, 49495, 49774, 50229, 51332, 51672, 51843, 51900, 52413, 52548, 52800, 53741, 54267, 56361, 56797, 57406, 58003, 58433, 58821, 59478, 59836, 59878, 61094, 63907, 64916, 65830, 66866, 67402, 69461, 70760, 71629, 73538 ], "y": [ 0.019230769230769232, 0.038461538461538464, 0.057692307692307696, 0.07692307692307693, 0.09615384615384616, 0.11538461538461539, 0.1346153846153846, 0.15384615384615385, 0.17307692307692307, 0.19230769230769232, 0.21153846153846154, 0.23076923076923078, 0.25, 0.2692307692307692, 0.28846153846153844, 0.3076923076923077, 0.3269230769230769, 0.34615384615384615, 0.36538461538461536, 0.38461538461538464, 0.40384615384615385, 0.4230769230769231, 0.4423076923076923, 0.46153846153846156, 0.4807692307692308, 0.5, 0.5192307692307693, 0.5384615384615384, 0.5576923076923077, 0.5769230769230769, 0.5961538461538461, 0.6153846153846154, 0.6346153846153846, 0.6538461538461539, 0.6730769230769231, 0.6923076923076923, 0.7115384615384616, 0.7307692307692307, 0.75, 0.7692307692307693, 0.7884615384615384, 0.8076923076923077, 0.8269230769230769, 0.8461538461538461, 0.8653846153846154, 0.8846153846153846, 0.9038461538461539, 0.9230769230769231, 0.9423076923076923, 0.9615384615384616, 0.9807692307692307, 1 ] }, { "marker": { "color": "rgba(55, 128, 191, 1.0)", "line": { "width": 1.3 }, "opacity": 0.8, "size": 12, "symbol": "circle" }, "mode": "markers+lines", "name": "2014", "textfont": { "color": "#4D5663" }, "type": "scatter", "uid": "2f2df6da-21fc-4c13-90db-c811a0be59ee", "x": [ 19686, 39464, 41264, 41576, 43342, 43511, 44621, 44968, 44991, 45033, 46235, 46693, 46766, 47212, 47334, 47764, 48737, 48804, 48849, 49087, 49342, 49928, 50338, 50521, 51872, 52205, 52400, 52576, 52716, 52738, 53115, 54447, 55579, 56423, 57166, 58252, 58687, 59448, 59846, 60231, 60294, 60828, 61489, 64792, 65986, 67846, 68201, 69235, 69899, 71829, 72062, 74149 ], "y": [ 0.019230769230769232, 0.038461538461538464, 0.057692307692307696, 0.07692307692307693, 0.09615384615384616, 0.11538461538461539, 0.1346153846153846, 0.15384615384615385, 0.17307692307692307, 0.19230769230769232, 0.21153846153846154, 0.23076923076923078, 0.25, 0.2692307692307692, 0.28846153846153844, 0.3076923076923077, 0.3269230769230769, 0.34615384615384615, 0.36538461538461536, 0.38461538461538464, 0.40384615384615385, 0.4230769230769231, 0.4423076923076923, 0.46153846153846156, 0.4807692307692308, 0.5, 0.5192307692307693, 0.5384615384615384, 0.5576923076923077, 0.5769230769230769, 0.5961538461538461, 0.6153846153846154, 0.6346153846153846, 0.6538461538461539, 0.6730769230769231, 0.6923076923076923, 0.7115384615384616, 0.7307692307692307, 0.75, 0.7692307692307693, 0.7884615384615384, 0.8076923076923077, 0.8269230769230769, 0.8461538461538461, 0.8653846153846154, 0.8846153846153846, 0.9038461538461539, 0.9230769230769231, 0.9423076923076923, 0.9615384615384616, 0.9807692307692307, 1 ] }, { "marker": { "color": "rgba(50, 171, 96, 1.0)", "line": { "width": 1.3 }, "opacity": 0.8, "size": 12, "symbol": "circle" }, "mode": "markers+lines", "name": "2015", "textfont": { "color": "#4D5663" }, "type": "scatter", "uid": "4d896937-4be5-4f1b-957b-2d39560204f4", "x": [ 19350, 39665, 41371, 41751, 43623, 43740, 44963, 45047, 45219, 45483, 46868, 46879, 47169, 47507, 47583, 48173, 49255, 49331, 49429, 49576, 49620, 50255, 50957, 51243, 51847, 52205, 52997, 53183, 53207, 53357, 53599, 55176, 56852, 57181, 57574, 58840, 59269, 60509, 60629, 60727, 61062, 61492, 61818, 65015, 66779, 68563, 69515, 70331, 70848, 72093, 72515, 74551 ], "y": [ 0.019230769230769232, 0.038461538461538464, 0.057692307692307696, 0.07692307692307693, 0.09615384615384616, 0.11538461538461539, 0.1346153846153846, 0.15384615384615385, 0.17307692307692307, 0.19230769230769232, 0.21153846153846154, 0.23076923076923078, 0.25, 0.2692307692307692, 0.28846153846153844, 0.3076923076923077, 0.3269230769230769, 0.34615384615384615, 0.36538461538461536, 0.38461538461538464, 0.40384615384615385, 0.4230769230769231, 0.4423076923076923, 0.46153846153846156, 0.4807692307692308, 0.5, 0.5192307692307693, 0.5384615384615384, 0.5576923076923077, 0.5769230769230769, 0.5961538461538461, 0.6153846153846154, 0.6346153846153846, 0.6538461538461539, 0.6730769230769231, 0.6923076923076923, 0.7115384615384616, 0.7307692307692307, 0.75, 0.7692307692307693, 0.7884615384615384, 0.8076923076923077, 0.8269230769230769, 0.8461538461538461, 0.8653846153846154, 0.8846153846153846, 0.9038461538461539, 0.9230769230769231, 0.9423076923076923, 0.9615384615384616, 0.9807692307692307, 1 ] }, { "marker": { "color": "rgba(128, 0, 128, 1.0)", "line": { "width": 1.3 }, "opacity": 0.8, "size": 12, "symbol": "circle" }, "mode": "markers+lines", "name": "2016", "textfont": { "color": "#4D5663" }, "type": "scatter", "uid": "031abfec-2d97-4632-a304-6a089687c8fb", "x": [ 19606, 40528, 42336, 42644, 44758, 44811, 45652, 45674, 46574, 46898, 48038, 48256, 48380, 48900, 49174, 49593, 50433, 50674, 50803, 50826, 51037, 51340, 52078, 53094, 53270, 53571, 54384, 54570, 54610, 54727, 54895, 56104, 58387, 59114, 59143, 59196, 60741, 61017, 62518, 62520, 62848, 63217, 63783, 66149, 68485, 70954, 71755, 71977, 72935, 73702, 74444, 76067 ], "y": [ 0.019230769230769232, 0.038461538461538464, 0.057692307692307696, 0.07692307692307693, 0.09615384615384616, 0.11538461538461539, 0.1346153846153846, 0.15384615384615385, 0.17307692307692307, 0.19230769230769232, 0.21153846153846154, 0.23076923076923078, 0.25, 0.2692307692307692, 0.28846153846153844, 0.3076923076923077, 0.3269230769230769, 0.34615384615384615, 0.36538461538461536, 0.38461538461538464, 0.40384615384615385, 0.4230769230769231, 0.4423076923076923, 0.46153846153846156, 0.4807692307692308, 0.5, 0.5192307692307693, 0.5384615384615384, 0.5576923076923077, 0.5769230769230769, 0.5961538461538461, 0.6153846153846154, 0.6346153846153846, 0.6538461538461539, 0.6730769230769231, 0.6923076923076923, 0.7115384615384616, 0.7307692307692307, 0.75, 0.7692307692307693, 0.7884615384615384, 0.8076923076923077, 0.8269230769230769, 0.8461538461538461, 0.8653846153846154, 0.8846153846153846, 0.9038461538461539, 0.9230769230769231, 0.9423076923076923, 0.9615384615384616, 0.9807692307692307, 1 ] } ], "layout": { "legend": { "bgcolor": "#F5F6F9", "font": { "color": "#4D5663" } }, "paper_bgcolor": "#F5F6F9", "plot_bgcolor": "#F5F6F9", "title": "ECDF of Wages in US states", "titlefont": { "color": "#4D5663" }, "xaxis": { "gridcolor": "#E1E5ED", "showgrid": true, "tickfont": { "color": "#4D5663" }, "title": "income", "titlefont": { "color": "#4D5663" }, "zerolinecolor": "#E1E5ED" }, "yaxis": { "gridcolor": "#E1E5ED", "showgrid": true, "tickfont": { "color": "#4D5663" }, "title": "percentile", "titlefont": { "color": "#4D5663" }, "zerolinecolor": "#E1E5ED" } } }, "text/html": [ "
" ], "text/vnd.plotly.v1+html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "df = ecdf(wages, 'income', grouper='year')\n", "df['year'] = df['year'].astype(str)\n", "df.iplot(x='income', y='y', mode='markers+lines', categories='year',\n", " xTitle='income', yTitle='percentile', title='ECDF of Wages in US states')" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "ExecuteTime": { "end_time": "2019-01-11T02:26:11.640618Z", "start_time": "2019-01-11T02:26:11.637846Z" } }, "outputs": [], "source": [ "df = wages.copy()" ] }, { "cell_type": "code", "execution_count": 70, "metadata": { "ExecuteTime": { "end_time": "2019-01-11T02:43:20.618287Z", "start_time": "2019-01-11T02:43:20.613267Z" } }, "outputs": [ { "data": { "text/plain": [ "0.5769230769230769" ] }, "execution_count": 70, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.loc[(df[x] - df[x].mean()).abs().idxmin(), 'y']" ] }, { "cell_type": "code", "execution_count": 71, "metadata": { "ExecuteTime": { "end_time": "2019-01-11T02:43:30.566715Z", "start_time": "2019-01-11T02:43:30.483368Z" } }, "outputs": [], "source": [ "x = 'income'\n", "text = 'geo_name'\n", "grouper = None\n", "title_override = None\n", "\n", "df = ecdf(df, x, grouper=grouper)\n", "\n", "if grouper is not None:\n", " data = [\n", " go.Scatter(\n", " x=grouped_data[x],\n", " y=grouped_data['y'],\n", " mode='markers+lines',\n", " marker=dict(opacity=0.6, line=dict(color='black', width=2)),\n", " text=grouped_data[text],\n", " name=group) for group, grouped_data in df.groupby(grouper)\n", " ]\n", "\n", "else:\n", " data = [\n", " go.Scatter(\n", " x=df[x],\n", " y=df['y'],\n", " mode='markers+lines',\n", " marker=dict(\n", " color='blue', opacity=0.6, line=dict(color='black', width=2)),\n", " text=df[text])\n", " ]\n", "\n", "quantiles = [0.25, 0.5, 0.75]\n", " \n", "shapes = [go.layout.Shape(type='line', x0=0, x1=1, y0=q, y1=q, xref='paper', yref='y',\n", " line=dict(width=2.1, color = 'red', dash='dash')) for q in quantiles]\n", "\n", "annotations = [go.layout.Annotation(x=0, y=q + 0.05, showarrow=False,\n", " xanchor='left', font=dict(size=14), xshift=20,\n", " text=f'{q}: {df[x].quantile(q):.2f}') for q in quantiles]\n", "\n", "annotations.append(go.layout.Annotation(x=df[x].min(), font=dict(size=14), \n", " y=0.05, text=f'Min: {df[x].min():.2f}'))\n", "annotations.append(go.layout.Annotation(x=df[x].max(), font=dict(size=14),\n", " y=1, text=f'Max: {df[x].max():.2f}'))\n", "annotations.append(go.layout.Annotation(x=df[x].mean(), font=dict(size=14),\n", " y=df.loc[(df[x] - df[x].mean()).abs().idxmin(), 'y'], \n", " text=f'Mean: {df[x].mean():.2f}'))\n", "\n", "x_nice = x.replace('_', '').title()\n", "layout = go.Layout(\n", " annotations=annotations,\n", " shapes=shapes,\n", " xaxis=dict(title=x_nice),\n", " yaxis=dict(title='percentile'),\n", " title=f'ECDF of {x_nice}' if title_override is None else title_override)\n", "\n", "figure = go.Figure(data=data, layout=layout)" ] }, { "cell_type": "code", "execution_count": 72, "metadata": { "ExecuteTime": { "end_time": "2019-01-11T02:43:31.600620Z", "start_time": "2019-01-11T02:43:31.596254Z" } }, "outputs": [ { "data": { "text/plain": [ "[layout.Annotation({\n", " 'font': {'size': 14}, 'showarrow': False, 'text': '0.25: 47303.50', 'x': 0, 'xanchor': 'left', 'xshift': 20, 'y': 0.3\n", " }), layout.Annotation({\n", " 'font': {'size': 14}, 'showarrow': False, 'text': '0.5: 52406.50', 'x': 0, 'xanchor': 'left', 'xshift': 20, 'y': 0.55\n", " }), layout.Annotation({\n", " 'font': {'size': 14}, 'showarrow': False, 'text': '0.75: 60347.75', 'x': 0, 'xanchor': 'left', 'xshift': 20, 'y': 0.8\n", " }), layout.Annotation({\n", " 'font': {'size': 14}, 'text': 'Min: 19350.00', 'x': 19350.0, 'y': 0.05\n", " }), layout.Annotation({\n", " 'font': {'size': 14}, 'text': 'Max: 76067.00', 'x': 76067.0, 'y': 1\n", " }), layout.Annotation({\n", " 'font': {'size': 14}, 'text': 'Mean: 53908.78', 'x': 53908.778846153844, 'y': 0.5769230769230769\n", " })]" ] }, "execution_count": 72, "metadata": {}, "output_type": "execute_result" } ], "source": [ "annotations" ] }, { "cell_type": "code", "execution_count": 73, "metadata": { "ExecuteTime": { "end_time": "2019-01-11T02:43:32.759537Z", "start_time": "2019-01-11T02:43:32.749425Z" } }, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "linkText": "Export to plot.ly", "plotlyServerURL": "https://plot.ly", "showLink": true }, "data": [ { "marker": { "color": "blue", "line": { "color": "black", "width": 2 }, "opacity": 0.6 }, "mode": "markers+lines", "text": [ "Puerto Rico", "Puerto Rico", "Puerto Rico", "Puerto Rico", "Mississippi", "Mississippi", "Mississippi", "Mississippi", "Arkansas", "West Virginia", "Arkansas", "Arkansas", "West Virginia", "West Virginia", "Arkansas", "West Virginia", "Kentucky", "Alabama", "Kentucky", "Alabama", "Alabama", "Kentucky", "Tennessee", "Tennessee", "Alabama", "South Carolina", "Kentucky", "Louisiana", "New Mexico", "New Mexico", "New Mexico", "Louisiana", "South Carolina", "Louisiana", "Tennessee", "Oklahoma", "South Carolina", "Louisiana", "New Mexico", "Montana", "Oklahoma", "North Carolina", "Tennessee", "North Carolina", "Montana", "Idaho", "North Carolina", "Oklahoma", "South Carolina", "Florida", "Montana", "Florida", "Idaho", "Missouri", "Florida", "Idaho", "Missouri", "Oklahoma", "Missouri", "Indiana", "North Carolina", "Ohio", "Montana", "Michigan", "Maine", "Indiana", "Maine", "Ohio", "Florida", "Michigan", "Idaho", "Georgia", "Indiana", "Maine", "Georgia", "Ohio", "South Dakota", "Michigan", "Missouri", "Georgia", "Arizona", "Arizona", "Oregon", "Arizona", "South Dakota", "Indiana", "Oregon", "Ohio", "Michigan", "Maine", "South Dakota", "Georgia", "Oregon", "Kansas", "Arizona", "Nebraska", "Iowa", "Nevada", "Kansas", "Texas", "South Dakota", "Nevada", "Kansas", "Nebraska", "Wisconsin", "Pennsylvania", "Texas", "Iowa", "Wisconsin", "Nevada", "Nebraska", "Nevada", "Pennsylvania", "Iowa", "Texas", "Oregon", "Wisconsin", "Kansas", "Pennsylvania", "North Dakota", "Vermont", "Nebraska", "Vermont", "Iowa", "Wisconsin", "Texas", "Pennsylvania", "Vermont", "North Dakota", "Vermont", "Rhode Island", "Rhode Island", "Illinois", "Rhode Island", "Illinois", "North Dakota", "Wyoming", "Illinois", "New York", "Wyoming", "Rhode Island", "Colorado", "New York", "Utah", "Wyoming", "North Dakota", "Wyoming", "Illinois", "New York", "Colorado", "Washington", "Minnesota", "Utah", "Delaware", "Delaware", "Washington", "Delaware", "Colorado", "Utah", "New York", "Minnesota", "Delaware", "Washington", "California", "California", "Minnesota", "California", "Utah", "Colorado", "Washington", "Minnesota", "California", "Virginia", "Virginia", "New Hampshire", "Virginia", "District of Columbia", "New Hampshire", "Virginia", "New Hampshire", "Massachusetts", "Hawaii", "Massachusetts", "Hawaii", "New Hampshire", "Massachusetts", "District of Columbia", "Connecticut", "Hawaii", "Connecticut", "Connecticut", "Alaska", "District of Columbia", "Massachusetts", "New Jersey", "Connecticut", "Alaska", "Hawaii", "New Jersey", "New Jersey", "Alaska", "District of Columbia", "Maryland", "New Jersey", "Maryland", "Alaska", "Maryland", "Maryland" ], "type": "scatter", "uid": "1add18e7-56ab-4b2c-8024-12fae1d6637e", "x": [ 19350, 19606, 19624, 19686, 39031, 39464, 39665, 40528, 40768, 41043, 41264, 41371, 41576, 41751, 42336, 42644, 43036, 43253, 43342, 43511, 43623, 43740, 44298, 44621, 44758, 44779, 44811, 44874, 44927, 44963, 44968, 44991, 45033, 45047, 45219, 45339, 45483, 45652, 45674, 46230, 46235, 46334, 46574, 46693, 46766, 46767, 46868, 46879, 46898, 46956, 47169, 47212, 47334, 47380, 47507, 47583, 47764, 48038, 48173, 48248, 48256, 48308, 48380, 48411, 48453, 48737, 48804, 48849, 48900, 49087, 49174, 49179, 49255, 49331, 49342, 49429, 49495, 49576, 49593, 49620, 49774, 49928, 50229, 50255, 50338, 50433, 50521, 50674, 50803, 50826, 50957, 51037, 51243, 51332, 51340, 51672, 51843, 51847, 51872, 51900, 52078, 52205, 52205, 52400, 52413, 52548, 52576, 52716, 52738, 52800, 52997, 53094, 53115, 53183, 53207, 53270, 53357, 53571, 53599, 53741, 54267, 54384, 54447, 54570, 54610, 54727, 54895, 55176, 55579, 56104, 56361, 56423, 56797, 56852, 57166, 57181, 57406, 57574, 58003, 58252, 58387, 58433, 58687, 58821, 58840, 59114, 59143, 59196, 59269, 59448, 59478, 59836, 59846, 59878, 60231, 60294, 60509, 60629, 60727, 60741, 60828, 61017, 61062, 61094, 61489, 61492, 61818, 62518, 62520, 62848, 63217, 63783, 63907, 64792, 64916, 65015, 65830, 65986, 66149, 66779, 66866, 67402, 67846, 68201, 68485, 68563, 69235, 69461, 69515, 69899, 70331, 70760, 70848, 70954, 71629, 71755, 71829, 71977, 72062, 72093, 72515, 72935, 73538, 73702, 74149, 74444, 74551, 76067 ], "y": [ 0.004807692307692308, 0.009615384615384616, 0.014423076923076924, 0.019230769230769232, 0.02403846153846154, 0.028846153846153848, 0.03365384615384615, 0.038461538461538464, 0.04326923076923077, 0.04807692307692308, 0.052884615384615384, 0.057692307692307696, 0.0625, 0.0673076923076923, 0.07211538461538461, 0.07692307692307693, 0.08173076923076923, 0.08653846153846154, 0.09134615384615384, 0.09615384615384616, 0.10096153846153846, 0.10576923076923077, 0.11057692307692307, 0.11538461538461539, 0.1201923076923077, 0.125, 0.12980769230769232, 0.1346153846153846, 0.13942307692307693, 0.14423076923076922, 0.14903846153846154, 0.15384615384615385, 0.15865384615384615, 0.16346153846153846, 0.16826923076923078, 0.17307692307692307, 0.1778846153846154, 0.18269230769230768, 0.1875, 0.19230769230769232, 0.1971153846153846, 0.20192307692307693, 0.20673076923076922, 0.21153846153846154, 0.21634615384615385, 0.22115384615384615, 0.22596153846153846, 0.23076923076923078, 0.23557692307692307, 0.2403846153846154, 0.24519230769230768, 0.25, 0.2548076923076923, 0.25961538461538464, 0.2644230769230769, 0.2692307692307692, 0.27403846153846156, 0.27884615384615385, 0.28365384615384615, 0.28846153846153844, 0.2932692307692308, 0.2980769230769231, 0.30288461538461536, 0.3076923076923077, 0.3125, 0.3173076923076923, 0.32211538461538464, 0.3269230769230769, 0.3317307692307692, 0.33653846153846156, 0.34134615384615385, 0.34615384615384615, 0.35096153846153844, 0.3557692307692308, 0.3605769230769231, 0.36538461538461536, 0.3701923076923077, 0.375, 0.3798076923076923, 0.38461538461538464, 0.3894230769230769, 0.3942307692307692, 0.39903846153846156, 0.40384615384615385, 0.40865384615384615, 0.41346153846153844, 0.4182692307692308, 0.4230769230769231, 0.42788461538461536, 0.4326923076923077, 0.4375, 0.4423076923076923, 0.44711538461538464, 0.4519230769230769, 0.4567307692307692, 0.46153846153846156, 0.46634615384615385, 0.47115384615384615, 0.47596153846153844, 0.4807692307692308, 0.4855769230769231, 0.49038461538461536, 0.4951923076923077, 0.5, 0.5048076923076923, 0.5096153846153846, 0.5144230769230769, 0.5192307692307693, 0.5240384615384616, 0.5288461538461539, 0.5336538461538461, 0.5384615384615384, 0.5432692307692307, 0.5480769230769231, 0.5528846153846154, 0.5576923076923077, 0.5625, 0.5673076923076923, 0.5721153846153846, 0.5769230769230769, 0.5817307692307693, 0.5865384615384616, 0.5913461538461539, 0.5961538461538461, 0.6009615384615384, 0.6057692307692307, 0.6105769230769231, 0.6153846153846154, 0.6201923076923077, 0.625, 0.6298076923076923, 0.6346153846153846, 0.6394230769230769, 0.6442307692307693, 0.6490384615384616, 0.6538461538461539, 0.6586538461538461, 0.6634615384615384, 0.6682692307692307, 0.6730769230769231, 0.6778846153846154, 0.6826923076923077, 0.6875, 0.6923076923076923, 0.6971153846153846, 0.7019230769230769, 0.7067307692307693, 0.7115384615384616, 0.7163461538461539, 0.7211538461538461, 0.7259615384615384, 0.7307692307692307, 0.7355769230769231, 0.7403846153846154, 0.7451923076923077, 0.75, 0.7548076923076923, 0.7596153846153846, 0.7644230769230769, 0.7692307692307693, 0.7740384615384616, 0.7788461538461539, 0.7836538461538461, 0.7884615384615384, 0.7932692307692307, 0.7980769230769231, 0.8028846153846154, 0.8076923076923077, 0.8125, 0.8173076923076923, 0.8221153846153846, 0.8269230769230769, 0.8317307692307693, 0.8365384615384616, 0.8413461538461539, 0.8461538461538461, 0.8509615384615384, 0.8557692307692307, 0.8605769230769231, 0.8653846153846154, 0.8701923076923077, 0.875, 0.8798076923076923, 0.8846153846153846, 0.8894230769230769, 0.8942307692307693, 0.8990384615384616, 0.9038461538461539, 0.9086538461538461, 0.9134615384615384, 0.9182692307692307, 0.9230769230769231, 0.9278846153846154, 0.9326923076923077, 0.9375, 0.9423076923076923, 0.9471153846153846, 0.9519230769230769, 0.9567307692307693, 0.9615384615384616, 0.9663461538461539, 0.9711538461538461, 0.9759615384615384, 0.9807692307692307, 0.9855769230769231, 0.9903846153846154, 0.9951923076923077, 1 ] } ], "layout": { "annotations": [ { "font": { "size": 14 }, "showarrow": false, "text": "0.25: 47303.50", "x": 0, "xanchor": "left", "xshift": 20, "y": 0.3 }, { "font": { "size": 14 }, "showarrow": false, "text": "0.5: 52406.50", "x": 0, "xanchor": "left", "xshift": 20, "y": 0.55 }, { "font": { "size": 14 }, "showarrow": false, "text": "0.75: 60347.75", "x": 0, "xanchor": "left", "xshift": 20, "y": 0.8 }, { "font": { "size": 14 }, "text": "Min: 19350.00", "x": 19350, "y": 0.05 }, { "font": { "size": 14 }, "text": "Max: 76067.00", "x": 76067, "y": 1 }, { "font": { "size": 14 }, "text": "Mean: 53908.78", "x": 53908.778846153844, "y": 0.5769230769230769 } ], "shapes": [ { "line": { "color": "red", "dash": "dash", "width": 2.1 }, "type": "line", "x0": 0, "x1": 1, "xref": "paper", "y0": 0.25, "y1": 0.25, "yref": "y" }, { "line": { "color": "red", "dash": "dash", "width": 2.1 }, "type": "line", "x0": 0, "x1": 1, "xref": "paper", "y0": 0.5, "y1": 0.5, "yref": "y" }, { "line": { "color": "red", "dash": "dash", "width": 2.1 }, "type": "line", "x0": 0, "x1": 1, "xref": "paper", "y0": 0.75, "y1": 0.75, "yref": "y" } ], "title": "ECDF of Income", "xaxis": { "title": "Income" }, "yaxis": { "title": "percentile" } } }, "text/html": [ "
" ], "text/vnd.plotly.v1+html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "iplot(figure)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "ExecuteTime": { "end_time": "2019-01-11T02:28:01.156169Z", "start_time": "2019-01-11T02:28:01.141356Z" } }, "outputs": [ { "data": { "text/plain": [ "year \n", "2013 0.25 46658.75\n", " 0.50 51757.50\n", " 0.75 58985.25\n", "2014 0.25 47100.50\n", " 0.50 52302.50\n", " 0.75 59942.25\n", "2015 0.25 47422.50\n", " 0.50 52601.00\n", " 0.75 60653.50\n", "2016 0.25 48770.00\n", " 0.50 53977.50\n", " 0.75 62518.50\n", "Name: income, dtype: float64" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" }, { "data": { "text/plain": [ "year\n", "2013 52878.230769\n", "2014 53468.788462\n", "2015 53957.519231\n", "2016 55330.576923\n", "Name: income, dtype: float64" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.groupby('year')['income'].quantile([0.25, 0.5, 0.75])\n", "df.groupby('year')['income'].mean()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "hide_input": false, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "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.6.5" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }