├── 1-Series ├── answers │ └── Series.ipynb └── series-tutorial.ipynb ├── 2-CSV ├── _files │ └── ParentTeacher.csv ├── answers │ └── csv.ipynb └── csv-tutorial.ipynb ├── README.md ├── _alpha_vantage ├── alpha_dataframe.py ├── alpha_rsi_dashboard.py ├── key.py └── rsi_bb_dashbord.py ├── core_components ├── datepicker.py ├── dropdown.py ├── markdown.py ├── range_slider.py ├── slider.py ├── tabs.py ├── textarea.py ├── upload_csv.py └── upload_img.py ├── dash_bootstrap └── bootstrap_basics.py ├── plotly_graphs ├── binance_account_piechard_dashboard.py ├── binance_api_keys.py ├── coingecko_v_s_bubble_graph.py └── image.py └── requirements.txt /1-Series/answers/Series.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "source": "\u003ch2\u003ePandas Series\n", 6 | "metadata": { 7 | "pycharm": { 8 | "metadata": false 9 | } 10 | } 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "source": "Importing pandas \u0026 declaring variables labels, data \u0026 dataCorrelated\n", 15 | "metadata": { 16 | "pycharm": { 17 | "metadata": false 18 | } 19 | } 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 1, 24 | "metadata": { 25 | "collapsed": true, 26 | "pycharm": { 27 | "is_executing": false 28 | } 29 | }, 30 | "outputs": [], 31 | "source": "import pandas as pd\n\nlabels \u003d [\u0027a\u0027, \u0027b\u0027, \u0027c\u0027, \u0027d\u0027]\n\ndata \u003d [\u002725\u0027, \u002750\u0027, \u002775\u0027, \u0027100\u0027]\n\ndataCorrelated \u003d {\u0027a\u0027: 100, \u0027b\u0027: 200, \u0027c\u0027: 300, \u0027d\u0027: 400}\n" 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 2, 36 | "outputs": [ 37 | { 38 | "data": { 39 | "text/plain": "a 25\nb 50\nc 75\nd 100\ndtype: object" 40 | }, 41 | "metadata": {}, 42 | "output_type": "execute_result", 43 | "execution_count": 2 44 | } 45 | ], 46 | "source": "pd.Series(data, index\u003dlabels)\n", 47 | "metadata": { 48 | "pycharm": { 49 | "metadata": false, 50 | "name": "#%%\n", 51 | "is_executing": false 52 | } 53 | } 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 3, 58 | "outputs": [ 59 | { 60 | "data": { 61 | "text/plain": "a 100\nb 200\nc 300\nd 400\ndtype: int64" 62 | }, 63 | "metadata": {}, 64 | "output_type": "execute_result", 65 | "execution_count": 3 66 | } 67 | ], 68 | "source": "pd.Series(dataCorrelated, index\u003dlabels)\n", 69 | "metadata": { 70 | "pycharm": { 71 | "metadata": false, 72 | "name": "#%%\n", 73 | "is_executing": false 74 | } 75 | } 76 | }, 77 | { 78 | "cell_type": "markdown", 79 | "source": "\u003ch4\u003eApplying Math to Pandas Series \u0026 Dataframes", 80 | "metadata": { 81 | "pycharm": { 82 | "metadata": false 83 | } 84 | } 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": 5, 89 | "outputs": [ 90 | { 91 | "traceback": [ 92 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 93 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", 94 | "\u001b[0;32m~/UdemyTutorial/lib/python3.7/site-packages/pandas/core/ops.py\u001b[0m in \u001b[0;36mna_op\u001b[0;34m(x, y)\u001b[0m\n\u001b[1;32m 1504\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-\u003e 1505\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m\u003d\u001b[0m \u001b[0mexpressions\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mevaluate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mop\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstr_rep\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0meval_kwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1506\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", 95 | "\u001b[0;32m~/UdemyTutorial/lib/python3.7/site-packages/pandas/core/computation/expressions.py\u001b[0m in \u001b[0;36mevaluate\u001b[0;34m(op, op_str, a, b, use_numexpr, **eval_kwargs)\u001b[0m\n\u001b[1;32m 207\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0muse_numexpr\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--\u003e 208\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0m_evaluate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mop\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mop_str\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0meval_kwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 209\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0m_evaluate_standard\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mop\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mop_str\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", 96 | "\u001b[0;32m~/UdemyTutorial/lib/python3.7/site-packages/pandas/core/computation/expressions.py\u001b[0m in \u001b[0;36m_evaluate_standard\u001b[0;34m(op, op_str, a, b, **eval_kwargs)\u001b[0m\n\u001b[1;32m 67\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0merrstate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mall\u001b[0m\u001b[0;34m\u003d\u001b[0m\u001b[0;34m\u0027ignore\u0027\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---\u003e 68\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mop\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 69\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", 97 | "\u001b[0;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str", 98 | "\nDuring handling of the above exception, another exception occurred:\n", 99 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", 100 | "\u001b[0;32m~/UdemyTutorial/lib/python3.7/site-packages/pandas/core/ops.py\u001b[0m in \u001b[0;36msafe_na_op\u001b[0;34m(lvalues, rvalues)\u001b[0m\n\u001b[1;32m 1528\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0merrstate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mall\u001b[0m\u001b[0;34m\u003d\u001b[0m\u001b[0;34m\u0027ignore\u0027\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-\u003e 1529\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mna_op\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlvalues\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrvalues\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1530\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", 101 | "\u001b[0;32m~/UdemyTutorial/lib/python3.7/site-packages/pandas/core/ops.py\u001b[0m in \u001b[0;36mna_op\u001b[0;34m(x, y)\u001b[0m\n\u001b[1;32m 1506\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-\u003e 1507\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m\u003d\u001b[0m \u001b[0mmasked_arith_op\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mop\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1508\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", 102 | "\u001b[0;32m~/UdemyTutorial/lib/python3.7/site-packages/pandas/core/ops.py\u001b[0m in \u001b[0;36mmasked_arith_op\u001b[0;34m(x, y, op)\u001b[0m\n\u001b[1;32m 1008\u001b[0m result[mask] \u003d op(xrav[mask],\n\u001b[0;32m-\u003e 1009\u001b[0;31m com.values_from_object(yrav[mask]))\n\u001b[0m\u001b[1;32m 1010\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", 103 | "\u001b[0;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str", 104 | "\nDuring handling of the above exception, another exception occurred:\n", 105 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", 106 | "\u001b[0;32m\u003cipython-input-5-749a63b4a47e\u003e\u001b[0m in \u001b[0;36m\u003cmodule\u003e\u001b[0;34m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mseries2\u001b[0m \u001b[0;34m\u003d\u001b[0m \u001b[0mpd\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mSeries\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdataCorrelated\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[0;34m\u003d\u001b[0m\u001b[0mlabels\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----\u003e 6\u001b[0;31m \u001b[0mseries1\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mseries2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 7\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", 107 | "\u001b[0;32m~/UdemyTutorial/lib/python3.7/site-packages/pandas/core/ops.py\u001b[0m in \u001b[0;36mwrapper\u001b[0;34m(left, right)\u001b[0m\n\u001b[1;32m 1581\u001b[0m \u001b[0mrvalues\u001b[0m \u001b[0;34m\u003d\u001b[0m \u001b[0mrvalues\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1582\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-\u003e 1583\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m\u003d\u001b[0m \u001b[0msafe_na_op\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlvalues\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrvalues\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1584\u001b[0m return construct_result(left, result,\n\u001b[1;32m 1585\u001b[0m index\u003dleft.index, name\u003dres_name, dtype\u003dNone)\n", 108 | "\u001b[0;32m~/UdemyTutorial/lib/python3.7/site-packages/pandas/core/ops.py\u001b[0m in \u001b[0;36msafe_na_op\u001b[0;34m(lvalues, rvalues)\u001b[0m\n\u001b[1;32m 1531\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mis_object_dtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlvalues\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1532\u001b[0m return libalgos.arrmap_object(lvalues,\n\u001b[0;32m-\u003e 1533\u001b[0;31m lambda x: op(x, rvalues))\n\u001b[0m\u001b[1;32m 1534\u001b[0m \u001b[0;32mraise\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1535\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", 109 | "\u001b[0;32mpandas/_libs/algos.pyx\u001b[0m in \u001b[0;36mpandas._libs.algos.arrmap\u001b[0;34m()\u001b[0m\n", 110 | "\u001b[0;32m~/UdemyTutorial/lib/python3.7/site-packages/pandas/core/ops.py\u001b[0m in \u001b[0;36m\u003clambda\u003e\u001b[0;34m(x)\u001b[0m\n\u001b[1;32m 1531\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mis_object_dtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlvalues\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1532\u001b[0m return libalgos.arrmap_object(lvalues,\n\u001b[0;32m-\u003e 1533\u001b[0;31m lambda x: op(x, rvalues))\n\u001b[0m\u001b[1;32m 1534\u001b[0m \u001b[0;32mraise\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1535\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", 111 | "\u001b[0;31mTypeError\u001b[0m: ufunc \u0027add\u0027 did not contain a loop with signature matching types dtype(\u0027\u003cU21\u0027) dtype(\u0027\u003cU21\u0027) dtype(\u0027\u003cU21\u0027)" 112 | ], 113 | "ename": "TypeError", 114 | "evalue": "ufunc \u0027add\u0027 did not contain a loop with signature matching types dtype(\u0027\u003cU21\u0027) dtype(\u0027\u003cU21\u0027) dtype(\u0027\u003cU21\u0027)", 115 | "output_type": "error" 116 | } 117 | ], 118 | "source": "#Why Doesnt this work?\nseries1 \u003d pd.Series(data, index\u003dlabels)\n\nseries2 \u003d pd.Series(dataCorrelated, index\u003dlabels)\n\nseries1 + series2\n", 119 | "metadata": { 120 | "pycharm": { 121 | "metadata": false, 122 | "name": "#%%\n", 123 | "is_executing": false 124 | } 125 | } 126 | }, 127 | { 128 | "cell_type": "markdown", 129 | "source": "How to change the data\u0027s dtype: \n", 130 | "metadata": { 131 | "pycharm": { 132 | "metadata": false 133 | } 134 | } 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": 6, 139 | "outputs": [ 140 | { 141 | "data": { 142 | "text/plain": "a 125\nb 250\nc 375\nd 500\ndtype: int64" 143 | }, 144 | "metadata": {}, 145 | "output_type": "execute_result", 146 | "execution_count": 6 147 | } 148 | ], 149 | "source": "series1.astype(int) + series2\n", 150 | "metadata": { 151 | "pycharm": { 152 | "metadata": false, 153 | "name": "#%%\n", 154 | "is_executing": false 155 | } 156 | } 157 | }, 158 | { 159 | "cell_type": "code", 160 | "execution_count": 7, 161 | "outputs": [ 162 | { 163 | "data": { 164 | "text/plain": "a 125.0\nb 250.0\nc 375.0\nd 500.0\ndtype: float64" 165 | }, 166 | "metadata": {}, 167 | "output_type": "execute_result", 168 | "execution_count": 7 169 | } 170 | ], 171 | "source": "series1.astype(float) + series2\n", 172 | "metadata": { 173 | "pycharm": { 174 | "metadata": false, 175 | "name": "#%%\n", 176 | "is_executing": false 177 | } 178 | } 179 | }, 180 | { 181 | "cell_type": "code", 182 | "execution_count": 8, 183 | "outputs": [ 184 | { 185 | "data": { 186 | "text/plain": "a 25100\nb 50200\nc 75300\nd 100400\ndtype: object" 187 | }, 188 | "metadata": {}, 189 | "output_type": "execute_result", 190 | "execution_count": 8 191 | } 192 | ], 193 | "source": "series1 + series2.astype(str)\n", 194 | "metadata": { 195 | "pycharm": { 196 | "metadata": false, 197 | "name": "#%%\n", 198 | "is_executing": false 199 | } 200 | } 201 | } 202 | ], 203 | "metadata": { 204 | "language_info": { 205 | "codemirror_mode": { 206 | "name": "ipython", 207 | "version": 2 208 | }, 209 | "file_extension": ".py", 210 | "mimetype": "text/x-python", 211 | "name": "python", 212 | "nbconvert_exporter": "python", 213 | "pygments_lexer": "ipython2", 214 | "version": "2.7.6" 215 | }, 216 | "kernelspec": { 217 | "name": "python3", 218 | "language": "python", 219 | "display_name": "Python 3" 220 | }, 221 | "stem_cell": { 222 | "cell_type": "raw", 223 | "source": "", 224 | "metadata": { 225 | "pycharm": { 226 | "metadata": false 227 | } 228 | } 229 | } 230 | }, 231 | "nbformat": 4, 232 | "nbformat_minor": 0 233 | } -------------------------------------------------------------------------------- /1-Series/series-tutorial.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "source": "\u003ch2\u003ePandas Series\n", 6 | "metadata": { 7 | "pycharm": { 8 | "metadata": false 9 | } 10 | } 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "source": "Importing pandas \u0026 declaring variables labels, data \u0026 dataCorrelated\n", 15 | "metadata": { 16 | "pycharm": { 17 | "metadata": false 18 | } 19 | } 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": null, 24 | "outputs": [], 25 | "source": "import pandas as pd\n\nlabels \u003d [\u0027a\u0027, \u0027b\u0027, \u0027c\u0027, \u0027d\u0027]\n\ndata \u003d [\u002725\u0027, \u002750\u0027, \u002775\u0027, \u0027100\u0027]\n\ndataCorrelated \u003d {\u0027a\u0027: 100, \u0027b\u0027: 200, \u0027c\u0027: 300, \u0027d\u0027: 400}\n", 26 | "metadata": { 27 | "pycharm": { 28 | "metadata": false, 29 | "name": "#%%\n" 30 | } 31 | } 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": null, 36 | "outputs": [], 37 | "source": "\n", 38 | "metadata": { 39 | "pycharm": { 40 | "metadata": false, 41 | "name": "#%%\n" 42 | } 43 | } 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": null, 48 | "outputs": [], 49 | "source": "\n", 50 | "metadata": { 51 | "pycharm": { 52 | "metadata": false, 53 | "name": "#%%\n" 54 | } 55 | } 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "source": "\u003ch4\u003eApplying Math to Pandas Series \u0026 Dataframes", 60 | "metadata": { 61 | "pycharm": { 62 | "metadata": false 63 | } 64 | } 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": null, 69 | "outputs": [], 70 | "source": "#Why Doesnt this work?\nseries1 \u003d pd.Series(data, index\u003dlabels)\n\nseries2 \u003d pd.Series(dataCorrelated, index\u003dlabels)\n\nseries1 + series2\n", 71 | "metadata": { 72 | "pycharm": { 73 | "metadata": false, 74 | "name": "#%%\n" 75 | } 76 | } 77 | }, 78 | { 79 | "cell_type": "markdown", 80 | "source": "How to change the data\u0027s dtype: \n", 81 | "metadata": { 82 | "pycharm": { 83 | "metadata": false 84 | } 85 | } 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": null, 90 | "outputs": [], 91 | "source": "\n", 92 | "metadata": { 93 | "pycharm": { 94 | "metadata": false, 95 | "name": "#%%\n" 96 | } 97 | } 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": null, 102 | "outputs": [], 103 | "source": "\n", 104 | "metadata": { 105 | "pycharm": { 106 | "metadata": false, 107 | "name": "#%%\n" 108 | } 109 | } 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": null, 114 | "outputs": [], 115 | "source": "\n", 116 | "metadata": { 117 | "pycharm": { 118 | "metadata": false, 119 | "name": "#%%\n" 120 | } 121 | } 122 | } 123 | ], 124 | "metadata": { 125 | "language_info": { 126 | "codemirror_mode": { 127 | "name": "ipython", 128 | "version": 2 129 | }, 130 | "file_extension": ".py", 131 | "mimetype": "text/x-python", 132 | "name": "python", 133 | "nbconvert_exporter": "python", 134 | "pygments_lexer": "ipython2", 135 | "version": "2.7.6" 136 | }, 137 | "kernelspec": { 138 | "name": "python3", 139 | "language": "python", 140 | "display_name": "Python 3" 141 | }, 142 | "stem_cell": { 143 | "cell_type": "raw", 144 | "source": "", 145 | "metadata": { 146 | "pycharm": { 147 | "metadata": false 148 | } 149 | } 150 | } 151 | }, 152 | "nbformat": 4, 153 | "nbformat_minor": 0 154 | } -------------------------------------------------------------------------------- /2-CSV/_files/ParentTeacher.csv: -------------------------------------------------------------------------------- 1 | Start Date ,Start Time,End Date,End Time,Event Title ,Event Description,All Day Event,No End Time,Contact ,Contact Email,Contact Phone,Location,Category,Registration,Maximum Seats,Last Date To Register 10/5/13,7:00 AM,10/5/13,8:00 AM,Parent Teacher Conference,Register for a one hour parent teacher conference. ,N,N,Chris Gallagher,cgallagher@schoolwires.com,814-555-5179,Room 203,2,Y,1,10/4/13 10/5/13,8:00 AM,10/5/13,9:00 AM,Parent Teacher Conference,Register for a one hour parent teacher conference. ,N,N,Chris Gallagher,cgallagher@schoolwires.com,814-555-5179,Room 203,2,Y,1,10/4/13 10/5/13,9:00 AM,10/5/13,10:00 AM,Parent Teacher Conference,Register for a one hour parent teacher conference. ,N,N,Chris Gallagher,cgallagher@schoolwires.com,814-555-5179,Room 203,2,Y,1,10/4/13 10/5/13,10:00 AM,10/5/13,11:00 AM,Parent Teacher Conference,Register for a one hour parent teacher conference. ,N,N,Chris Gallagher,cgallagher@schoolwires.com,814-555-5179,Room 203,2,Y,1,10/4/13 10/5/13,11:00 AM,10/5/13,12:00 PM,Parent Teacher Conference,Register for a one hour parent teacher conference. ,N,N,Chris Gallagher,cgallagher@schoolwires.com,814-555-5179,Room 203,2,Y,1,10/4/13 10/5/13,12:00 PM,10/5/13,1:00 PM,Parent Teacher Conference,Register for a one hour parent teacher conference. ,N,N,Chris Gallagher,cgallagher@schoolwires.com,814-555-5179,Room 203,2,Y,1,10/4/13 10/5/13,1:00 PM,10/5/13,2:00 PM,Parent Teacher Conference,Register for a one hour parent teacher conference. ,N,N,Chris Gallagher,cgallagher@schoolwires.com,814-555-5179,Room 203,2,Y,1,10/4/13 10/5/13,2:00 PM,10/5/13,3:00 PM,Parent Teacher Conference,Register for a one hour parent teacher conference. ,N,N,Chris Gallagher,cgallagher@schoolwires.com,814-555-5179,Room 203,2,Y,1,10/4/13 10/5/13,3:00 PM,10/5/13,4:00 PM,Parent Teacher Conference,Register for a one hour parent teacher conference. ,N,N,Chris Gallagher,cgallagher@schoolwires.com,814-555-5179,Room 203,2,Y,1,10/4/13 10/5/13,4:00 PM,10/5/13,5:00 PM,Parent Teacher Conference,Register for a one hour parent teacher conference. ,N,N,Chris Gallagher,cgallagher@schoolwires.com,814-555-5179,Room 203,2,Y,1,10/4/13 10/5/13,5:00 PM,10/5/13,6:00 PM,Parent Teacher Conference,Register for a one hour parent teacher conference. ,N,N,Chris Gallagher,cgallagher@schoolwires.com,814-555-5179,Room 203,2,Y,1,10/4/13 10/5/13,6:00 PM,10/5/13,7:00 PM,Parent Teacher Conference,Register for a one hour parent teacher conference. ,N,N,Chris Gallagher,cgallagher@schoolwires.com,814-555-5179,Room 203,2,Y,1,10/4/13 -------------------------------------------------------------------------------- /2-CSV/answers/csv.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "source": "\u003ch2\u003eWorking in Data: CSV\n", 6 | "metadata": { 7 | "pycharm": { 8 | "metadata": false 9 | } 10 | } 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "source": "Creating a loop, for every line within csv_reader print line:", 15 | "metadata": { 16 | "pycharm": { 17 | "metadata": false 18 | } 19 | } 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 2, 24 | "outputs": [ 25 | { 26 | "name": "stdout", 27 | "text": [ 28 | "[\u0027Start Date \u0027, \u0027Start Time\u0027, \u0027End Date\u0027, \u0027End Time\u0027, \u0027Event Title \u0027, \u0027Event Description\u0027, \u0027All Day Event\u0027, \u0027No End Time\u0027, \u0027Contact \u0027, \u0027Contact Email\u0027, \u0027Contact Phone\u0027, \u0027Location\u0027, \u0027Category\u0027, \u0027Registration\u0027, \u0027Maximum Seats\u0027, \u0027Last Date To Register\u0027]\n[\u002710/5/13\u0027, \u00277:00 AM\u0027, \u002710/5/13\u0027, \u00278:00 AM\u0027, \u0027Parent Teacher Conference\u0027, \u0027Register for a one hour parent teacher conference. \u0027, \u0027N\u0027, \u0027N\u0027, \u0027Chris Gallagher\u0027, \u0027cgallagher@schoolwires.com\u0027, \u0027814-555-5179\u0027, \u0027Room 203\u0027, \u00272\u0027, \u0027Y\u0027, \u00271\u0027, \u002710/4/13\u0027]\n[\u002710/5/13\u0027, \u00278:00 AM\u0027, \u002710/5/13\u0027, \u00279:00 AM\u0027, \u0027Parent Teacher Conference\u0027, \u0027Register for a one hour parent teacher conference. \u0027, \u0027N\u0027, \u0027N\u0027, \u0027Chris Gallagher\u0027, \u0027cgallagher@schoolwires.com\u0027, \u0027814-555-5179\u0027, \u0027Room 203\u0027, \u00272\u0027, \u0027Y\u0027, \u00271\u0027, \u002710/4/13\u0027]\n[\u002710/5/13\u0027, \u00279:00 AM\u0027, \u002710/5/13\u0027, \u002710:00 AM\u0027, \u0027Parent Teacher Conference\u0027, \u0027Register for a one hour parent teacher conference. \u0027, \u0027N\u0027, \u0027N\u0027, \u0027Chris Gallagher\u0027, \u0027cgallagher@schoolwires.com\u0027, \u0027814-555-5179\u0027, \u0027Room 203\u0027, \u00272\u0027, \u0027Y\u0027, \u00271\u0027, \u002710/4/13\u0027]\n[\u002710/5/13\u0027, \u002710:00 AM\u0027, \u002710/5/13\u0027, \u002711:00 AM\u0027, \u0027Parent Teacher Conference\u0027, \u0027Register for a one hour parent teacher conference. \u0027, \u0027N\u0027, \u0027N\u0027, \u0027Chris Gallagher\u0027, \u0027cgallagher@schoolwires.com\u0027, \u0027814-555-5179\u0027, \u0027Room 203\u0027, \u00272\u0027, \u0027Y\u0027, \u00271\u0027, \u002710/4/13\u0027]\n[\u002710/5/13\u0027, \u002711:00 AM\u0027, \u002710/5/13\u0027, \u002712:00 PM\u0027, \u0027Parent Teacher Conference\u0027, \u0027Register for a one hour parent teacher conference. \u0027, \u0027N\u0027, \u0027N\u0027, \u0027Chris Gallagher\u0027, \u0027cgallagher@schoolwires.com\u0027, \u0027814-555-5179\u0027, \u0027Room 203\u0027, \u00272\u0027, \u0027Y\u0027, \u00271\u0027, \u002710/4/13\u0027]\n[\u002710/5/13\u0027, \u002712:00 PM\u0027, \u002710/5/13\u0027, \u00271:00 PM\u0027, \u0027Parent Teacher Conference\u0027, \u0027Register for a one hour parent teacher conference. \u0027, \u0027N\u0027, \u0027N\u0027, \u0027Chris Gallagher\u0027, \u0027cgallagher@schoolwires.com\u0027, \u0027814-555-5179\u0027, \u0027Room 203\u0027, \u00272\u0027, \u0027Y\u0027, \u00271\u0027, \u002710/4/13\u0027]\n[\u002710/5/13\u0027, \u00271:00 PM\u0027, \u002710/5/13\u0027, \u00272:00 PM\u0027, \u0027Parent Teacher Conference\u0027, \u0027Register for a one hour parent teacher conference. \u0027, \u0027N\u0027, \u0027N\u0027, \u0027Chris Gallagher\u0027, \u0027cgallagher@schoolwires.com\u0027, \u0027814-555-5179\u0027, \u0027Room 203\u0027, \u00272\u0027, \u0027Y\u0027, \u00271\u0027, \u002710/4/13\u0027]\n[\u002710/5/13\u0027, \u00272:00 PM\u0027, \u002710/5/13\u0027, \u00273:00 PM\u0027, \u0027Parent Teacher Conference\u0027, \u0027Register for a one hour parent teacher conference. \u0027, \u0027N\u0027, \u0027N\u0027, \u0027Chris Gallagher\u0027, \u0027cgallagher@schoolwires.com\u0027, \u0027814-555-5179\u0027, \u0027Room 203\u0027, \u00272\u0027, \u0027Y\u0027, \u00271\u0027, \u002710/4/13\u0027]\n[\u002710/5/13\u0027, \u00273:00 PM\u0027, \u002710/5/13\u0027, \u00274:00 PM\u0027, \u0027Parent Teacher Conference\u0027, \u0027Register for a one hour parent teacher conference. \u0027, \u0027N\u0027, \u0027N\u0027, \u0027Chris Gallagher\u0027, \u0027cgallagher@schoolwires.com\u0027, \u0027814-555-5179\u0027, \u0027Room 203\u0027, \u00272\u0027, \u0027Y\u0027, \u00271\u0027, \u002710/4/13\u0027]\n[\u002710/5/13\u0027, \u00274:00 PM\u0027, \u002710/5/13\u0027, \u00275:00 PM\u0027, \u0027Parent Teacher Conference\u0027, \u0027Register for a one hour parent teacher conference. \u0027, \u0027N\u0027, \u0027N\u0027, \u0027Chris Gallagher\u0027, \u0027cgallagher@schoolwires.com\u0027, \u0027814-555-5179\u0027, \u0027Room 203\u0027, \u00272\u0027, \u0027Y\u0027, \u00271\u0027, \u002710/4/13\u0027]\n[\u002710/5/13\u0027, \u00275:00 PM\u0027, \u002710/5/13\u0027, \u00276:00 PM\u0027, \u0027Parent Teacher Conference\u0027, \u0027Register for a one hour parent teacher conference. \u0027, \u0027N\u0027, \u0027N\u0027, \u0027Chris Gallagher\u0027, \u0027cgallagher@schoolwires.com\u0027, \u0027814-555-5179\u0027, \u0027Room 203\u0027, \u00272\u0027, \u0027Y\u0027, \u00271\u0027, \u002710/4/13\u0027]\n[\u002710/5/13\u0027, \u00276:00 PM\u0027, \u002710/5/13\u0027, \u00277:00 PM\u0027, \u0027Parent Teacher Conference\u0027, \u0027Register for a one hour parent teacher conference. \u0027, \u0027N\u0027, \u0027N\u0027, \u0027Chris Gallagher\u0027, \u0027cgallagher@schoolwires.com\u0027, \u0027814-555-5179\u0027, \u0027Room 203\u0027, \u00272\u0027, \u0027Y\u0027, \u00271\u0027, \u002710/4/13\u0027]\n" 29 | ], 30 | "output_type": "stream" 31 | } 32 | ], 33 | "source": "import csv\n\nwith open(\u0027../_files/ParentTeacher.csv\u0027) as csv_file:\n csv_reader \u003d csv.reader(csv_file)\n\n #Creating a loop, for every line within csv_reader print line\n for line in csv_reader:\n print(line)\n ", 34 | "metadata": { 35 | "pycharm": { 36 | "metadata": false, 37 | "name": "#%%\n", 38 | "is_executing": false 39 | } 40 | } 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "source": "Moving the csv into a list:\n", 45 | "metadata": { 46 | "pycharm": { 47 | "metadata": false 48 | } 49 | } 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": 3, 54 | "outputs": [ 55 | { 56 | "name": "stdout", 57 | "text": [ 58 | "[[\u0027Start Date \u0027, \u0027Start Time\u0027, \u0027End Date\u0027, \u0027End Time\u0027, \u0027Event Title \u0027, \u0027Event Description\u0027, \u0027All Day Event\u0027, \u0027No End Time\u0027, \u0027Contact \u0027, \u0027Contact Email\u0027, \u0027Contact Phone\u0027, \u0027Location\u0027, \u0027Category\u0027, \u0027Registration\u0027, \u0027Maximum Seats\u0027, \u0027Last Date To Register\u0027], [\u002710/5/13\u0027, \u00277:00 AM\u0027, \u002710/5/13\u0027, \u00278:00 AM\u0027, \u0027Parent Teacher Conference\u0027, \u0027Register for a one hour parent teacher conference. \u0027, \u0027N\u0027, \u0027N\u0027, \u0027Chris Gallagher\u0027, \u0027cgallagher@schoolwires.com\u0027, \u0027814-555-5179\u0027, \u0027Room 203\u0027, \u00272\u0027, \u0027Y\u0027, \u00271\u0027, \u002710/4/13\u0027], [\u002710/5/13\u0027, \u00278:00 AM\u0027, \u002710/5/13\u0027, \u00279:00 AM\u0027, \u0027Parent Teacher Conference\u0027, \u0027Register for a one hour parent teacher conference. \u0027, \u0027N\u0027, \u0027N\u0027, \u0027Chris Gallagher\u0027, \u0027cgallagher@schoolwires.com\u0027, \u0027814-555-5179\u0027, \u0027Room 203\u0027, \u00272\u0027, \u0027Y\u0027, \u00271\u0027, \u002710/4/13\u0027], [\u002710/5/13\u0027, \u00279:00 AM\u0027, \u002710/5/13\u0027, \u002710:00 AM\u0027, \u0027Parent Teacher Conference\u0027, \u0027Register for a one hour parent teacher conference. \u0027, \u0027N\u0027, \u0027N\u0027, \u0027Chris Gallagher\u0027, \u0027cgallagher@schoolwires.com\u0027, \u0027814-555-5179\u0027, \u0027Room 203\u0027, \u00272\u0027, \u0027Y\u0027, \u00271\u0027, \u002710/4/13\u0027], [\u002710/5/13\u0027, \u002710:00 AM\u0027, \u002710/5/13\u0027, \u002711:00 AM\u0027, \u0027Parent Teacher Conference\u0027, \u0027Register for a one hour parent teacher conference. \u0027, \u0027N\u0027, \u0027N\u0027, \u0027Chris Gallagher\u0027, \u0027cgallagher@schoolwires.com\u0027, \u0027814-555-5179\u0027, \u0027Room 203\u0027, \u00272\u0027, \u0027Y\u0027, \u00271\u0027, \u002710/4/13\u0027], [\u002710/5/13\u0027, \u002711:00 AM\u0027, \u002710/5/13\u0027, \u002712:00 PM\u0027, \u0027Parent Teacher Conference\u0027, \u0027Register for a one hour parent teacher conference. \u0027, \u0027N\u0027, \u0027N\u0027, \u0027Chris Gallagher\u0027, \u0027cgallagher@schoolwires.com\u0027, \u0027814-555-5179\u0027, \u0027Room 203\u0027, \u00272\u0027, \u0027Y\u0027, \u00271\u0027, \u002710/4/13\u0027], [\u002710/5/13\u0027, \u002712:00 PM\u0027, \u002710/5/13\u0027, \u00271:00 PM\u0027, \u0027Parent Teacher Conference\u0027, \u0027Register for a one hour parent teacher conference. \u0027, \u0027N\u0027, \u0027N\u0027, \u0027Chris Gallagher\u0027, \u0027cgallagher@schoolwires.com\u0027, \u0027814-555-5179\u0027, \u0027Room 203\u0027, \u00272\u0027, \u0027Y\u0027, \u00271\u0027, \u002710/4/13\u0027], [\u002710/5/13\u0027, \u00271:00 PM\u0027, \u002710/5/13\u0027, \u00272:00 PM\u0027, \u0027Parent Teacher Conference\u0027, \u0027Register for a one hour parent teacher conference. \u0027, \u0027N\u0027, \u0027N\u0027, \u0027Chris Gallagher\u0027, \u0027cgallagher@schoolwires.com\u0027, \u0027814-555-5179\u0027, \u0027Room 203\u0027, \u00272\u0027, \u0027Y\u0027, \u00271\u0027, \u002710/4/13\u0027], [\u002710/5/13\u0027, \u00272:00 PM\u0027, \u002710/5/13\u0027, \u00273:00 PM\u0027, \u0027Parent Teacher Conference\u0027, \u0027Register for a one hour parent teacher conference. \u0027, \u0027N\u0027, \u0027N\u0027, \u0027Chris Gallagher\u0027, \u0027cgallagher@schoolwires.com\u0027, \u0027814-555-5179\u0027, \u0027Room 203\u0027, \u00272\u0027, \u0027Y\u0027, \u00271\u0027, \u002710/4/13\u0027], [\u002710/5/13\u0027, \u00273:00 PM\u0027, \u002710/5/13\u0027, \u00274:00 PM\u0027, \u0027Parent Teacher Conference\u0027, \u0027Register for a one hour parent teacher conference. \u0027, \u0027N\u0027, \u0027N\u0027, \u0027Chris Gallagher\u0027, \u0027cgallagher@schoolwires.com\u0027, \u0027814-555-5179\u0027, \u0027Room 203\u0027, \u00272\u0027, \u0027Y\u0027, \u00271\u0027, \u002710/4/13\u0027], [\u002710/5/13\u0027, \u00274:00 PM\u0027, \u002710/5/13\u0027, \u00275:00 PM\u0027, \u0027Parent Teacher Conference\u0027, \u0027Register for a one hour parent teacher conference. \u0027, \u0027N\u0027, \u0027N\u0027, \u0027Chris Gallagher\u0027, \u0027cgallagher@schoolwires.com\u0027, \u0027814-555-5179\u0027, \u0027Room 203\u0027, \u00272\u0027, \u0027Y\u0027, \u00271\u0027, \u002710/4/13\u0027], [\u002710/5/13\u0027, \u00275:00 PM\u0027, \u002710/5/13\u0027, \u00276:00 PM\u0027, \u0027Parent Teacher Conference\u0027, \u0027Register for a one hour parent teacher conference. \u0027, \u0027N\u0027, \u0027N\u0027, \u0027Chris Gallagher\u0027, \u0027cgallagher@schoolwires.com\u0027, \u0027814-555-5179\u0027, \u0027Room 203\u0027, \u00272\u0027, \u0027Y\u0027, \u00271\u0027, \u002710/4/13\u0027], [\u002710/5/13\u0027, \u00276:00 PM\u0027, \u002710/5/13\u0027, \u00277:00 PM\u0027, \u0027Parent Teacher Conference\u0027, \u0027Register for a one hour parent teacher conference. \u0027, \u0027N\u0027, \u0027N\u0027, \u0027Chris Gallagher\u0027, \u0027cgallagher@schoolwires.com\u0027, \u0027814-555-5179\u0027, \u0027Room 203\u0027, \u00272\u0027, \u0027Y\u0027, \u00271\u0027, \u002710/4/13\u0027]]\n" 59 | ], 60 | "output_type": "stream" 61 | } 62 | ], 63 | "source": "with open(\u0027../_files/ParentTeacher.csv\u0027) as csv_file:\n csv_reader2 \u003d csv.reader(csv_file)\n \n#create a blank list\n blank_list \u003d []\n\n #Creating a loop, for every line within csv_reader\n for line in csv_reader2:\n #append each line to the blank_list\n blank_list.append(line)\n\n #print the new list (Issue nested list)\n print(blank_list)\n ", 64 | "metadata": { 65 | "pycharm": { 66 | "metadata": false, 67 | "name": "#%%\n", 68 | "is_executing": false 69 | } 70 | } 71 | }, 72 | { 73 | "cell_type": "markdown", 74 | "source": "Remove Nested list:", 75 | "metadata": { 76 | "pycharm": { 77 | "metadata": false 78 | } 79 | } 80 | }, 81 | { 82 | "cell_type": "code", 83 | "execution_count": 4, 84 | "outputs": [ 85 | { 86 | "name": "stdout", 87 | "text": [ 88 | "[\u0027Start Date \u0027, \u0027Start Time\u0027, \u0027End Date\u0027, \u0027End Time\u0027, \u0027Event Title \u0027, \u0027Event Description\u0027, \u0027All Day Event\u0027, \u0027No End Time\u0027, \u0027Contact \u0027, \u0027Contact Email\u0027, \u0027Contact Phone\u0027, \u0027Location\u0027, \u0027Category\u0027, \u0027Registration\u0027, \u0027Maximum Seats\u0027, \u0027Last Date To Register\u0027]\n" 89 | ], 90 | "output_type": "stream" 91 | } 92 | ], 93 | "source": "print(blank_list[0])\n", 94 | "metadata": { 95 | "pycharm": { 96 | "metadata": false, 97 | "name": "#%%\n", 98 | "is_executing": false 99 | } 100 | } 101 | }, 102 | { 103 | "cell_type": "markdown", 104 | "source": "Learn how to call individual data within the list:", 105 | "metadata": { 106 | "pycharm": { 107 | "metadata": false 108 | } 109 | } 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": 5, 114 | "outputs": [ 115 | { 116 | "name": "stdout", 117 | "text": [ 118 | "End Time\n" 119 | ], 120 | "output_type": "stream" 121 | } 122 | ], 123 | "source": "print(blank_list[0][3])\n", 124 | "metadata": { 125 | "pycharm": { 126 | "metadata": false, 127 | "name": "#%%\n", 128 | "is_executing": false 129 | } 130 | } 131 | }, 132 | { 133 | "cell_type": "markdown", 134 | "source": "Learn how to call a range of data within the list:", 135 | "metadata": { 136 | "pycharm": { 137 | "metadata": false 138 | } 139 | } 140 | }, 141 | { 142 | "cell_type": "code", 143 | "execution_count": 6, 144 | "outputs": [ 145 | { 146 | "name": "stdout", 147 | "text": [ 148 | "[\u0027Start Date \u0027, \u0027Start Time\u0027, \u0027End Date\u0027, \u0027End Time\u0027, \u0027Event Title \u0027, \u0027Event Description\u0027, \u0027All Day Event\u0027, \u0027No End Time\u0027, \u0027Contact \u0027, \u0027Contact Email\u0027, \u0027Contact Phone\u0027, \u0027Location\u0027, \u0027Category\u0027, \u0027Registration\u0027, \u0027Maximum Seats\u0027]\n" 149 | ], 150 | "output_type": "stream" 151 | } 152 | ], 153 | "source": "print(blank_list[0][0:15])\n\n", 154 | "metadata": { 155 | "pycharm": { 156 | "metadata": false, 157 | "name": "#%%\n", 158 | "is_executing": false 159 | } 160 | } 161 | } 162 | ], 163 | "metadata": { 164 | "language_info": { 165 | "codemirror_mode": { 166 | "name": "ipython", 167 | "version": 2 168 | }, 169 | "file_extension": ".py", 170 | "mimetype": "text/x-python", 171 | "name": "python", 172 | "nbconvert_exporter": "python", 173 | "pygments_lexer": "ipython2", 174 | "version": "2.7.6" 175 | }, 176 | "kernelspec": { 177 | "name": "python3", 178 | "language": "python", 179 | "display_name": "Python 3" 180 | }, 181 | "stem_cell": { 182 | "cell_type": "raw", 183 | "source": "", 184 | "metadata": { 185 | "pycharm": { 186 | "metadata": false 187 | } 188 | } 189 | } 190 | }, 191 | "nbformat": 4, 192 | "nbformat_minor": 0 193 | } -------------------------------------------------------------------------------- /2-CSV/csv-tutorial.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "source": "\u003ch2\u003eWorking in Data: CSV\n", 6 | "metadata": { 7 | "pycharm": { 8 | "metadata": false 9 | } 10 | } 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "source": "Creating a loop, for every line within csv_reader print line:", 15 | "metadata": { 16 | "pycharm": { 17 | "metadata": false 18 | } 19 | } 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 14, 24 | "metadata": { 25 | "collapsed": true, 26 | "pycharm": { 27 | "is_executing": false 28 | } 29 | }, 30 | "outputs": [], 31 | "source": "import csv\n " 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "source": "Moving the csv into a list:\n", 36 | "metadata": { 37 | "pycharm": { 38 | "metadata": false 39 | } 40 | } 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": 15, 45 | "outputs": [], 46 | "source": "\n \n#create a blank list\n \n\n #Creating a loop, for every line within csv_reader\n \n #append each line to the blank_list\n \n\n #print the new list (Issue nested list)\n \n ", 47 | "metadata": { 48 | "pycharm": { 49 | "metadata": false, 50 | "name": "#%%\n", 51 | "is_executing": false 52 | } 53 | } 54 | }, 55 | { 56 | "cell_type": "markdown", 57 | "source": "Remove Nested list:", 58 | "metadata": { 59 | "pycharm": { 60 | "metadata": false 61 | } 62 | } 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": 15, 67 | "outputs": [], 68 | "source": "\n", 69 | "metadata": { 70 | "pycharm": { 71 | "metadata": false, 72 | "name": "#%%\n", 73 | "is_executing": false 74 | } 75 | } 76 | }, 77 | { 78 | "cell_type": "markdown", 79 | "source": "Learn how to call individual data within the list:", 80 | "metadata": { 81 | "pycharm": { 82 | "metadata": false 83 | } 84 | } 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": 15, 89 | "outputs": [], 90 | "source": "\n", 91 | "metadata": { 92 | "pycharm": { 93 | "metadata": false, 94 | "name": "#%%\n", 95 | "is_executing": false 96 | } 97 | } 98 | }, 99 | { 100 | "cell_type": "markdown", 101 | "source": "Learn how to call a range of data within the list:", 102 | "metadata": { 103 | "pycharm": { 104 | "metadata": false 105 | } 106 | } 107 | }, 108 | { 109 | "cell_type": "code", 110 | "execution_count": 15, 111 | "outputs": [], 112 | "source": "\n\n", 113 | "metadata": { 114 | "pycharm": { 115 | "metadata": false, 116 | "name": "#%%\n", 117 | "is_executing": false 118 | } 119 | } 120 | } 121 | ], 122 | "metadata": { 123 | "language_info": { 124 | "codemirror_mode": { 125 | "name": "ipython", 126 | "version": 2 127 | }, 128 | "file_extension": ".py", 129 | "mimetype": "text/x-python", 130 | "name": "python", 131 | "nbconvert_exporter": "python", 132 | "pygments_lexer": "ipython2", 133 | "version": "2.7.6" 134 | }, 135 | "kernelspec": { 136 | "name": "python3", 137 | "language": "python", 138 | "display_name": "Python 3" 139 | }, 140 | "stem_cell": { 141 | "cell_type": "raw", 142 | "source": "", 143 | "metadata": { 144 | "pycharm": { 145 | "metadata": false 146 | } 147 | } 148 | } 149 | }, 150 | "nbformat": 4, 151 | "nbformat_minor": 0 152 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![alt text](https://i.udemycdn.com/course/480x270/2597712_9552_2.jpg) 2 | 3 | # Alpha Vantage Tutorial 4 | 5 | Follow along with the tutorial videos: 6 | 7 | [Full Udemy Course](https://www.udemy.com/course/plotly-dash/?referralCode=16FC11D8981E0863E557) 8 | 9 | 10 | ## How to Install 11 | 12 | ``pip install -r requirements.txt`` 13 | 14 | Add [API Key](https://www.alphavantage.co/support/#support) to api_key within the file 15 | 16 | Run App & Enjoy 17 | 18 | # Useful Links 19 | 20 | [Alpha Vantage Docs](https://www.alphavantage.co/documentation/) 21 | 22 | [Alpha Vantage Github](https://github.com/RomelTorres/alpha_vantage) 23 | 24 | [Pandas Dataframes](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html) 25 | 26 | [Plotly](https://plot.ly/python/) 27 | 28 | [Dash Docs](https://dash.plot.ly/) 29 | 30 | ### Still Have Questions? 31 | [cryptopotluck.com](https://www.cryptopotluck.com) 32 | 33 | [cryptopotluck Discord](https://discord.gg/rNc6xtP) 34 | -------------------------------------------------------------------------------- /_alpha_vantage/alpha_dataframe.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | from alpha_vantage.techindicators import TechIndicators 3 | from alpha_vantage.timeseries import TimeSeries 4 | from _alpha_vantage.key import api_key 5 | import datetime 6 | 7 | stock = input('What stock do you want?') 8 | print('') 9 | 10 | api_key = api_key 11 | def rsi_dataframe(stock=stock): 12 | 13 | period = 60 14 | ts = TimeSeries(key=api_key, output_format='pandas') 15 | data_ts = ts.get_intraday(stock.upper(), interval='1min', outputsize='full') 16 | 17 | ti = TechIndicators(key=stock.upper(), output_format='pandas') 18 | 19 | data_ti, meta_data_ti = ti.get_bbands(symbol=stock.upper(), interval='1min', time_period=period, series_type='close') 20 | 21 | 22 | df = data_ts[0][period::] 23 | 24 | # df.index = pd.Index(map(lambda x: str(x)[:-3], df.index)) 25 | 26 | df2 = data_ti 27 | 28 | 29 | total_df = pd.merge(df, df2, on="date") 30 | 31 | low = [] 32 | for l in total_df['3. low']: 33 | low.append(float(l)) 34 | 35 | high = [] 36 | for h in total_df['2. high']: 37 | high.append(float(h)) 38 | 39 | bb_low = [] 40 | for bl in total_df['Real Lower Band']: 41 | bb_low.append(float(bl)) 42 | 43 | bb_high = [] 44 | for bh in total_df['Real Upper Band']: 45 | bb_high.append(float(bh)) 46 | 47 | 48 | buy = [] 49 | buy_index = [] 50 | 51 | for bl, p, i in zip(bb_low, low, total_df.index[::-1]): 52 | if p < bl: 53 | if not buy_index: 54 | buy.append(p) 55 | buy_index.append(i) 56 | else: 57 | index_need_to_beat = buy_index[-1] + datetime.timedelta(minutes=30) 58 | if i > index_need_to_beat: 59 | buy.append(p) 60 | buy_index.append(i) 61 | 62 | # If Price signals a good sell 63 | 64 | sell = [] 65 | sell_index = [] 66 | for bh, p, i in zip(bb_high, high, total_df.index[::-1]): 67 | if p < bh: 68 | if not sell_index: 69 | sell.append(p) 70 | sell_index.append(i) 71 | else: 72 | index_need_to_beat = sell_index[-1] + datetime.timedelta(minutes=30) 73 | if i > index_need_to_beat: 74 | sell.append(p) 75 | sell_index.append(i) 76 | 77 | buy_positions = 0 78 | profit = 0 79 | stocks = 0 80 | buy_point = 0 81 | sell_point = 0 82 | 83 | while buy_point != len(buy): 84 | if buy_index[buy_point] < sell_index[sell_point]: 85 | buy_positions += round(float(buy[buy_point])) 86 | print(f'buy position = {buy[buy_point]} total positions = {round(buy_positions, 2)} at sell index = {sell_index[sell_point]}') 87 | buy_point += 1 88 | stocks += 1 89 | else: 90 | print(f'sold at {sell[sell_point]}') 91 | profit += buy_positions - (float(sell[sell_point]) * stocks) 92 | profit = round(profit, 2) 93 | print(f'profit = {profit}') 94 | print('') 95 | buy_positions = 0 96 | stocks =0 97 | sell_point += 1 98 | else: 99 | pass 100 | 101 | # for h in total_df.head(): 102 | # print(h) 103 | return print(f'${profit}') 104 | rsi_dataframe() -------------------------------------------------------------------------------- /_alpha_vantage/alpha_rsi_dashboard.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | from alpha_vantage.techindicators import TechIndicators 3 | from alpha_vantage.timeseries import TimeSeries 4 | import dash 5 | import dash_html_components as html 6 | import dash_core_components as dcc 7 | from dash.dependencies import Input, Output, State 8 | import plotly.graph_objs as go 9 | 10 | 11 | external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css'] 12 | 13 | app = dash.Dash() 14 | 15 | app.layout = html.Div([ 16 | html.Link( 17 | rel='stylesheet', 18 | href='https://codepen.io/chriddyp/pen/bWLwgP.css' 19 | ), 20 | dcc.Input(id='input-box', value='', type='text', placeholder='Enter a Stock symbol', ), 21 | html.Button('Submit', id='button'), 22 | html.Div(), 23 | html.P('5 Calls Per Min'), 24 | dcc.Graph( 25 | id='candle-graph', animate=True, style={"backgroundColor": "#1a2d46", 'color':'#ffffff'},), 26 | html.Div([ 27 | html.P('Developed by: ', style={'display': 'inline', 'color' : 'white'}), 28 | html.A('Austin Kiese', href='http://www.austinkiese.com'), 29 | html.P(' - ', style={'display': 'inline', 'color' : 'white'}), 30 | html.A('cryptopotluck@gmail.com', href='mailto:cryptopotluck@gmail.com') 31 | ], className="twelve columns", 32 | style={'fontSize': 18, 'padding-top': 20} 33 | 34 | ) 35 | ]) 36 | 37 | api_key = '' 38 | period = 60 39 | ts = TimeSeries(key=api_key, output_format='pandas') 40 | ti = TechIndicators(key=api_key, output_format='pandas') 41 | 42 | @app.callback(Output('candle-graph', 'figure'), 43 | [Input('button', 'n_clicks')], 44 | [State('input-box', 'value')]) 45 | def update_layout(n_clicks, input_value): 46 | 47 | #Getting Dataframes Ready 48 | data_ts = ts.get_intraday(symbol=input_value.upper(), interval='1min', outputsize='full') 49 | data_ti, meta_data_ti = ti.get_rsi(symbol=input_value.upper(), interval='1min', time_period=period, series_type='close') 50 | 51 | df = data_ts[0][period::] 52 | 53 | df.index = pd.Index(map(lambda x: str(x)[:-3], df.index)) 54 | 55 | df2 = data_ti 56 | 57 | total_df = pd.concat([df, df2], axis=1, sort=True) 58 | 59 | #Breaking Down Datafames 60 | 61 | opens = [] 62 | for o in total_df['1. open']: 63 | opens.append(float(o)) 64 | 65 | high = [] 66 | for h in total_df['2. high']: 67 | high.append(float(h)) 68 | 69 | low = [] 70 | for l in total_df['3. low']: 71 | low.append(float(l)) 72 | 73 | close = [] 74 | for c in total_df['4. close']: 75 | close.append(float(c)) 76 | 77 | rsi_offset = [] 78 | 79 | for r, l in zip(total_df['RSI'], low): 80 | rsi_offset.append(l-(l / r)) 81 | 82 | #SELL SCATTER 83 | high_rsi_value = [] 84 | high_rsi_time = [] 85 | 86 | for value, time, l in zip(total_df['RSI'], total_df.index, low): 87 | if value > 60: 88 | high_rsi_value.append(l-(l/value)) 89 | high_rsi_time.append(time) 90 | 91 | #BUY SCATTER 92 | low_rsi_value = [] 93 | low_rsi_time = [] 94 | 95 | for value, time, l in zip(total_df['RSI'], total_df.index, low): 96 | if value < 35: 97 | low_rsi_value.append(l - (l / value)) 98 | low_rsi_time.append(time) 99 | 100 | 101 | scatter = go.Scatter( 102 | x=high_rsi_time, 103 | y=high_rsi_value, 104 | mode='markers', 105 | name='Sell' 106 | ) 107 | scatter_buy = go.Scatter( 108 | x=low_rsi_time, 109 | y=low_rsi_value, 110 | mode='markers', 111 | name='Buy' 112 | ) 113 | 114 | rsi = go.Scatter( 115 | x=total_df.index, 116 | y=rsi_offset, 117 | ) 118 | 119 | BuySide = go.Candlestick( 120 | x=total_df.index, 121 | open=opens, 122 | high=high, 123 | low=low, 124 | close=close, 125 | increasing={'line': {'color': '#00CC94'}}, 126 | decreasing={'line': {'color': '#F50030'}}, 127 | name='candlestick' 128 | ) 129 | data = [BuySide, rsi, scatter, scatter_buy] 130 | 131 | layout = go.Layout( 132 | paper_bgcolor='#27293d', 133 | plot_bgcolor='rgba(0,0,0,0)', 134 | xaxis=dict(type="category"), 135 | yaxis=dict(range=[min(rsi_offset), max(high)]), 136 | font=dict(color='white'), 137 | 138 | ) 139 | return {'data': data, 'layout': layout} 140 | 141 | 142 | if __name__ == '__main__': 143 | app.run_server(port=8085) 144 | 145 | 146 | -------------------------------------------------------------------------------- /_alpha_vantage/key.py: -------------------------------------------------------------------------------- 1 | api_key = '' -------------------------------------------------------------------------------- /_alpha_vantage/rsi_bb_dashbord.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | from alpha_vantage.techindicators import TechIndicators 3 | from alpha_vantage.timeseries import TimeSeries 4 | import dash 5 | import dash_html_components as html 6 | import dash_core_components as dcc, dash_table 7 | from dash.dependencies import Input, Output, State 8 | import plotly.graph_objs as go 9 | from _alpha_vantage.key import api_key 10 | import datetime 11 | 12 | external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css'] 13 | 14 | app = dash.Dash() 15 | 16 | app.layout = html.Div([ 17 | html.Link( 18 | rel='stylesheet', 19 | href='https://codepen.io/chriddyp/pen/bWLwgP.css' 20 | ), 21 | html.Div([ 22 | dcc.Input(id='input-box', value='', type='text', placeholder='Enter a Stock symbol', ), 23 | dcc.Input(id='wait-time-box', value='', type='number', placeholder='Wait Time Min.', ), 24 | dcc.Input(id='stocks-number-box', value='', type='number', placeholder='Stocks Per Buy', ), 25 | html.Button('Submit', id='button'), 26 | ]), 27 | html.Div(), 28 | html.P('5 Calls Per Min'), 29 | dcc.Tabs(id='tabs', value='graph-1', children=[ 30 | dcc.Tab(label='Bollinger Band', value='graph-1', children=[ 31 | html.H2(id='profit-text'), 32 | html.Div(dcc.Graph(id='candle-graph', animate=True, style={"backgroundColor": "#1a2d46", 'color':'#ffffff'},)), 33 | html.Div(id='table-div') 34 | ]), 35 | dcc.Tab(label='RSI', value='graph-2', children=[ 36 | html.Div( 37 | dcc.Graph(id='candle-graph2', animate=True, style={"backgroundColor": "#1a2d46", 'color':'#ffffff'},) 38 | ) 39 | ]) 40 | ]), 41 | 42 | html.Div([ 43 | html.P('Developed by: ', style={'display': 'inline', 'color' : 'white'}), 44 | html.A('Austin Kiese', href='http://www.austinkiese.com'), 45 | html.P(' - ', style={'display': 'inline', 'color' : 'white'}), 46 | html.A('cryptopotluck@gmail.com', href='mailto:cryptopotluck@gmail.com') 47 | ], className="twelve columns", 48 | style={'fontSize': 18, 'padding-top': 20} 49 | 50 | ) 51 | ]) 52 | 53 | api_key = api_key 54 | period = 60 55 | ts = TimeSeries(key=api_key, output_format='pandas') 56 | ti = TechIndicators(key=api_key, output_format='pandas') 57 | 58 | @app.callback([Output('candle-graph', 'figure'), 59 | Output('candle-graph2', 'figure'), 60 | Output('profit-text', 'children'), 61 | Output('table-div', 'children'), 62 | ], 63 | 64 | [Input('button', 'n_clicks'), 65 | Input('tabs', 'value')], 66 | 67 | [ 68 | State('input-box', 'value'), 69 | State('wait-time-box', 'value'), 70 | State('stocks-number-box', 'value'), 71 | ]) 72 | def update_layout(n_clicks, tab, input_value, input_wait, input_stocks): 73 | 74 | #Getting Dataframes Ready 75 | data_ts = ts.get_intraday(symbol=input_value.upper(), interval='1min', outputsize='full') 76 | data_ti, meta_data_ti = ti.get_rsi(symbol=input_value.upper(), interval='1min', time_period=period, series_type='close') 77 | data_ti2, meta_data_ti2 = ti.get_bbands(symbol=input_value.upper(), interval='1min', time_period=period, series_type='close') 78 | 79 | 80 | price_df = data_ts[0][period::] 81 | 82 | rsi_df = data_ti 83 | bb_df = data_ti2 84 | 85 | total_df = pd.merge(price_df, rsi_df, on='date') 86 | total_df = pd.merge(total_df, bb_df, on='date') 87 | 88 | """Price Data""" 89 | opens = [] 90 | for o in total_df['1. open']: 91 | opens.append(float(o)) 92 | 93 | high = [] 94 | for h in total_df['2. high']: 95 | high.append(float(h)) 96 | 97 | low = [] 98 | for l in total_df['3. low']: 99 | low.append(float(l)) 100 | 101 | close = [] 102 | for c in total_df['4. close']: 103 | close.append(float(c)) 104 | 105 | """Bollinger Bands Data""" 106 | bb_low = [] 107 | for bl in total_df['Real Lower Band']: 108 | bb_low.append(float(bl)) 109 | 110 | bb_middle =[] 111 | for bm in total_df['Real Middle Band']: 112 | bb_middle.append(bm) 113 | 114 | bb_high = [] 115 | for bh in total_df['Real Upper Band']: 116 | bb_high.append(float(bh)) 117 | 118 | buy = [] 119 | buy_index = [] 120 | 121 | for bl, p, i in zip(bb_low, low, total_df.index[::-1]): 122 | if p < bl: 123 | if not buy_index: 124 | buy.append(p) 125 | buy_index.append(i) 126 | else: 127 | index_need_to_beat = buy_index[-1] + datetime.timedelta(minutes=input_wait) 128 | if i > index_need_to_beat: 129 | buy.append(p) 130 | buy_index.append(i) 131 | 132 | # If Price signals a good sell 133 | 134 | sell = [] 135 | sell_index = [] 136 | for bh, p, i in zip(bb_high, high, total_df.index[::-1]): 137 | if p < bh: 138 | if not sell_index: 139 | sell.append(p) 140 | sell_index.append(i) 141 | else: 142 | index_need_to_beat = sell_index[-1] + datetime.timedelta(minutes=input_wait) 143 | if i > index_need_to_beat: 144 | sell.append(p) 145 | sell_index.append(i) 146 | 147 | buy_positions = 0 148 | profit = 0 149 | stock_buy_inc = input_stocks 150 | stocks = 0 151 | buy_point = 0 152 | sell_point = 0 153 | values_df_prep = {'index': [], 154 | 'Buy Price': [], 155 | 'Sell Price': [], 156 | 'Profit': [] 157 | } 158 | 159 | while buy_point != len(buy): 160 | if buy_index[buy_point] < sell_index[sell_point]: 161 | buy_positions += round(float(buy[buy_point] * stock_buy_inc)) 162 | stocks += stock_buy_inc 163 | values_df_prep['index'].append(buy_index[buy_point]) 164 | values_df_prep['Sell Price'].append(0) 165 | values_df_prep['Buy Price'].append(buy[buy_point]) 166 | values_df_prep['Profit'].append(f'{round(profit, 2)}') 167 | buy_point += 1 168 | else: 169 | sell_price = round(sell[sell_point] * stocks, 2) 170 | profit += sell_price - buy_positions 171 | values_df_prep['Buy Price'].append(0) 172 | values_df_prep['Sell Price'].append(round(sell[sell_point] * stocks, 2)) 173 | values_df_prep['index'].append(sell_index[sell_point]) 174 | values_df_prep['Profit'].append(f'{round(profit, 2)}') 175 | buy_positions = 0 176 | stocks = 0 177 | sell_point += 1 178 | else: 179 | pass 180 | 181 | profit_df = pd.DataFrame.from_dict(values_df_prep, orient='index') 182 | profit_df = profit_df.T 183 | 184 | """RSI Data""" 185 | rsi_offset = [] 186 | 187 | for r, l in zip(total_df['RSI'], low): 188 | rsi_offset.append(l-(l / r)) 189 | 190 | #SELL SCATTER 191 | sell_rsi_value = [] 192 | sell_rsi_time = [] 193 | 194 | for value, time, r in zip(total_df['RSI'], total_df.index, rsi_offset): 195 | if value > 60: 196 | if not sell_rsi_time: 197 | sell_rsi_value.append(r) 198 | sell_rsi_time.append(time) 199 | else: 200 | index_need_to_beat = sell_rsi_time[-1] + datetime.timedelta(minutes=input_wait) 201 | if time > index_need_to_beat: 202 | sell_rsi_value.append(r) 203 | sell_rsi_time.append(time) 204 | 205 | 206 | #BUY SCATTER 207 | buy_rsi_value = [] 208 | buy_rsi_time = [] 209 | 210 | for value, time, r in zip(total_df['RSI'], total_df.index, rsi_offset): 211 | if value < 35: 212 | if not buy_rsi_time: 213 | buy_rsi_value.append(r) 214 | sell_rsi_time.append(time) 215 | else: 216 | index_need_to_beat = buy_rsi_time[-1] + datetime.timedelta(minutes=input_wait) 217 | if time > index_need_to_beat: 218 | buy_rsi_value.append(r) 219 | sell_rsi_time.append(time) 220 | 221 | # BB Graph 222 | band_low = go.Scatter( 223 | x=total_df.index[::-1], 224 | y=bb_low 225 | ) 226 | band_middle = go.Scatter( 227 | x=total_df.index[::-1], 228 | y=bb_middle 229 | ) 230 | band_high = go.Scatter( 231 | x=total_df.index[::-1], 232 | y=bb_high 233 | ) 234 | buy_band = go.Scatter( 235 | x=buy_index, 236 | y=buy, 237 | mode = 'markers', 238 | name = 'Buy' 239 | 240 | ) 241 | sell_band = go.Scatter( 242 | x=sell_index, 243 | y=sell, 244 | mode = 'markers', 245 | name = 'Sell' 246 | ) 247 | 248 | # RSI Graph 249 | scatter = go.Scatter( 250 | x=sell_rsi_time, 251 | y=sell_rsi_value, 252 | mode='markers', 253 | name='Sell' 254 | ) 255 | scatter_buy = go.Scatter( 256 | x=buy_rsi_time, 257 | y=buy_rsi_value, 258 | mode='markers', 259 | name='Buy' 260 | ) 261 | 262 | rsi = go.Scatter( 263 | x=total_df.index[::-1], 264 | y=rsi_offset, 265 | ) 266 | 267 | #Price Action 268 | BuySide = go.Candlestick( 269 | x=total_df.index[::-1], 270 | open=opens, 271 | high=high, 272 | low=low, 273 | close=close, 274 | increasing={'line': {'color': '#00CC94'}}, 275 | decreasing={'line': {'color': '#F50030'}}, 276 | name='candlestick' 277 | ) 278 | 279 | data = [BuySide, rsi, scatter, scatter_buy] 280 | data_bb = [BuySide, band_low, band_middle, band_high, buy_band, sell_band] 281 | 282 | layout_bb = go.Layout( 283 | paper_bgcolor='#27293d', 284 | plot_bgcolor='rgba(0,0,0,0)', 285 | xaxis=dict(type="category"), 286 | yaxis=dict(range=[min(bb_low), max(bb_high)]), 287 | font=dict(color='white'), 288 | ) 289 | 290 | layout = go.Layout( 291 | paper_bgcolor='#27293d', 292 | plot_bgcolor='rgba(0,0,0,0)', 293 | xaxis=dict(type="category"), 294 | yaxis=dict(range=[min(rsi_offset), max(high)]), 295 | font=dict(color='white'), 296 | 297 | ) 298 | if tab == 'graph-1': 299 | return {'data': data_bb, 'layout': layout_bb}, {'data': data, 'layout': layout}, f'Profit = ${round(profit, 2)}', \ 300 | html.Div(dash_table.DataTable( 301 | id='table', 302 | columns=[{'name': i, 'id': i} for i in profit_df.columns], 303 | data=profit_df.to_dict('rows'), 304 | style_cell={'width': '300px', 305 | 'height': '30px', 306 | 'textAlign': 'left'} 307 | )) 308 | elif tab == 'graph-2': 309 | return {'data': data_bb, 'layout': layout_bb}, {'data': data, 'layout': layout}, f'Profit = ${round(profit, 2)}', \ 310 | html.Div(dash_table.DataTable( 311 | id='table', 312 | columns=[{'name': i, 'id': i} for i in profit_df.columns], 313 | data=profit_df.to_dict('rows'), 314 | style_cell={'width': '300px', 315 | 'height': '30px', 316 | 'textAlign': 'left'} 317 | )) 318 | 319 | 320 | if __name__ == '__main__': 321 | app.run_server(port=8085) 322 | 323 | 324 | -------------------------------------------------------------------------------- /core_components/datepicker.py: -------------------------------------------------------------------------------- 1 | import dash 2 | import dash_html_components as html 3 | import dash_core_components as dcc, dash_table 4 | from dash.dependencies import Input, Output 5 | from datetime import datetime as dt 6 | from _alpha_vantage.key import api_key 7 | from alpha_vantage.techindicators import TechIndicators 8 | from alpha_vantage.timeseries import TimeSeries 9 | 10 | 11 | 12 | 13 | 14 | external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css'] 15 | 16 | app = dash.Dash(__name__, external_stylesheets=external_stylesheets) 17 | 18 | app.layout = html.Div([ 19 | dcc.DatePickerSingle( 20 | id='date-picker-range', 21 | date=dt(2019, 5, 3), 22 | ), 23 | html.Div(id='date-content') 24 | ]) 25 | 26 | api_key = api_key 27 | period = 60 28 | ts = TimeSeries(key=api_key, output_format='pandas') 29 | 30 | 31 | 32 | @app.callback(Output('date-content', 'children'), 33 | [Input('date-picker-range', 'date')]) 34 | def render_content(date): 35 | data_ts = ts.get_daily(symbol='fb', outputsize='full') 36 | price_df = data_ts[0][period::] 37 | date = dt.strptime(date, '%Y-%m-%d') 38 | price_table = price_df.index > date 39 | 40 | return html.Div(dash_table.DataTable( 41 | id='table', 42 | columns=[{'name': i, 'id': i} for i in price_df[price_table].columns], 43 | data=price_df[price_table].to_dict('rows'), 44 | style_cell={'width': '300px', 45 | 'height': '30px', 46 | 'textAlign': 'left'} 47 | )) 48 | 49 | 50 | 51 | 52 | if __name__ == '__main__': 53 | app.run_server(debug=True) 54 | 55 | 166.23 56 | 11.4 57 | 166.23 -------------------------------------------------------------------------------- /core_components/dropdown.py: -------------------------------------------------------------------------------- 1 | import dash 2 | import dash_html_components as html 3 | import dash_core_components as dcc 4 | from dash.dependencies import Input, Output 5 | import requests, base64 6 | from io import BytesIO 7 | 8 | 9 | app = dash.Dash() 10 | 11 | def enconde_image(image_url): 12 | buffered = BytesIO(requests.get(image_url).content) 13 | image_base64 = base64.b64encode(buffered.getvalue()) 14 | return b'data:image/png;base64,' + image_base64 15 | 16 | 17 | app.layout = html.Div([ 18 | dcc.Dropdown( 19 | id='my-dropdown', 20 | options=[ 21 | {'label': 'New York City', 'value': 'NYC'}, 22 | {'label': 'Houston', 'value': 'TX'}, 23 | {'label': 'San Francisco', 'value': 'SF'} 24 | ], 25 | value='NYC', 26 | placeholder="Select a city", 27 | ), 28 | html.Div(id='output-container') 29 | ]) 30 | 31 | 32 | @app.callback( 33 | Output('output-container', 'children'), 34 | [Input('my-dropdown', 'value')]) 35 | def update_output(value): 36 | NYC_img = enconde_image('https://proxy.duckduckgo.com/iu/?u=https%3A%2F%2Fcincoveces.files.wordpress.com%2F2011%2F08%2Fnycpan2.jpg&f=1&nofb=1') 37 | TX_img = enconde_image('https://proxy.duckduckgo.com/iu/?u=https%3A%2F%2Fwww.sparefoot.com%2Fmoving%2Fwp-content%2Fuploads%2F2015%2F12%2FThinkstockPhotos-480535456-1-1.jpg&f=1&nofb=1') 38 | SF_img = enconde_image('https://proxy.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.hotelgsanfrancisco.com%2Fassets%2Fthemes%2Fhotelgsanfrancisco%2Fimg%2FHotelG-map.jpg&f=1&nofb=1') 39 | if value == 'NYC': 40 | return html.Div(html.Img(src=NYC_img.decode(), style={'width': '500px', 'height':'400px'})) 41 | elif value == 'TX': 42 | return html.Div(html.Img(src=TX_img.decode(), style={'width': '500px', 'height':'400px'})) 43 | elif value == 'SF': 44 | return html.Div(html.Img(src=SF_img.decode(), style={'width': '500px', 'height':'400px'})) 45 | 46 | 47 | if __name__ == '__main__': 48 | app.run_server(debug=True) -------------------------------------------------------------------------------- /core_components/markdown.py: -------------------------------------------------------------------------------- 1 | import dash 2 | import dash_html_components as html 3 | import dash_core_components as dcc 4 | 5 | app = dash.Dash() 6 | 7 | app.layout = html.Div([ 8 | dcc.Markdown(''' 9 | #### Dash and Markdown 10 | 11 | Dash supports [Markdown](http://commonmark.org/help). 12 | 13 | Markdown is a simple way to write and format text. 14 | It includes a syntax for things like **bold text** and *italics*, 15 | [links](http://commonmark.org/help), inline `code` snippets, lists, 16 | quotes, and more. 17 | '''), 18 | ]) 19 | 20 | 21 | if __name__ == '__main__': 22 | app.run_server(debug=True) -------------------------------------------------------------------------------- /core_components/range_slider.py: -------------------------------------------------------------------------------- 1 | import dash_core_components as dcc 2 | import dash_html_components as html 3 | from dash.dependencies import Input, Output 4 | import dash 5 | 6 | external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css'] 7 | 8 | app = dash.Dash(__name__, external_stylesheets=external_stylesheets) 9 | 10 | # Use the following function when accessing the value of 'my-slider' 11 | # in callbacks to transform the output value to logarithmic 12 | def transform_value(value): 13 | return 10 ** value 14 | 15 | 16 | app.layout = html.Div([ 17 | html.H1('Subtract'), 18 | dcc.RangeSlider( 19 | id='range_slider', 20 | min=0, 21 | max=30, 22 | value=[20, 10], 23 | ), 24 | html.Div( 25 | html.Div(id='solution', style={'margin-top': 20}), 26 | ) 27 | 28 | ]) 29 | 30 | 31 | @app.callback([ 32 | Output('solution', 'children'), 33 | ], 34 | [ 35 | Input('range_slider', 'value') 36 | ]) 37 | def display_value(value): 38 | return [f'You have selected {value[1]} - {value[0]} = {value[1]-value[0]}'] 39 | 40 | 41 | if __name__ == '__main__': 42 | app.run_server(debug=True) -------------------------------------------------------------------------------- /core_components/slider.py: -------------------------------------------------------------------------------- 1 | import dash_core_components as dcc 2 | import dash_html_components as html 3 | from dash.dependencies import Input, Output 4 | import plotly.graph_objs as go 5 | import dash 6 | 7 | external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css'] 8 | 9 | app = dash.Dash(__name__, external_stylesheets=external_stylesheets) 10 | 11 | 12 | app.layout = html.Div([ 13 | html.H1('Square Root Slider Graph'), 14 | dcc.Graph(id='slider-graph', animate=True, style={"backgroundColor": "#1a2d46", 'color': '#ffffff'}), 15 | dcc.Slider( 16 | id='slider-updatemode', 17 | marks={i: '{}'.format(i) for i in range(20)}, 18 | max=20, 19 | value=2, 20 | step=1, 21 | updatemode='drag', 22 | ), 23 | html.Div(id='updatemode-output-container', style={'margin-top': 20}) 24 | ]) 25 | 26 | 27 | @app.callback([ 28 | Output('slider-graph', 'figure'), 29 | Output('updatemode-output-container', 'children') 30 | ], 31 | [Input('slider-updatemode', 'value')]) 32 | def display_value(value): 33 | 34 | 35 | x = [] 36 | for i in range(value): 37 | x.append(i) 38 | 39 | y = [] 40 | for i in range(value): 41 | y.append(i*i) 42 | 43 | graph = go.Scatter( 44 | x=x, 45 | y=y, 46 | name='Manipulate Graph' 47 | ) 48 | layout = go.Layout( 49 | paper_bgcolor='#27293d', 50 | plot_bgcolor='rgba(0,0,0,0)', 51 | xaxis=dict(range=[min(x), max(x)]), 52 | yaxis=dict(range=[min(y), max(y)]), 53 | font=dict(color='white'), 54 | 55 | ) 56 | return {'data': [graph], 'layout': layout}, f'Value: {round(value, 1)} Square: {value*value}' 57 | 58 | 59 | if __name__ == '__main__': 60 | app.run_server(debug=True) -------------------------------------------------------------------------------- /core_components/tabs.py: -------------------------------------------------------------------------------- 1 | import dash 2 | import dash_html_components as html 3 | import dash_core_components as dcc 4 | from dash.dependencies import Input, Output 5 | 6 | 7 | external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css'] 8 | 9 | app = dash.Dash(__name__, external_stylesheets=external_stylesheets) 10 | 11 | app.layout = html.Div([ 12 | dcc.Tabs(id="tabs", value='tab-1', children=[ 13 | dcc.Tab(label='Tab one', value='tab-1'), 14 | dcc.Tab(label='Tab two', value='tab-2'), 15 | ]), 16 | html.Div(id='tabs-content') 17 | ]) 18 | 19 | @app.callback(Output('tabs-content', 'children'), 20 | 21 | [Input('tabs', 'value')]) 22 | def render_content(tab): 23 | if tab == 'tab-1': 24 | return html.Div([ 25 | html.H3('Tab content 1'), 26 | ]) 27 | elif tab == 'tab-2': 28 | return html.Div([ 29 | html.H3('Tab content 2'), 30 | ]) 31 | 32 | 33 | if __name__ == '__main__': 34 | app.run_server(debug=True) -------------------------------------------------------------------------------- /core_components/textarea.py: -------------------------------------------------------------------------------- 1 | import dash_core_components as dcc 2 | import dash_html_components as html 3 | from dash.dependencies import Input, Output 4 | import plotly.graph_objs as go 5 | import dash 6 | from collections import Counter 7 | 8 | external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css'] 9 | 10 | app = dash.Dash(__name__, external_stylesheets=external_stylesheets) 11 | 12 | # Use the following function when accessing the value of 'my-slider' 13 | # in callbacks to transform the output value to logarithmic 14 | def transform_value(value): 15 | return 10 ** value 16 | 17 | 18 | app.layout = html.Div([ 19 | html.H1('Common Words Graph'), 20 | dcc.Graph(id='txt-graph', animate=True, style={"backgroundColor": "#1a2d46", 'color': '#ffffff'}), 21 | dcc.Textarea( 22 | id='txt', 23 | placeholder='Common Words...', 24 | value='', 25 | style={'width': '100%'} 26 | ), 27 | html.Div(id='updatemode-output-container', style={'margin-top': 20}) 28 | ]) 29 | 30 | 31 | @app.callback( 32 | Output('txt-graph', 'figure') 33 | , 34 | [Input('txt', 'value')]) 35 | def display_value(value): 36 | 37 | word_list = value.split() 38 | 39 | word_dic=Counter(word_list) 40 | x = list(word_dic.keys()) 41 | y = list(word_dic.values()) 42 | 43 | graph = go.Bar( 44 | x=x, 45 | y=y, 46 | name='Manipulate Graph', 47 | type='bar', 48 | marker=dict(color='lightgreen') 49 | ) 50 | 51 | layout = go.Layout( 52 | paper_bgcolor='#27293d', 53 | plot_bgcolor='rgba(0,0,0,0)', 54 | xaxis=dict(type="category"), 55 | yaxis=dict(range=[min(y), max(y)]), 56 | font=dict(color='white'), 57 | 58 | ) 59 | return {'data': [graph], 'layout': layout} 60 | 61 | 62 | if __name__ == '__main__': 63 | app.run_server(debug=True) -------------------------------------------------------------------------------- /core_components/upload_csv.py: -------------------------------------------------------------------------------- 1 | import base64 2 | import datetime 3 | import io 4 | import dash 5 | from dash.dependencies import Input, Output, State 6 | import dash_core_components as dcc 7 | import dash_html_components as html 8 | import dash_table 9 | import pandas as pd 10 | 11 | 12 | external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css'] 13 | 14 | app = dash.Dash(__name__, external_stylesheets=external_stylesheets) 15 | 16 | app.layout = html.Div([ 17 | html.H1('Upload CSV or XLS', style={'text-align':'center'}), 18 | dcc.Upload( 19 | id='upload-data', 20 | children=html.Div([ 21 | 'Drag and Drop or ', 22 | html.A('Select Files') 23 | ]), 24 | style={ 25 | 'width': '100%', 26 | 'height': '60px', 27 | 'lineHeight': '60px', 28 | 'borderWidth': '1px', 29 | 'borderStyle': 'dashed', 30 | 'borderRadius': '5px', 31 | 'textAlign': 'center', 32 | 'margin': '10px' 33 | }, 34 | # Allow multiple files to be uploaded 35 | multiple=True 36 | ), 37 | html.Div(id='output-data-upload'), 38 | ]) 39 | 40 | 41 | def parse_contents(contents, filename, date): 42 | content_type, content_string = contents.split(',') 43 | 44 | decoded = base64.b64decode(content_string) 45 | try: 46 | if 'csv' in filename: 47 | # Assume that the user uploaded a CSV file 48 | df = pd.read_csv( 49 | io.StringIO(decoded.decode('utf-8'))) 50 | elif 'xls' in filename: 51 | # Assume that the user uploaded an excel file 52 | df = pd.read_excel(io.BytesIO(decoded)) 53 | except Exception as e: 54 | print(e) 55 | return html.Div([ 56 | 'There was an error processing this file.' 57 | ]) 58 | 59 | return html.Div([ 60 | html.H5(filename), 61 | html.H6(datetime.datetime.fromtimestamp(date)), 62 | 63 | dash_table.DataTable( 64 | data=df.to_dict('records'), 65 | columns=[{'name': i, 'id': i} for i in df.columns] 66 | ), 67 | 68 | html.Hr(), 69 | ]) 70 | 71 | 72 | @app.callback(Output('output-data-upload', 'children'), 73 | [Input('upload-data', 'contents')], 74 | [State('upload-data', 'filename'), 75 | State('upload-data', 'last_modified')]) 76 | def update_output(list_of_contents, list_of_names, list_of_dates): 77 | if list_of_contents is not None: 78 | children = [ 79 | parse_contents(c, n, d) for c, n, d in 80 | zip(list_of_contents, list_of_names, list_of_dates)] 81 | return children 82 | 83 | 84 | 85 | if __name__ == '__main__': 86 | app.run_server(debug=True) -------------------------------------------------------------------------------- /core_components/upload_img.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | 3 | import dash 4 | from dash.dependencies import Input, Output, State 5 | import dash_core_components as dcc 6 | import dash_html_components as html 7 | 8 | external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css'] 9 | 10 | app = dash.Dash(__name__, external_stylesheets=external_stylesheets) 11 | 12 | app.layout = html.Div([ 13 | html.H1('Upload Images', style={'text-align': 'center'}), 14 | dcc.Upload( 15 | id='upload-image', 16 | children=html.Div([ 17 | 'Drag and Drop or ', 18 | html.A('Select Files') 19 | ]), 20 | style={ 21 | 'width': '100%', 22 | 'height': '60px', 23 | 'lineHeight': '60px', 24 | 'borderWidth': '1px', 25 | 'borderStyle': 'dashed', 26 | 'borderRadius': '5px', 27 | 'textAlign': 'center', 28 | 'margin': '10px' 29 | }, 30 | # Allow multiple files to be uploaded 31 | multiple=True 32 | ), 33 | html.Div(id='output-image-upload'), 34 | ]) 35 | 36 | 37 | def parse_contents(contents, filename, date): 38 | return html.Div([ 39 | html.H5(filename), 40 | html.H6(datetime.datetime.fromtimestamp(date)), 41 | 42 | # HTML images accept base64 encoded strings in the same format 43 | # that is supplied by the upload 44 | html.Img(src=contents, style={'width': '500px', 'height':'400px'}), 45 | html.Hr(), 46 | html.Div('Raw Content'), 47 | html.Pre(contents[0:200] + '...', style={ 48 | 'whiteSpace': 'pre-wrap', 49 | 'wordBreak': 'break-all' 50 | }) 51 | ]) 52 | 53 | 54 | @app.callback(Output('output-image-upload', 'children'), 55 | [Input('upload-image', 'contents')], 56 | [State('upload-image', 'filename'), 57 | State('upload-image', 'last_modified')]) 58 | def update_output(list_of_contents, list_of_names, list_of_dates): 59 | if list_of_contents is not None: 60 | children = [ 61 | parse_contents(c, n, d) for c, n, d in 62 | zip(list_of_contents, list_of_names, list_of_dates)] 63 | return children 64 | 65 | 66 | if __name__ == '__main__': 67 | app.run_server(debug=True) -------------------------------------------------------------------------------- /dash_bootstrap/bootstrap_basics.py: -------------------------------------------------------------------------------- 1 | """ 2 | A simple app demonstrating how to manually construct a navbar with a customised 3 | layout using the Navbar component and the supporting Nav, NavItem, NavLink, 4 | NavbarBrand, and NavbarToggler components. 5 | Requires dash-bootstrap-components 0.3.0 or later 6 | """ 7 | import dash 8 | import dash_bootstrap_components as dbc 9 | import dash_html_components as html 10 | from dash.dependencies import Input, Output, State 11 | import requests, base64 12 | from io import BytesIO 13 | import dash_core_components as dcc 14 | import plotly.graph_objs as go 15 | from collections import Counter 16 | 17 | PLOTLY_LOGO = "https://potluckspaces.sfo2.cdn.digitaloceanspaces.com/static/img/contentcreator.png" 18 | 19 | app = dash.Dash(external_stylesheets=[dbc.themes.BOOTSTRAP]) 20 | # try running the app with one of the Bootswatch themes e.g. 21 | # app = dash.Dash(external_stylesheets=[dbc.themes.JOURNAL]) 22 | # app = dash.Dash(external_stylesheets=[dbc.themes.SKETCHY]) 23 | 24 | 25 | """Navbar""" 26 | #dropdown Items 27 | 28 | # make a reuseable navitem for the different examples 29 | nav_item = dbc.NavItem(dbc.NavLink("Dash Udemy Course", href="https://www.udemy.com/course/plotly-dash/?referralCode=16FC11D8981E0863E557")) 30 | 31 | # make a reuseable dropdown for the different examples 32 | dropdown = dbc.DropdownMenu( 33 | children=[ 34 | dbc.DropdownMenuItem("Youtube Channel", href='https://www.youtube.com/channel/UC-pBvv8mzLpj0k-RIbc2Nog?view_as=subscriber'), 35 | dbc.DropdownMenuItem("Potluck App", href='https://cryptopotluck.com/'), 36 | dbc.DropdownMenuItem(divider=True), 37 | dbc.DropdownMenuItem("Project Github", href='https://github.com/cryptopotluck/alpha_vantage_tutorial'), 38 | dbc.DropdownMenuItem("Plotly / Dash", href='https://dash.plot.ly/'), 39 | dbc.DropdownMenuItem("Dash Bootstrap", href='https://dash-bootstrap-components.opensource.faculty.ai/'), 40 | ], 41 | nav=True, 42 | in_navbar=True, 43 | label="Important Links", 44 | ) 45 | 46 | #Navbar Layout 47 | navbar = dbc.Navbar( 48 | dbc.Container( 49 | [ 50 | html.A( 51 | # Use row and col to control vertical alignment of logo / brand 52 | dbc.Row( 53 | [ 54 | dbc.Col(html.Img(src=PLOTLY_LOGO, height="30px")), 55 | dbc.Col(dbc.NavbarBrand("CryptoPotluck", className="ml-2")), 56 | ], 57 | align="center", 58 | no_gutters=True, 59 | ), 60 | href="https://plot.ly", 61 | ), 62 | dbc.NavbarToggler(id="navbar-toggler2"), 63 | dbc.Collapse( 64 | dbc.Nav( 65 | [nav_item, 66 | dropdown, 67 | ], className="ml-auto", navbar=True 68 | ), 69 | id="navbar-collapse2", 70 | navbar=True, 71 | ), 72 | ] 73 | ), 74 | color="dark", 75 | dark=True, 76 | className="mb-5", 77 | ) 78 | 79 | ##################################################################################### 80 | """App Components""" 81 | #Dropdown App 82 | def enconde_image(image_url): 83 | buffered = BytesIO(requests.get(image_url).content) 84 | image_base64 = base64.b64encode(buffered.getvalue()) 85 | return b'data:image/png;base64,' + image_base64 86 | 87 | 88 | DropdownApp = html.Div([ 89 | dcc.Dropdown( 90 | id='my-dropdown', 91 | options=[ 92 | {'label': 'New York City', 'value': 'NYC'}, 93 | {'label': 'Houston', 'value': 'TX'}, 94 | {'label': 'San Francisco', 'value': 'SF'} 95 | ], 96 | value='NYC', 97 | placeholder="Select a city", 98 | ), 99 | html.Div(id='output-container') 100 | ]) 101 | 102 | #Textarea App 103 | def transform_value(value): 104 | return 10 ** value 105 | 106 | 107 | TextApp = html.Div([ 108 | html.H1('Common Words Graph'), 109 | dcc.Graph(id='txt-graph', animate=True, style={"backgroundColor": "#1a2d46", 'color': '#ffffff'}), 110 | dcc.Textarea( 111 | id='txt', 112 | placeholder='Common Words...', 113 | value='', 114 | style={'width': '100%'} 115 | ), 116 | html.Div(id='text-output-container', style={'margin-top': 20}) 117 | ]) 118 | 119 | #Slider 120 | SliderApp = html.Div([ 121 | html.H1('Square Root Slider Graph'), 122 | dcc.Graph(id='slider-graph', animate=True, style={"backgroundColor": "#1a2d46", 'color': '#ffffff'}), 123 | dcc.Slider( 124 | id='slider-updatemode', 125 | marks={i: '{}'.format(i) for i in range(20)}, 126 | max=20, 127 | value=2, 128 | step=1, 129 | updatemode='drag', 130 | ), 131 | html.Div(id='updatemode-output-container', style={'margin-top': 20}) 132 | ]) 133 | 134 | """Body Components""" 135 | #Cards 136 | cardOne = dbc.Card( 137 | [ 138 | dbc.CardImg(src="https://i.imgur.com/JnUeE7g.png", top=True), 139 | dbc.CardBody( 140 | [ 141 | html.H4("Dropdown Components & Images", className="card-title"), 142 | html.P( 143 | "We learn how to create dropdown components & render different types of image types within dash applications.", 144 | className="card-text", 145 | ), 146 | dbc.Button("Open App", id="open", color='warning', style={'margin': 'auto', 'width': '100%'}), 147 | dbc.Modal( 148 | [ 149 | dbc.ModalHeader("Modal"), 150 | dbc.ModalBody(DropdownApp), 151 | dbc.ModalFooter( 152 | dbc.Button("Close", id="close", className="ml-auto") 153 | ), 154 | ], 155 | id="modal", 156 | ), 157 | ] 158 | ), 159 | ], 160 | style={"width": "18rem"}, 161 | ) 162 | 163 | cardTwo = dbc.Card( 164 | [ 165 | dbc.CardImg(src="https://i.imgur.com/mItJUKG.png", top=True), 166 | dbc.CardBody( 167 | [ 168 | html.H4("Sq Root Slider", className="card-title"), 169 | html.P( 170 | "This simple line graph highlights the slider" 171 | "as it calculates the sq root based off the two numbers selected by the slider", 172 | className="card-text", 173 | ), 174 | dbc.Button("Open App", id="opentwo", color='primary', style={'margin': 'auto', 'width': '100%'}), 175 | dbc.Modal( 176 | [ 177 | dbc.ModalHeader("Modal"), 178 | dbc.ModalBody(SliderApp), 179 | dbc.ModalFooter( 180 | dbc.Button("Close", id="closetwo", className="ml-auto") 181 | ), 182 | ], 183 | id="modaltwo", 184 | ), 185 | ] 186 | ), 187 | ], 188 | style={"width": "18rem"}, 189 | ) 190 | 191 | cardThree = dbc.Card( 192 | [ 193 | dbc.CardImg(src="https://i.imgur.com/a9rphkb.png", top=True), 194 | dbc.CardBody( 195 | [ 196 | html.H4("Word Distribution Counter", className="card-title"), 197 | html.P( 198 | "This App will break down paragraphs or long articles & count & map the word distribution " 199 | "providing a powerful tool for figuring out keywords.", 200 | className="card-text", 201 | ), 202 | dbc.Button("Open App", id="openthree", color='success', style={'margin': 'auto', 'width': '100%'}), 203 | dbc.Modal( 204 | [ 205 | dbc.ModalHeader("Modal"), 206 | dbc.ModalBody(TextApp), 207 | dbc.ModalFooter( 208 | dbc.Button("Close", id="closethree", className="ml-auto") 209 | ), 210 | ], 211 | id="modalthree", 212 | ), 213 | ] 214 | ), 215 | ], 216 | style={"width": "18rem"}, 217 | ) 218 | 219 | card_content = [ 220 | dbc.CardHeader("Dash-Bootstrap-Components Tutorial"), 221 | dbc.CardBody( 222 | [ 223 | html.H5("Styling Made Simple", className="card-title"), 224 | html.P( 225 | "This tutorial we will learn the fundamentals to an awesome addition to dash that will allow us to integrate bootstap functionality into our projects & we will embed three of our apps we developed from the Udemy course.", 226 | className="card-text", 227 | ), 228 | ] 229 | ), 230 | ] 231 | 232 | """Body""" 233 | #rows 234 | row = html.Div( 235 | [ 236 | dbc.Row(html.Img(src="https://i.imgur.com/dHZLL1a.png", style={'float': 'right', 'clear': 'right', 'margin-left': '19%', 'width': '80vw', 'height': '30vh'})), 237 | dbc.Row(dbc.Col(html.Div(dbc.Col(dbc.Card(card_content, color="dark", inverse=True)),))), 238 | dbc.Row(html.P('')), 239 | dbc.Row( 240 | [ 241 | dbc.Col(html.Div(cardOne)), 242 | dbc.Col(html.Div(cardTwo)), 243 | dbc.Col(html.Div(cardThree)), 244 | ], 245 | style={'margin': 'auto', 'width': '80vw'} 246 | ), 247 | ] 248 | ) 249 | ##################################################################################### 250 | 251 | """Layout""" 252 | 253 | app.layout = html.Div( 254 | [navbar, row] 255 | ) 256 | 257 | 258 | """Apps Functions""" 259 | #dropdown App 260 | @app.callback( 261 | Output('output-container', 'children'), 262 | [Input('my-dropdown', 'value')]) 263 | def update_output(value): 264 | NYC_img = enconde_image('https://proxy.duckduckgo.com/iu/?u=https%3A%2F%2Fcincoveces.files.wordpress.com%2F2011%2F08%2Fnycpan2.jpg&f=1&nofb=1') 265 | TX_img = enconde_image('https://proxy.duckduckgo.com/iu/?u=https%3A%2F%2Fwww.sparefoot.com%2Fmoving%2Fwp-content%2Fuploads%2F2015%2F12%2FThinkstockPhotos-480535456-1-1.jpg&f=1&nofb=1') 266 | SF_img = enconde_image('https://proxy.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.hotelgsanfrancisco.com%2Fassets%2Fthemes%2Fhotelgsanfrancisco%2Fimg%2FHotelG-map.jpg&f=1&nofb=1') 267 | if value == 'NYC': 268 | return html.Div(html.Img(src=NYC_img.decode(), style={'width': '100%', 'height':'400px'})) 269 | elif value == 'TX': 270 | return html.Div(html.Img(src=TX_img.decode(), style={'width': '100%', 'height':'400px'})) 271 | elif value == 'SF': 272 | return html.Div(html.Img(src=SF_img.decode(), style={'width': '100%', 'height':'400px'})) 273 | 274 | #Slider App 275 | @app.callback([ 276 | Output('slider-graph', 'figure'), 277 | Output('updatemode-output-container', 'children') 278 | ], 279 | [Input('slider-updatemode', 'value')]) 280 | def display_value(value): 281 | 282 | 283 | x = [] 284 | for i in range(value): 285 | x.append(i) 286 | 287 | y = [] 288 | for i in range(value): 289 | y.append(i*i) 290 | 291 | graph = go.Scatter( 292 | x=x, 293 | y=y, 294 | name='Manipulate Graph' 295 | ) 296 | layout = go.Layout( 297 | paper_bgcolor='#27293d', 298 | plot_bgcolor='rgba(0,0,0,0)', 299 | xaxis=dict(range=[min(x), max(x)]), 300 | yaxis=dict(range=[min(y), max(y)]), 301 | font=dict(color='white'), 302 | 303 | ) 304 | return {'data': [graph], 'layout': layout}, f'Value: {round(value, 1)} Square: {value*value}' 305 | 306 | #Text App 307 | @app.callback( 308 | Output('txt-graph', 'figure') 309 | , 310 | [Input('txt', 'value')]) 311 | def display_value(value): 312 | 313 | word_list = value.split() 314 | 315 | word_dic=Counter(word_list) 316 | x = list(word_dic.keys()) 317 | y = list(word_dic.values()) 318 | 319 | graph = go.Bar( 320 | x=x, 321 | y=y, 322 | name='Manipulate Graph', 323 | type='bar', 324 | marker=dict(color='lightgreen') 325 | ) 326 | 327 | layout = go.Layout( 328 | paper_bgcolor='#27293d', 329 | plot_bgcolor='rgba(0,0,0,0)', 330 | xaxis=dict(type="category"), 331 | yaxis=dict(range=[min(y), max(y)]), 332 | font=dict(color='white'), 333 | 334 | ) 335 | return {'data': [graph], 'layout': layout} 336 | 337 | #module One 338 | @app.callback( 339 | Output("modal", "is_open"), 340 | [Input("open", "n_clicks"), Input("close", "n_clicks")], 341 | [State("modal", "is_open")], 342 | ) 343 | def toggle_modal(n1, n2, is_open): 344 | if n1 or n2: 345 | return not is_open 346 | return is_open 347 | #Module Two 348 | @app.callback( 349 | Output("modaltwo", "is_open"), 350 | [Input("opentwo", "n_clicks"), Input("closetwo", "n_clicks")], 351 | [State("modaltwo", "is_open")], 352 | ) 353 | def toggle_modal(n1, n2, is_open): 354 | if n1 or n2: 355 | return not is_open 356 | return is_open 357 | 358 | #Module Three 359 | @app.callback( 360 | Output("modalthree", "is_open"), 361 | [Input("openthree", "n_clicks"), Input("closethree", "n_clicks")], 362 | [State("modalthree", "is_open")], 363 | ) 364 | def toggle_modal(n1, n2, is_open): 365 | if n1 or n2: 366 | return not is_open 367 | return is_open 368 | 369 | 370 | # we use a callback to toggle the collapse on small screens 371 | def toggle_navbar_collapse(n, is_open): 372 | if n: 373 | return not is_open 374 | return is_open 375 | 376 | 377 | # the same function (toggle_navbar_collapse) is used in all three callbacks 378 | for i in [2]: 379 | app.callback( 380 | Output(f"navbar-collapse{i}", "is_open"), 381 | [Input(f"navbar-toggler{i}", "n_clicks")], 382 | [State(f"navbar-collapse{i}", "is_open")], 383 | )(toggle_navbar_collapse) 384 | 385 | if __name__ == "__main__": 386 | app.run_server(debug=True, port=8888) -------------------------------------------------------------------------------- /plotly_graphs/binance_account_piechard_dashboard.py: -------------------------------------------------------------------------------- 1 | from binance.client import Client 2 | import plotly.offline as pyo 3 | import plotly.graph_objs as go 4 | import pandas as pd 5 | from plotly_graphs.binance_api_keys import APIKey, SecretKey 6 | 7 | client = Client(api_key=APIKey, api_secret=SecretKey) 8 | pd.set_option('float_format', '{:f}'.format) 9 | 10 | 11 | def grab_binance_ballance(): 12 | account = client.get_account() 13 | clean_df = pd.DataFrame(account['balances']) 14 | for index, row in clean_df.iterrows(): 15 | if float(row['free']) < 0.01: 16 | clean_df.drop(index, inplace=True) 17 | 18 | clean_df['asset'] = clean_df['asset'].astype(str) + 'BTC' 19 | clean_df.set_index('asset', inplace=True) 20 | clean_df = clean_df.drop('locked', axis=1) 21 | return clean_df 22 | 23 | 24 | print(grab_binance_ballance()) 25 | 26 | 27 | # %% 28 | 29 | def grab_btc_equivalent(): 30 | prices = client.get_all_tickers() 31 | cleandf = pd.DataFrame(prices) 32 | cleandf.set_index('symbol', inplace=True) 33 | 34 | return cleandf 35 | 36 | 37 | print(grab_btc_equivalent()) 38 | 39 | 40 | # %% 41 | 42 | def grab_btc(): 43 | prices = client.get_symbol_ticker(symbol='BTCTUSD') 44 | cleandf = pd.DataFrame(prices, index=[0]) 45 | cleandf.set_index('symbol', inplace=True) 46 | cleandf = float(cleandf['price'][0]) 47 | return cleandf 48 | 49 | 50 | print(grab_btc()) 51 | 52 | 53 | # %% 54 | 55 | def compare_BTC_equivalent_and_binance_balance(): 56 | btc_symbol = grab_btc_equivalent() 57 | binance_ballance = grab_binance_ballance() 58 | btc_value = grab_btc() 59 | 60 | filtered_df = btc_symbol.join(binance_ballance) 61 | filtered_df = filtered_df.dropna() 62 | filtered_df[['price', 'free']] = filtered_df[['price', 'free']].astype(float) 63 | filtered_df['btc_value'] = filtered_df['price'] * filtered_df['free'] 64 | filtered_df['usd_value'] = filtered_df['btc_value'].multiply(float(btc_value)) 65 | filtered_df = filtered_df[filtered_df.usd_value > 3.00] 66 | return filtered_df 67 | 68 | 69 | print(compare_BTC_equivalent_and_binance_balance()) 70 | 71 | # %% 72 | 73 | df = compare_BTC_equivalent_and_binance_balance() 74 | 75 | values = [] 76 | 77 | for marketcap in df['usd_value'].unique(): 78 | values.append(int(marketcap)) 79 | 80 | labels = [] 81 | for name in df.index.unique(): 82 | labels.append(str(name)) 83 | 84 | trace = go.Pie(labels=labels, values=values, domain={'x': [0, .48]}, hoverinfo='label+value', hole=0.4) 85 | 86 | layout = go.Layout( 87 | title='Binance: Total Asset Breakdown', 88 | paper_bgcolor='black', 89 | titlefont={"size": 30, 'color': '#ffffff'}, 90 | legend={"font": {"color": '#ffffff'}}, 91 | annotations=[{"font": { 92 | "size": 20, 93 | "color": '#ffffff', 94 | 95 | }, 96 | 97 | "showarrow": False, 98 | "text": "Portfolio", 99 | "x": 0.19, 100 | "y": 0.5}]) 101 | 102 | data = [trace] 103 | 104 | fig = go.Figure(data=data, layout=layout) 105 | 106 | pyo.plot(fig) 107 | 108 | -------------------------------------------------------------------------------- /plotly_graphs/binance_api_keys.py: -------------------------------------------------------------------------------- 1 | APIKey = '' 2 | SecretKey = '' -------------------------------------------------------------------------------- /plotly_graphs/coingecko_v_s_bubble_graph.py: -------------------------------------------------------------------------------- 1 | from plotly.offline import plot 2 | from pycoingecko import CoinGeckoAPI 3 | from pandas import DataFrame as df 4 | from plotly_graphs.image import encoded_image 5 | cg = CoinGeckoAPI() 6 | 7 | 8 | def getCurrency(name): 9 | data = cg.get_coins_markets(vs_currency='usd', ids=name, order='market_cap_desc', per_page='100', page='1', 10 | price_change_percentage='1h') 11 | return data[0] 12 | 13 | 14 | def getALL(): 15 | currency = ['civic', 'dogecoin', 'true-usd', 'ripple'] 16 | allcoins = [] 17 | 18 | for coin in currency: 19 | result = getCurrency(coin) 20 | 21 | allcoins.append(result) 22 | allcoins.sort(key=lambda c: c['market_cap_rank']) 23 | 24 | return allcoins 25 | 26 | 27 | dataframe = df(getALL()) 28 | dataframe.set_index('symbol', inplace=True) 29 | 30 | 31 | colors = ['blue', 'orange', 'green', 'red'] 32 | 33 | opt = [] 34 | opts = [] 35 | for i in range(0, len(colors)): 36 | opt = dict( 37 | target = dataframe['name'][[i]].unique(), value = dict(marker = dict(color = colors[i])) 38 | ) 39 | opts.append(opt) 40 | 41 | data = [dict( 42 | type = 'scatter', 43 | mode = 'markers', 44 | x = dataframe['circulating_supply'], 45 | y = dataframe['total_volume'], 46 | text = dataframe['name'], 47 | hoverinfo = 'text', 48 | opacity = 0.8, 49 | marker = dict( 50 | size = dataframe['total_volume'] /10000 , 51 | sizemode = 'area', 52 | ), 53 | transforms = [ 54 | dict( 55 | type = 'groupby', 56 | groups = dataframe['name'], 57 | styles = opts 58 | ) 59 | ] 60 | )] 61 | 62 | layout = dict( 63 | title = 'Gapminder
2007 Average GDP Per Cap & Life Exp. by Continent', 64 | yaxis = dict( 65 | type = 'log' 66 | ), 67 | images=[dict( 68 | source=encoded_image, 69 | xref="paper", yref="paper", 70 | x=1.1, y=-0.1, 71 | sizex=0.5, sizey=0.75, 72 | sizing='stretch', 73 | opacity=0.5, 74 | xanchor="right", yanchor="bottom" 75 | )], 76 | ) 77 | 78 | 79 | plot({'data': data, 'layout': layout}, validate=False) 80 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | alpha-vantage==2.1.1 2 | appnope==0.1.0 3 | asn1crypto==1.0.1 4 | attrs==19.2.0 5 | autobahn==19.10.1 6 | Automat==0.7.0 7 | backcall==0.1.0 8 | bleach==3.1.0 9 | certifi==2019.9.11 10 | cffi==1.12.3 11 | chardet==3.0.4 12 | Click==7.0 13 | constantly==15.1.0 14 | cryptography==2.7 15 | dash==1.3.1 16 | dash-core-components==1.2.1 17 | dash-html-components==1.0.1 18 | dash-renderer==1.1.0 19 | dash-table==4.3.0 20 | dateparser==0.7.2 21 | decorator==4.4.0 22 | defusedxml==0.6.0 23 | docopt==0.6.2 24 | entrypoints==0.3 25 | Flask==1.1.1 26 | Flask-Compress==1.4.0 27 | future==0.17.1 28 | hyperlink==19.0.0 29 | idna==2.8 30 | importlib-metadata==0.23 31 | incremental==17.5.0 32 | ipykernel==5.1.2 33 | ipython==7.8.0 34 | ipython-genutils==0.2.0 35 | ipywidgets==7.5.1 36 | itsdangerous==1.1.0 37 | jedi==0.15.1 38 | Jinja2==2.10.1 39 | jsonschema==3.1.1 40 | jupyter==1.0.0 41 | jupyter-client==5.3.4 42 | jupyter-console==6.0.0 43 | jupyter-core==4.6.0 44 | MarkupSafe==1.1.1 45 | mistune==0.8.4 46 | more-itertools==7.2.0 47 | nbconvert==5.6.0 48 | nbformat==4.4.0 49 | notebook==6.0.1 50 | numpy==1.17.2 51 | pandas==0.25.1 52 | pandocfilters==1.4.2 53 | parso==0.5.1 54 | pexpect==4.7.0 55 | pickleshare==0.7.5 56 | pipreqs==0.4.9 57 | plotly==4.1.1 58 | prometheus-client==0.7.1 59 | prompt-toolkit==2.0.10 60 | ptyprocess==0.6.0 61 | pyasn1==0.4.7 62 | pyasn1-modules==0.2.7 63 | pycoingecko==0.4.0 64 | pycparser==2.19 65 | Pygments==2.4.2 66 | PyHamcrest==1.9.0 67 | pyOpenSSL==19.0.0 68 | pyrsistent==0.15.4 69 | python-binance==0.7.4 70 | python-dateutil==2.8.0 71 | pytz==2019.2 72 | pyzmq==18.1.0 73 | qtconsole==4.5.5 74 | regex==2019.8.19 75 | requests==2.22.0 76 | retrying==1.3.3 77 | Send2Trash==1.5.0 78 | service-identity==18.1.0 79 | six==1.12.0 80 | terminado==0.8.2 81 | testpath==0.4.2 82 | tornado==6.0.3 83 | traitlets==4.3.3 84 | Twisted==19.7.0 85 | txaio==18.8.1 86 | tzlocal==2.0.0 87 | urllib3==1.25.6 88 | wcwidth==0.1.7 89 | webencodings==0.5.1 90 | Werkzeug==0.16.0 91 | widgetsnbextension==3.5.1 92 | yarg==0.1.9 93 | zipp==0.6.0 94 | zope.interface==4.6.0 95 | --------------------------------------------------------------------------------