├── .gitignore ├── LICENSE ├── environment.yml ├── events.ipynb ├── index.ipynb ├── postBuild ├── requirements_dev.txt └── webinar_jlab_demo.ipynb /.gitignore: -------------------------------------------------------------------------------- 1 | # IntelliJ IDEA (IDE-related files) 2 | *.iml 3 | .idea/* 4 | .ipynb_checkpoints/* 5 | 6 | # OS X 7 | .DS_Store 8 | 9 | node_modules/* 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /environment.yml: -------------------------------------------------------------------------------- 1 | name: qgrid-environment 2 | channels: 3 | - conda-forge 4 | - defaults 5 | dependencies: 6 | - jupyterlab 7 | - qgrid 8 | - pandas-datareader>=0.5.0 9 | - matplotlib>=2.1.1 10 | 11 | -------------------------------------------------------------------------------- /events.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Linking qgrid to other visualizations using event callbacks\n", 8 | "===============================================\n", 9 | "\n", 10 | "The following examples use qgrid's new \"events API\" that is only available in qgrid version 1.0.3 or newer. Specifically this notebook makes use of the ``on`` methods that qgrid provides for attaching event handlers. Event handlers can be attached using the ``qgrid.on`` method to listen for events on all widgets, or using the ``QgridWidget.on`` method the to listen for events on individual QgridWidget instances. " 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "metadata": {}, 16 | "source": [ 17 | "## Example 1 - Filter matplotlib scatter plot using qgrid\n", 18 | "In this example you'll see that by listening for a QgridWidget instances's ``filter_changed`` event, we can use qgrid to filter the data that's being visualized by another control in the notebook, in this case a matplotlib scatter plot. \n", 19 | "\n", 20 | "This capability allows you to filter a visualization by ANY field in the underlying DataFrame, including fields that are not used to generate the visualization. This enables interesting workflows like using a Categorical column to mark a particular row of the DataFrame with as \"bad\", setting a filter to hide \"bad\" rows in the qgrid instance, and then seeing the \"bad\" rows also disappear from any visualizations that the qgrid instance is hooked up to.\n", 21 | "\n", 22 | "The try out a simple example of using qgrid to filter another visualization, first execute the following two cells. Once you do that you should see a qgrid instance and a matplotlib scatter plot showing the same data as the qgrid instance. Next, set some filters on the columns of the qgrid instance and watch what happens to the scatter plot. You should see it update immediately to reflect the filtering changes." 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": null, 28 | "metadata": {}, 29 | "outputs": [], 30 | "source": [ 31 | "import numpy as np\n", 32 | "import pandas as pd\n", 33 | "import qgrid\n", 34 | "randn = np.random.randn\n", 35 | "df_types = pd.DataFrame({\n", 36 | " 'A' : 1.,\n", 37 | " 'B' : pd.Series(['2013-01-01', '2013-01-02', '2013-01-03', '2013-01-04',\n", 38 | " '2013-01-05', '2013-01-06', '2013-01-07', '2013-01-08', '2013-01-09'],index=list(range(9)),dtype='datetime64[ns]'),\n", 39 | " 'C' : pd.Series(randn(9),index=list(range(9)),dtype='float32'),\n", 40 | " 'D' : np.array([3] * 9,dtype='int32'),\n", 41 | " 'E' : pd.Categorical([\"washington\", \"adams\", \"washington\", \"madison\", \"lincoln\",\"jefferson\", \"hamilton\", \"roosevelt\", \"kennedy\"]),\n", 42 | " 'F' : [\"foo\", \"bar\", \"buzz\", \"bippity\",\"boppity\", \"foo\", \"foo\", \"bar\", \"zoo\"] })\n", 43 | "df_types['G'] = df_types['F'] == 'foo'\n", 44 | "qgrid_widget = qgrid.show_grid(df_types, show_toolbar=True)\n", 45 | "qgrid_widget" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": null, 51 | "metadata": {}, 52 | "outputs": [], 53 | "source": [ 54 | "%matplotlib nbagg\n", 55 | "import matplotlib.pyplot as plt\n", 56 | "\n", 57 | "n = 50\n", 58 | "\n", 59 | "qgrid_df = qgrid_widget.get_changed_df()\n", 60 | "x = qgrid_df.index\n", 61 | "y = qgrid_df['C']\n", 62 | "\n", 63 | "fig, ax = plt.subplots()\n", 64 | "fit = np.polyfit(x, y, deg=1)\n", 65 | "line, = ax.plot(x, fit[0] * x + fit[1], color='red')\n", 66 | "scatter, = ax.plot(x,y,ms=8,color='b',marker='o',ls='')\n", 67 | "\n", 68 | "def handle_filter_changed(event, widget):\n", 69 | " qgrid_df = qgrid_widget.get_changed_df()\n", 70 | " x = qgrid_df.index\n", 71 | " y = qgrid_df['C']\n", 72 | " fit = np.polyfit(x, y, deg=1)\n", 73 | " line.set_data(x, fit[0] * x + fit[1])\n", 74 | " fig.canvas.draw()\n", 75 | " scatter.set_data(x, y)\n", 76 | " fig.canvas.draw()\n", 77 | "\n", 78 | "qgrid_widget.on('filter_changed', handle_filter_changed)" 79 | ] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "execution_count": null, 84 | "metadata": {}, 85 | "outputs": [], 86 | "source": [ 87 | "qgrid_widget # render the qgrid widget again so we don't have to scroll to see the changes in the scatter plot" 88 | ] 89 | }, 90 | { 91 | "cell_type": "markdown", 92 | "metadata": {}, 93 | "source": [ 94 | "## Example 2 - Filter matplotlib price chart using qgrid\n", 95 | "This example is basically a repeat of Example 1, except with a line chart of some pricing data for the S&P 500 instead of a scatter plot.\n", 96 | "\n", 97 | "First, execute the following two cells. Once you do that you should see a qgrid instance and a matplotlib line chart showing the same data as the qgrid instance. Next, set some filters on the columns of the qgrid instance and watch what happens to the line chart (it should update immediately to reflect the filtering changes)." 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": null, 103 | "metadata": {}, 104 | "outputs": [], 105 | "source": [ 106 | "import pandas as pd\n", 107 | "import numpy as np\n", 108 | "import qgrid\n", 109 | "randn = np.random.randn\n", 110 | "\n", 111 | "# Get a pandas DataFrame containing the daily prices for the S&P 500 from 1/1/2014 - 1/1/2017\n", 112 | "from pandas_datareader.data import DataReader\n", 113 | "spy = DataReader(\n", 114 | " 'SPY',\n", 115 | " 'yahoo',\n", 116 | " pd.Timestamp('2014-01-01'), \n", 117 | " pd.Timestamp('2017-01-01'),\n", 118 | ")\n", 119 | "# Tell qgrid to automatically render all DataFrames and Series as qgrids.\n", 120 | "qgrid.enable()\n", 121 | "\n", 122 | "# Render the DataFrame as a qgrid automatically\n", 123 | "spy_qgrid = qgrid.show_grid(spy)\n", 124 | "spy_qgrid" 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "execution_count": null, 130 | "metadata": {}, 131 | "outputs": [], 132 | "source": [ 133 | "%matplotlib nbagg\n", 134 | "import matplotlib.pyplot as plt\n", 135 | "import datetime\n", 136 | "import matplotlib.pyplot as plt\n", 137 | "import matplotlib.dates as mdates\n", 138 | "import matplotlib.cbook as cbook\n", 139 | "from traitlets import All\n", 140 | "\n", 141 | "years = mdates.YearLocator() # every year\n", 142 | "months = mdates.MonthLocator() # every month\n", 143 | "yearsFmt = mdates.DateFormatter('%Y')\n", 144 | "\n", 145 | "n = 50\n", 146 | "qgrid_spy_df = spy_qgrid.get_changed_df()\n", 147 | "x = qgrid_spy_df.index\n", 148 | "y = qgrid_spy_df['Close']\n", 149 | "\n", 150 | "fig, ax = plt.subplots()\n", 151 | "line, = ax.plot(x, y)\n", 152 | "\n", 153 | "# format the ticks\n", 154 | "ax.xaxis.set_major_locator(years)\n", 155 | "ax.xaxis.set_major_formatter(yearsFmt)\n", 156 | "ax.xaxis.set_minor_locator(months)\n", 157 | "\n", 158 | "datemin = datetime.date(x.min().year, 1, 1)\n", 159 | "datemax = datetime.date(x.max().year + 1, 1, 1)\n", 160 | "ax.set_xlim(datemin, datemax)\n", 161 | "\n", 162 | "# format the coords message box\n", 163 | "def price(x):\n", 164 | " return '$%1.2f' % x\n", 165 | "ax.format_xdata = mdates.DateFormatter('%Y-%m-%d')\n", 166 | "ax.format_ydata = price\n", 167 | "ax.grid(True)\n", 168 | "\n", 169 | "# rotates and right aligns the x labels, and moves the bottom of the\n", 170 | "# axes up to make room for them\n", 171 | "fig.autofmt_xdate()\n", 172 | "\n", 173 | "def handle_filter_changed(event, widget):\n", 174 | " qgrid_spy_df = widget.get_changed_df()\n", 175 | " x = qgrid_spy_df.index\n", 176 | " y = qgrid_spy_df['Close']\n", 177 | " \n", 178 | " datemin = datetime.date(x.min().year, 1, 1)\n", 179 | " datemax = datetime.date(x.max().year + 1, 1, 1)\n", 180 | " ax.set_xlim(datemin, datemax)\n", 181 | " \n", 182 | " line.set_data(x, y)\n", 183 | " fig.canvas.draw()\n", 184 | "\n", 185 | "spy_qgrid.on('filter_changed', handle_filter_changed)" 186 | ] 187 | }, 188 | { 189 | "cell_type": "code", 190 | "execution_count": null, 191 | "metadata": {}, 192 | "outputs": [], 193 | "source": [ 194 | "spy_qgrid # render the qgrid widget again so we don't have to scroll to see the changes in the scatter plot" 195 | ] 196 | }, 197 | { 198 | "cell_type": "markdown", 199 | "metadata": {}, 200 | "source": [ 201 | "## Example 3 - Logging all events\n", 202 | "In this example we'll see how you can listen for events from any qgrid instance using the `qgrid.on` method.\n", 203 | "\n", 204 | "Execute the following two cells. The first cell will create an empty output widget, and the second cell use the `on` method to listen for all events from all qgrid instances. Once the cells are executed, try interacting with any of the qgrid instances you created earlier in the notebook (i.e. by sorting, filtering, scrolling, etc). Then scroll back down to this output widget and you'll notice that any actions that you took got printed to the output widget.\n", 205 | "\n", 206 | "In practice you'd probably want to do something more interesting than just print these events to the notebook, such as log the events to a service that you use to track user interactions. This is just a proof-of-concept to show which events are available." 207 | ] 208 | }, 209 | { 210 | "cell_type": "code", 211 | "execution_count": null, 212 | "metadata": {}, 213 | "outputs": [], 214 | "source": [ 215 | "import ipywidgets as widgets\n", 216 | "json_updates = widgets.Output(layout={'border': '1px solid black'})\n", 217 | "user_interactions = widgets.Output(layout={'border': '1px solid black'})\n", 218 | "\n", 219 | "widgets.VBox([user_interactions, json_updates])" 220 | ] 221 | }, 222 | { 223 | "cell_type": "code", 224 | "execution_count": null, 225 | "metadata": {}, 226 | "outputs": [], 227 | "source": [ 228 | "import qgrid\n", 229 | "from traitlets import All\n", 230 | "\n", 231 | "def handle_all_events(event, qgrid_widget):\n", 232 | " output_area = json_updates if event['name'] == 'json_updated' else user_interactions\n", 233 | " with output_area:\n", 234 | " print(event)\n", 235 | "\n", 236 | "qgrid.on(All, handle_all_events)" 237 | ] 238 | }, 239 | { 240 | "cell_type": "markdown", 241 | "metadata": {}, 242 | "source": [ 243 | "## Example 4 - Filter qgrid using ipywidgets slider (experimental)\n", 244 | "In the Example 1 and 2, qgrid was being used to control other visualizations. In this example, we're going to invert the direction of control and use another visualization (in this case an ipywidget slider) to control qgrid.\n", 245 | "\n", 246 | "Please note that the `_handle_qgrid_msg_helper` method used in this example is not a documented part of the API yet and should be considered experimental. It will likely be renamed and changed slightly once it gets officially added to the API.\n", 247 | "\n", 248 | "First, execute the following cell. Once you do that you should see a slider widget directly above a qgrid widget. The slider is hooked up to control the filter for the index column. Next, move the sliders on the slider widget and watch qgrid instance update immediately to reflect the filtering changes." 249 | ] 250 | }, 251 | { 252 | "cell_type": "code", 253 | "execution_count": null, 254 | "metadata": {}, 255 | "outputs": [], 256 | "source": [ 257 | "import numpy as np\n", 258 | "import pandas as pd\n", 259 | "import qgrid\n", 260 | "import ipywidgets as widgets\n", 261 | "df_scale = pd.DataFrame(np.random.randn(1000, 4), columns=list('ABCD'))\n", 262 | "q_scale = qgrid.show_grid(df_scale, show_toolbar=False)\n", 263 | "\n", 264 | "int_range = widgets.IntRangeSlider(\n", 265 | " value=[0, 999],\n", 266 | " min=0,\n", 267 | " max=999,\n", 268 | " step=1,\n", 269 | " description='Test:',\n", 270 | " disabled=False,\n", 271 | " continuous_update=True,\n", 272 | " orientation='horizontal',\n", 273 | " readout=True,\n", 274 | " readout_format='d',\n", 275 | ")\n", 276 | "\n", 277 | "def on_value_change(change):\n", 278 | " q_scale._handle_qgrid_msg_helper({\n", 279 | " 'field': \"index\",\n", 280 | " 'filter_info': {\n", 281 | " 'field': \"index\",\n", 282 | " 'max': change['new'][1],\n", 283 | " 'min': change['new'][0],\n", 284 | " 'type': \"slider\"\n", 285 | " },\n", 286 | " 'type': \"filter_changed\"\n", 287 | " })\n", 288 | "\n", 289 | "int_range.observe(on_value_change, names='value')\n", 290 | "\n", 291 | "widgets.VBox([int_range, q_scale])" 292 | ] 293 | } 294 | ], 295 | "metadata": { 296 | "kernelspec": { 297 | "display_name": "Python 3", 298 | "language": "python", 299 | "name": "python3" 300 | }, 301 | "language_info": { 302 | "codemirror_mode": { 303 | "name": "ipython", 304 | "version": 3 305 | }, 306 | "file_extension": ".py", 307 | "mimetype": "text/x-python", 308 | "name": "python", 309 | "nbconvert_exporter": "python", 310 | "pygments_lexer": "ipython3", 311 | "version": "3.6.5" 312 | }, 313 | "widgets": { 314 | "application/vnd.jupyter.widget-state+json": { 315 | "state": { 316 | "1a834c4c69af4c48bed691594ce5e0ad": { 317 | "model_module": "@jupyter-widgets/base", 318 | "model_module_version": "1.0.0", 319 | "model_name": "LayoutModel", 320 | "state": {} 321 | }, 322 | "3fb8c261d3e249248ea7703065634285": { 323 | "model_module": "@jupyter-widgets/base", 324 | "model_module_version": "1.0.0", 325 | "model_name": "LayoutModel", 326 | "state": {} 327 | }, 328 | "7aa5e1ce49fc4d0f9366bea5c684c58d": { 329 | "model_module": "qgrid", 330 | "model_module_version": "1.0.0-alpha.6", 331 | "model_name": "QgridModel", 332 | "state": { 333 | "_columns": { 334 | "A": { 335 | "name": "A", 336 | "type": "number" 337 | }, 338 | "B": { 339 | "name": "B", 340 | "type": "datetime" 341 | }, 342 | "C": { 343 | "name": "C", 344 | "type": "number" 345 | }, 346 | "D": { 347 | "name": "D", 348 | "type": "integer" 349 | }, 350 | "E": { 351 | "constraints": { 352 | "enum": [ 353 | "adams", 354 | "hamilton", 355 | "jefferson", 356 | "kennedy", 357 | "lincoln", 358 | "madison", 359 | "roosevelt", 360 | "washington" 361 | ] 362 | }, 363 | "name": "E", 364 | "ordered": false, 365 | "type": "any" 366 | }, 367 | "F": { 368 | "name": "F", 369 | "type": "string" 370 | }, 371 | "G": { 372 | "name": "G", 373 | "type": "boolean" 374 | }, 375 | "index": { 376 | "name": "index", 377 | "type": "integer" 378 | } 379 | }, 380 | "_df_json": "{\"schema\": {\"fields\":[{\"name\":\"index\",\"type\":\"integer\"},{\"name\":\"A\",\"type\":\"number\"},{\"name\":\"B\",\"type\":\"datetime\"},{\"name\":\"C\",\"type\":\"number\"},{\"name\":\"D\",\"type\":\"integer\"},{\"name\":\"E\",\"type\":\"any\",\"constraints\":{\"enum\":[\"adams\",\"hamilton\",\"jefferson\",\"kennedy\",\"lincoln\",\"madison\",\"roosevelt\",\"washington\"]},\"ordered\":false},{\"name\":\"F\",\"type\":\"string\"},{\"name\":\"G\",\"type\":\"boolean\"}],\"primaryKey\":[\"index\"],\"pandas_version\":\"0.20.0\"}, \"data\": [{\"index\":0,\"A\":1.0,\"B\":\"2013-01-01T00:00:00.000Z\",\"C\":-0.09128,\"D\":3,\"E\":\"washington\",\"F\":\"foo\",\"G\":true},{\"index\":1,\"A\":1.0,\"B\":\"2013-01-02T00:00:00.000Z\",\"C\":-0.57373,\"D\":3,\"E\":\"adams\",\"F\":\"bar\",\"G\":false},{\"index\":2,\"A\":1.0,\"B\":\"2013-01-03T00:00:00.000Z\",\"C\":0.4723,\"D\":3,\"E\":\"washington\",\"F\":\"buzz\",\"G\":false},{\"index\":3,\"A\":1.0,\"B\":\"2013-01-04T00:00:00.000Z\",\"C\":-0.09316,\"D\":3,\"E\":\"madison\",\"F\":\"bippity\",\"G\":false},{\"index\":4,\"A\":1.0,\"B\":\"2013-01-05T00:00:00.000Z\",\"C\":-0.20181,\"D\":3,\"E\":\"lincoln\",\"F\":\"boppity\",\"G\":false},{\"index\":5,\"A\":1.0,\"B\":\"2013-01-06T00:00:00.000Z\",\"C\":1.7561,\"D\":3,\"E\":\"jefferson\",\"F\":\"foo\",\"G\":true},{\"index\":6,\"A\":1.0,\"B\":\"2013-01-07T00:00:00.000Z\",\"C\":1.20064,\"D\":3,\"E\":\"hamilton\",\"F\":\"foo\",\"G\":true},{\"index\":7,\"A\":1.0,\"B\":\"2013-01-08T00:00:00.000Z\",\"C\":0.98097,\"D\":3,\"E\":\"roosevelt\",\"F\":\"bar\",\"G\":false},{\"index\":8,\"A\":1.0,\"B\":\"2013-01-09T00:00:00.000Z\",\"C\":0.8321,\"D\":3,\"E\":\"kennedy\",\"F\":\"zoo\",\"G\":false}]}", 381 | "_df_range": [ 382 | 0, 383 | 100 384 | ], 385 | "_interval_columns": [], 386 | "_model_module_version": "1.0.0-alpha.6", 387 | "_row_count": 9, 388 | "_sort_ascending": true, 389 | "_sort_field": "", 390 | "_view_module_version": "1.0.0-alpha.6", 391 | "grid_options": { 392 | "autoEdit": false, 393 | "defaultColumnWidth": 150, 394 | "editable": true, 395 | "enableColumnReorder": false, 396 | "enableTextSelectionOnCells": true, 397 | "explicitInitialization": true, 398 | "forceFitColumns": true, 399 | "fullWidthRows": true, 400 | "rowHeight": 28, 401 | "syncColumnCellResize": true 402 | }, 403 | "layout": "IPY_MODEL_1a834c4c69af4c48bed691594ce5e0ad", 404 | "precision": 5, 405 | "show_toolbar": false 406 | } 407 | }, 408 | "7ec042abef044645a9f8bd38a3f69faf": { 409 | "model_module": "qgrid", 410 | "model_module_version": "1.0.0-alpha.6", 411 | "model_name": "QgridModel", 412 | "state": { 413 | "_columns": { 414 | "A": { 415 | "name": "A", 416 | "type": "number" 417 | }, 418 | "B": { 419 | "name": "B", 420 | "type": "datetime" 421 | }, 422 | "C": { 423 | "name": "C", 424 | "type": "number" 425 | }, 426 | "D": { 427 | "name": "D", 428 | "type": "integer" 429 | }, 430 | "E": { 431 | "constraints": { 432 | "enum": [ 433 | "adams", 434 | "hamilton", 435 | "jefferson", 436 | "kennedy", 437 | "lincoln", 438 | "madison", 439 | "roosevelt", 440 | "washington" 441 | ] 442 | }, 443 | "name": "E", 444 | "ordered": false, 445 | "type": "any" 446 | }, 447 | "F": { 448 | "name": "F", 449 | "type": "string" 450 | }, 451 | "G": { 452 | "name": "G", 453 | "type": "boolean" 454 | }, 455 | "index": { 456 | "name": "index", 457 | "type": "integer" 458 | } 459 | }, 460 | "_df_json": "{\"schema\": {\"fields\":[{\"name\":\"index\",\"type\":\"integer\"},{\"name\":\"A\",\"type\":\"number\"},{\"name\":\"B\",\"type\":\"datetime\"},{\"name\":\"C\",\"type\":\"number\"},{\"name\":\"D\",\"type\":\"integer\"},{\"name\":\"E\",\"type\":\"any\",\"constraints\":{\"enum\":[\"adams\",\"hamilton\",\"jefferson\",\"kennedy\",\"lincoln\",\"madison\",\"roosevelt\",\"washington\"]},\"ordered\":false},{\"name\":\"F\",\"type\":\"string\"},{\"name\":\"G\",\"type\":\"boolean\"}],\"primaryKey\":[\"index\"],\"pandas_version\":\"0.20.0\"}, \"data\": [{\"index\":0,\"A\":1.0,\"B\":\"2013-01-01T00:00:00.000Z\",\"C\":0.13177,\"D\":3,\"E\":\"washington\",\"F\":\"foo\",\"G\":true},{\"index\":1,\"A\":1.0,\"B\":\"2013-01-02T00:00:00.000Z\",\"C\":-1.56846,\"D\":3,\"E\":\"adams\",\"F\":\"bar\",\"G\":false},{\"index\":2,\"A\":1.0,\"B\":\"2013-01-03T00:00:00.000Z\",\"C\":1.2584,\"D\":3,\"E\":\"washington\",\"F\":\"buzz\",\"G\":false},{\"index\":3,\"A\":1.0,\"B\":\"2013-01-04T00:00:00.000Z\",\"C\":-1.54316,\"D\":3,\"E\":\"madison\",\"F\":\"bippity\",\"G\":false},{\"index\":4,\"A\":1.0,\"B\":\"2013-01-05T00:00:00.000Z\",\"C\":0.01483,\"D\":3,\"E\":\"lincoln\",\"F\":\"boppity\",\"G\":false},{\"index\":5,\"A\":1.0,\"B\":\"2013-01-06T00:00:00.000Z\",\"C\":-0.26442,\"D\":3,\"E\":\"jefferson\",\"F\":\"foo\",\"G\":true},{\"index\":6,\"A\":1.0,\"B\":\"2013-01-07T00:00:00.000Z\",\"C\":-1.85692,\"D\":3,\"E\":\"hamilton\",\"F\":\"foo\",\"G\":true},{\"index\":7,\"A\":1.0,\"B\":\"2013-01-08T00:00:00.000Z\",\"C\":1.38498,\"D\":3,\"E\":\"roosevelt\",\"F\":\"bar\",\"G\":false},{\"index\":8,\"A\":1.0,\"B\":\"2013-01-09T00:00:00.000Z\",\"C\":0.40905,\"D\":3,\"E\":\"kennedy\",\"F\":\"zoo\",\"G\":false}]}", 461 | "_df_range": [ 462 | 0, 463 | 100 464 | ], 465 | "_interval_columns": [], 466 | "_model_module_version": "1.0.0-alpha.6", 467 | "_row_count": 9, 468 | "_sort_ascending": true, 469 | "_sort_field": "", 470 | "_view_module_version": "1.0.0-alpha.6", 471 | "grid_options": { 472 | "autoEdit": false, 473 | "defaultColumnWidth": 150, 474 | "editable": true, 475 | "enableColumnReorder": false, 476 | "enableTextSelectionOnCells": true, 477 | "explicitInitialization": true, 478 | "forceFitColumns": true, 479 | "fullWidthRows": true, 480 | "rowHeight": 28, 481 | "syncColumnCellResize": true 482 | }, 483 | "layout": "IPY_MODEL_8eb3cf5ce7da431db4a3e4e9d3d64511", 484 | "precision": 5, 485 | "show_toolbar": false 486 | } 487 | }, 488 | "8eb3cf5ce7da431db4a3e4e9d3d64511": { 489 | "model_module": "@jupyter-widgets/base", 490 | "model_module_version": "1.0.0", 491 | "model_name": "LayoutModel", 492 | "state": {} 493 | }, 494 | "fa118ab9f1c840cd83509f56d50ee163": { 495 | "model_module": "qgrid", 496 | "model_module_version": "1.0.0-alpha.6", 497 | "model_name": "QgridModel", 498 | "state": { 499 | "_columns": { 500 | "A": { 501 | "name": "A", 502 | "type": "number" 503 | }, 504 | "B": { 505 | "name": "B", 506 | "type": "datetime" 507 | }, 508 | "C": { 509 | "name": "C", 510 | "type": "number" 511 | }, 512 | "D": { 513 | "name": "D", 514 | "type": "integer" 515 | }, 516 | "E": { 517 | "constraints": { 518 | "enum": [ 519 | "adams", 520 | "hamilton", 521 | "jefferson", 522 | "kennedy", 523 | "lincoln", 524 | "madison", 525 | "roosevelt", 526 | "washington" 527 | ] 528 | }, 529 | "name": "E", 530 | "ordered": false, 531 | "type": "any" 532 | }, 533 | "F": { 534 | "name": "F", 535 | "type": "string" 536 | }, 537 | "G": { 538 | "name": "G", 539 | "type": "boolean" 540 | }, 541 | "index": { 542 | "name": "index", 543 | "type": "integer" 544 | } 545 | }, 546 | "_df_json": "{\"schema\": {\"fields\":[{\"name\":\"index\",\"type\":\"integer\"},{\"name\":\"A\",\"type\":\"number\"},{\"name\":\"B\",\"type\":\"datetime\"},{\"name\":\"C\",\"type\":\"number\"},{\"name\":\"D\",\"type\":\"integer\"},{\"name\":\"E\",\"type\":\"any\",\"constraints\":{\"enum\":[\"adams\",\"hamilton\",\"jefferson\",\"kennedy\",\"lincoln\",\"madison\",\"roosevelt\",\"washington\"]},\"ordered\":false},{\"name\":\"F\",\"type\":\"string\"},{\"name\":\"G\",\"type\":\"boolean\"}],\"primaryKey\":[\"index\"],\"pandas_version\":\"0.20.0\"}, \"data\": [{\"index\":0,\"A\":1.0,\"B\":\"2013-01-01T00:00:00.000Z\",\"C\":-0.67408,\"D\":3,\"E\":\"washington\",\"F\":\"foo\",\"G\":true},{\"index\":1,\"A\":1.0,\"B\":\"2013-01-02T00:00:00.000Z\",\"C\":-0.87122,\"D\":3,\"E\":\"adams\",\"F\":\"bar\",\"G\":false},{\"index\":2,\"A\":1.0,\"B\":\"2013-01-03T00:00:00.000Z\",\"C\":0.58722,\"D\":3,\"E\":\"washington\",\"F\":\"buzz\",\"G\":false},{\"index\":3,\"A\":1.0,\"B\":\"2013-01-04T00:00:00.000Z\",\"C\":0.14947,\"D\":3,\"E\":\"madison\",\"F\":\"bippity\",\"G\":false},{\"index\":4,\"A\":1.0,\"B\":\"2013-01-05T00:00:00.000Z\",\"C\":0.89719,\"D\":3,\"E\":\"lincoln\",\"F\":\"boppity\",\"G\":false},{\"index\":5,\"A\":1.0,\"B\":\"2013-01-06T00:00:00.000Z\",\"C\":0.41141,\"D\":3,\"E\":\"jefferson\",\"F\":\"foo\",\"G\":true},{\"index\":6,\"A\":1.0,\"B\":\"2013-01-07T00:00:00.000Z\",\"C\":0.66837,\"D\":3,\"E\":\"hamilton\",\"F\":\"foo\",\"G\":true},{\"index\":7,\"A\":1.0,\"B\":\"2013-01-08T00:00:00.000Z\",\"C\":0.42815,\"D\":3,\"E\":\"roosevelt\",\"F\":\"bar\",\"G\":false},{\"index\":8,\"A\":1.0,\"B\":\"2013-01-09T00:00:00.000Z\",\"C\":-0.49399,\"D\":3,\"E\":\"kennedy\",\"F\":\"zoo\",\"G\":false}]}", 547 | "_df_range": [ 548 | 0, 549 | 100 550 | ], 551 | "_interval_columns": [], 552 | "_model_module_version": "1.0.0-alpha.6", 553 | "_row_count": 9, 554 | "_sort_ascending": true, 555 | "_sort_field": "", 556 | "_view_module_version": "1.0.0-alpha.6", 557 | "grid_options": { 558 | "autoEdit": false, 559 | "defaultColumnWidth": 150, 560 | "editable": true, 561 | "enableColumnReorder": false, 562 | "enableTextSelectionOnCells": true, 563 | "explicitInitialization": true, 564 | "forceFitColumns": true, 565 | "fullWidthRows": true, 566 | "rowHeight": 28, 567 | "syncColumnCellResize": true 568 | }, 569 | "layout": "IPY_MODEL_3fb8c261d3e249248ea7703065634285", 570 | "precision": 5, 571 | "show_toolbar": false 572 | } 573 | } 574 | }, 575 | "version_major": 2, 576 | "version_minor": 0 577 | } 578 | } 579 | }, 580 | "nbformat": 4, 581 | "nbformat_minor": 2 582 | } 583 | -------------------------------------------------------------------------------- /index.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "qgrid - An interactive grid for viewing and editing pandas DataFrames\n", 8 | "=======================================================\n", 9 | "Qgrid is an Jupyter notebook widget which uses a javascript library called SlickGrid to render pandas DataFrames within a Jupyter notebook. It was developed for use in [Quantopian's hosted research environment]( https://www.quantopian.com/research?utm_source=github&utm_medium=web&utm_campaign=qgrid-nbviewer).\n", 10 | "\n", 11 | "The purpose of this notebook is to give an overview of what qgrid is capable of. Execute the cells below to generate some qgrids using a diverse set of DataFrames." 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "metadata": {}, 17 | "source": [ 18 | "## Overview\n", 19 | "* [SlickGrid](https://github.com/mleibman/SlickGrid) is a javascript grid which allows users to scroll, sort, \n", 20 | "and filter hundreds of thousands of rows with extreme responsiveness. \n", 21 | "* [Pandas](https://github.com/pydata/pandas) is a powerful data analysis / manipulation library for Python, and DataFrames are the primary way of storing and manipulating two-dimensional data in pandas.\n", 22 | "\n", 23 | "[Qgrid](https://github.com/quantopian/qgrid) renders pandas DataFrames as SlickGrids, which enables users to explore the entire contents of a DataFrame using intuitive sorting and filtering controls. It's built on the ipywidget framework and is designed to be used in Jupyter notebook, Jupyterhub, or Jupyterlab" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "## What's new\n", 31 | "\n", 32 | "#### Column options and new \"live-updating\" API methods - as of 1.1.0\n", 33 | "* Column options can be provided via the `show_grid` method. Options can be provided for all columns via the `column_options` parameter, and for individual columns via the `column_definitions` parameter.\n", 34 | "* Added `edit_cell`, `change_selection`, `toggle_editable` methods for updating the state of an existing grid widget without having to call `show_grid`.\n", 35 | "* Updated the `add_row` method so that the caller can specify the values for the new row via the `row` parameter. This will allow people to add rows to a qgrid instance even if it's showing a DataFrame that doesn't have an integer index.\n", 36 | "* Updated the `remove_row` method so that the indices of the rows to remove can optionally be provided via the `rows` parameter.\n", 37 | "* Fixed issue where moving the scroll bar around a bunch of times quickly can cause a series of grid refreshes to occur.\n", 38 | "\n", 39 | "#### Multi-index support - as of 1.0.6-beta.6\n", 40 | "* Improves support for viewing DataFrames with a MultiIndex.\n", 41 | "* Cells are merged vertically (similar to how pandas does it) to make it easier to identify the levels of the index.\n", 42 | "* Sorting or grouping any column other than level 0 of the multi-index results in the DataFrame returning to it's normal behavior of never merging cells vertically.\n", 43 | "* Column header is hidden for unnamed levels of the index (instead of showing \"level_0\", \"level_1\", etc)\n", 44 | "\n", 45 | "#### Events API - as of 1.0.3:\n", 46 | "* Added the ability to listen for events on all QgridWidget instances (using `qgrid.on`) as well as on individual instances (using `QgridWidget.on`).\n", 47 | "* **Breaking API Change:** Previously the recommended (but not officially documented) way of attaching event handlers to a QgridWidget instance was to listen for changes to the ``_df`` attribute using the ``observe`` method (i.e.``qgrid_widget.observe(handle_df_changed, names=['_df'])``). This method will no longer work for most events (scrolling, sorting, filtering, etc) so the new ``QgridWidget.on`` method should be used instead." 48 | ] 49 | }, 50 | { 51 | "cell_type": "markdown", 52 | "metadata": {}, 53 | "source": [ 54 | "## API & Usage\n", 55 | "API documentation is hosted on [readthedocs](http://qgrid.readthedocs.io/en/widget-guidelines/). \n", 56 | "\n", 57 | "The API documentation can also be accessed via the \"?\" operator in IPython. To use the \"?\" operator, type the name of the function followed by \"?\" to see the documentation for that function, like this:\n", 58 | "```\n", 59 | "qgrid.show_grid?\n", 60 | "qgrid.set_defaults?\n", 61 | "qgrid.set_grid_options?\n", 62 | "qgrid.enable?\n", 63 | "qgrid.disable?\n", 64 | "\n", 65 | "```" 66 | ] 67 | }, 68 | { 69 | "cell_type": "markdown", 70 | "metadata": {}, 71 | "source": [ 72 | "## Example 1 - Render a DataFrame with many different types of columns" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": null, 78 | "metadata": {}, 79 | "outputs": [], 80 | "source": [ 81 | "import numpy as np\n", 82 | "import pandas as pd\n", 83 | "import qgrid\n", 84 | "randn = np.random.randn\n", 85 | "df_types = pd.DataFrame({\n", 86 | " 'A' : pd.Series(['2013-01-01', '2013-01-02', '2013-01-03', '2013-01-04',\n", 87 | " '2013-01-05', '2013-01-06', '2013-01-07', '2013-01-08', '2013-01-09'],index=list(range(9)),dtype='datetime64[ns]'),\n", 88 | " 'B' : pd.Series(randn(9),index=list(range(9)),dtype='float32'),\n", 89 | " 'C' : pd.Categorical([\"washington\", \"adams\", \"washington\", \"madison\", \"lincoln\",\"jefferson\", \"hamilton\", \"roosevelt\", \"kennedy\"]),\n", 90 | " 'D' : [\"foo\", \"bar\", \"buzz\", \"bippity\",\"boppity\", \"foo\", \"foo\", \"bar\", \"zoo\"] })\n", 91 | "df_types['E'] = df_types['D'] == 'foo'\n", 92 | "qgrid_widget = qgrid.show_grid(df_types, show_toolbar=True)\n", 93 | "qgrid_widget" 94 | ] 95 | }, 96 | { 97 | "cell_type": "markdown", 98 | "metadata": {}, 99 | "source": [ 100 | "If you make any sorting/filtering changes, or edit the grid by double clicking, you can retrieve a copy of your DataFrame which reflects these changes by calling `get_changed_df` on the `QgridWidget` instance returned by `show_grid`." 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": null, 106 | "metadata": { 107 | "scrolled": true 108 | }, 109 | "outputs": [], 110 | "source": [ 111 | "qgrid_widget.get_changed_df()" 112 | ] 113 | }, 114 | { 115 | "cell_type": "markdown", 116 | "metadata": {}, 117 | "source": [ 118 | "## Example 2 - Render a DataFrame with 1 million rows\n", 119 | "*Note: The reason for the redundant \"import\" statements in the next cell (and many subsequent cells) is because it allows us to run the cells in any order.*" 120 | ] 121 | }, 122 | { 123 | "cell_type": "code", 124 | "execution_count": null, 125 | "metadata": {}, 126 | "outputs": [], 127 | "source": [ 128 | "import pandas as pd\n", 129 | "import numpy as np\n", 130 | "import qgrid\n", 131 | "\n", 132 | "# set the default max number of rows to 10 so the larger DataFrame we render don't take up to much space \n", 133 | "qgrid.set_grid_option('maxVisibleRows', 10)\n", 134 | "\n", 135 | "df_scale = pd.DataFrame(np.random.randn(1000000, 4), columns=list('ABCD'))\n", 136 | "# duplicate column B as a string column, to test scalability for text column filters\n", 137 | "df_scale['B (as str)'] = df_scale['B'].map(lambda x: str(x))\n", 138 | "q_scale = qgrid.show_grid(df_scale, show_toolbar=True, grid_options={'forceFitColumns': False, 'defaultColumnWidth': 200})\n", 139 | "q_scale" 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": null, 145 | "metadata": { 146 | "scrolled": true 147 | }, 148 | "outputs": [], 149 | "source": [ 150 | "q_scale.get_changed_df()" 151 | ] 152 | }, 153 | { 154 | "cell_type": "markdown", 155 | "metadata": {}, 156 | "source": [ 157 | "## Example 3 - Render a DataFrame returned by Yahoo Finance by enabling automatic qgrids" 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": null, 163 | "metadata": {}, 164 | "outputs": [], 165 | "source": [ 166 | "import pandas as pd\n", 167 | "import numpy as np\n", 168 | "import qgrid\n", 169 | "randn = np.random.randn\n", 170 | "\n", 171 | "# Get a pandas DataFrame containing the daily prices for the S&P 500 from 1/1/2014 - 1/1/2017\n", 172 | "from pandas_datareader.data import DataReader\n", 173 | "spy = DataReader(\n", 174 | " 'SPY',\n", 175 | " 'yahoo',\n", 176 | " pd.Timestamp('2014-01-01'), \n", 177 | " pd.Timestamp('2017-01-01'),\n", 178 | ")\n", 179 | "# Tell qgrid to automatically render all DataFrames and Series as qgrids.\n", 180 | "qgrid.enable()\n", 181 | "\n", 182 | "# Render the DataFrame as a qgrid automatically\n", 183 | "spy" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": null, 189 | "metadata": {}, 190 | "outputs": [], 191 | "source": [ 192 | "# Disable automatic display so we can display DataFrames in the normal way\n", 193 | "qgrid.disable()" 194 | ] 195 | }, 196 | { 197 | "cell_type": "markdown", 198 | "metadata": {}, 199 | "source": [ 200 | "## Example 4 - Render a DataFrame with a multi-index\n", 201 | "\n", 202 | "Create a sample DataFrame using the `wb.download` function and render it without using qgrid" 203 | ] 204 | }, 205 | { 206 | "cell_type": "code", 207 | "execution_count": null, 208 | "metadata": {}, 209 | "outputs": [], 210 | "source": [ 211 | "import qgrid\n", 212 | "import pandas as pd\n", 213 | "from pandas_datareader import wb\n", 214 | "df_countries = wb.download(indicator='NY.GDP.PCAP.KD', country=['all'], start=2005, end=2008)\n", 215 | "df_countries.columns = ['GDP per capita (constant 2005 US$)']\n", 216 | "qgrid.show_grid(df_countries)" 217 | ] 218 | }, 219 | { 220 | "cell_type": "code", 221 | "execution_count": null, 222 | "metadata": { 223 | "scrolled": true 224 | }, 225 | "outputs": [], 226 | "source": [ 227 | "df_countries" 228 | ] 229 | }, 230 | { 231 | "cell_type": "markdown", 232 | "metadata": {}, 233 | "source": [ 234 | "## Example 5 - Render a DataFrame with an interval column\n", 235 | "Create a sample DataFrame using the `wb.download` function and render it without using qgrid" 236 | ] 237 | }, 238 | { 239 | "cell_type": "code", 240 | "execution_count": null, 241 | "metadata": {}, 242 | "outputs": [], 243 | "source": [ 244 | "import numpy as np\n", 245 | "import pandas as pd\n", 246 | "import qgrid\n", 247 | "\n", 248 | "td = np.cumsum(np.random.randint(1, 15*60, 1000))\n", 249 | "start = pd.Timestamp('2017-04-17')\n", 250 | "df_interval = pd.DataFrame(\n", 251 | " [(start + pd.Timedelta(seconds=d)) for d in td],\n", 252 | " columns=['time'])\n", 253 | "\n", 254 | "freq = '15Min'\n", 255 | "start = df_interval['time'].min().floor(freq)\n", 256 | "end = df_interval['time'].max().ceil(freq)\n", 257 | "bins = pd.date_range(start, end, freq=freq)\n", 258 | "\n", 259 | "df_interval['time_bin'] = pd.cut(df_interval['time'], bins)\n", 260 | "\n", 261 | "qgrid.show_grid(df_interval, show_toolbar=True)" 262 | ] 263 | }, 264 | { 265 | "cell_type": "code", 266 | "execution_count": null, 267 | "metadata": { 268 | "scrolled": true 269 | }, 270 | "outputs": [], 271 | "source": [ 272 | "df_interval" 273 | ] 274 | }, 275 | { 276 | "cell_type": "markdown", 277 | "metadata": {}, 278 | "source": [ 279 | "## Example 6 - Render a DataFrame with unnamed columns\n", 280 | "Create a sample DataFrame using the `wb.download` function and render it without using qgrid" 281 | ] 282 | }, 283 | { 284 | "cell_type": "code", 285 | "execution_count": null, 286 | "metadata": {}, 287 | "outputs": [], 288 | "source": [ 289 | "import numpy as np\n", 290 | "import pandas as pd\n", 291 | "import qgrid\n", 292 | "\n", 293 | "arrays = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'],\n", 294 | " ['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]\n", 295 | "df_multi = pd.DataFrame(np.random.randn(8, 4), index=arrays)\n", 296 | "qgrid.show_grid(df_multi, show_toolbar=True)" 297 | ] 298 | }, 299 | { 300 | "cell_type": "code", 301 | "execution_count": null, 302 | "metadata": {}, 303 | "outputs": [], 304 | "source": [ 305 | "df_multi" 306 | ] 307 | }, 308 | { 309 | "cell_type": "markdown", 310 | "metadata": {}, 311 | "source": [ 312 | "## Example 7 - Render a narrow DataFrame inside a Layout widget\n", 313 | "Create a sample DataFrame with only two columns using `randint`, and render it in a Layout widget that's 20% of the width of the output area." 314 | ] 315 | }, 316 | { 317 | "cell_type": "code", 318 | "execution_count": null, 319 | "metadata": {}, 320 | "outputs": [], 321 | "source": [ 322 | "import numpy as np\n", 323 | "import pandas as pd\n", 324 | "import qgrid\n", 325 | "import ipywidgets as ipyw\n", 326 | "randn = np.random.randn\n", 327 | "df_types = pd.DataFrame(np.random.randint(1,14,14))\n", 328 | "qgrid_widget = qgrid.show_grid(df_types, show_toolbar=False)\n", 329 | "qgrid_widget.layout = ipyw.Layout(width='20%')\n", 330 | "qgrid_widget" 331 | ] 332 | }, 333 | { 334 | "cell_type": "markdown", 335 | "metadata": {}, 336 | "source": [ 337 | "## Example 8 - Render a DataFrame with an index and column that contain multiple types" 338 | ] 339 | }, 340 | { 341 | "cell_type": "code", 342 | "execution_count": null, 343 | "metadata": {}, 344 | "outputs": [], 345 | "source": [ 346 | "import pandas as pd\n", 347 | "import qgrid\n", 348 | "df = pd.DataFrame({'A': [1.2, 'xy', 4], 'B': [3, 4, 5]})\n", 349 | "df = df.set_index(pd.Index(['yz', 7, 3.2]))\n", 350 | "view = qgrid.show_grid(df)\n", 351 | "view" 352 | ] 353 | }, 354 | { 355 | "cell_type": "markdown", 356 | "metadata": {}, 357 | "source": [ 358 | "## Example 9 - Render a DataFrame with a Period index and Period column" 359 | ] 360 | }, 361 | { 362 | "cell_type": "code", 363 | "execution_count": null, 364 | "metadata": {}, 365 | "outputs": [], 366 | "source": [ 367 | "import pandas as pd\n", 368 | "import qgrid\n", 369 | "range_index = pd.period_range(start='2000', periods=10, freq='B')\n", 370 | "df = pd.DataFrame({'a': 5, 'b': range_index}, index=range_index)\n", 371 | "view = qgrid.show_grid(df)\n", 372 | "view" 373 | ] 374 | }, 375 | { 376 | "cell_type": "markdown", 377 | "metadata": {}, 378 | "source": [ 379 | "## Example 10 - Render a DataFrame with NaN and None" 380 | ] 381 | }, 382 | { 383 | "cell_type": "code", 384 | "execution_count": null, 385 | "metadata": {}, 386 | "outputs": [], 387 | "source": [ 388 | "import pandas as pd\n", 389 | "import numpy as np\n", 390 | "import qgrid\n", 391 | "df = pd.DataFrame([(pd.Timestamp('2017-02-02'), None, 3.4), (np.nan, 2, 4.7), (pd.Timestamp('2017-02-03'), 3, None)])\n", 392 | "qgrid.show_grid(df)" 393 | ] 394 | }, 395 | { 396 | "cell_type": "code", 397 | "execution_count": null, 398 | "metadata": {}, 399 | "outputs": [], 400 | "source": [] 401 | } 402 | ], 403 | "metadata": { 404 | "kernelspec": { 405 | "display_name": "Python 3", 406 | "language": "python", 407 | "name": "python3" 408 | }, 409 | "language_info": { 410 | "codemirror_mode": { 411 | "name": "ipython", 412 | "version": 3 413 | }, 414 | "file_extension": ".py", 415 | "mimetype": "text/x-python", 416 | "name": "python", 417 | "nbconvert_exporter": "python", 418 | "pygments_lexer": "ipython3", 419 | "version": "3.6.5" 420 | }, 421 | "widgets": { 422 | "application/vnd.jupyter.widget-state+json": { 423 | "state": { 424 | "1a834c4c69af4c48bed691594ce5e0ad": { 425 | "model_module": "@jupyter-widgets/base", 426 | "model_module_version": "1.0.0", 427 | "model_name": "LayoutModel", 428 | "state": {} 429 | }, 430 | "3fb8c261d3e249248ea7703065634285": { 431 | "model_module": "@jupyter-widgets/base", 432 | "model_module_version": "1.0.0", 433 | "model_name": "LayoutModel", 434 | "state": {} 435 | }, 436 | "7aa5e1ce49fc4d0f9366bea5c684c58d": { 437 | "model_module": "qgrid", 438 | "model_module_version": "1.0.0-alpha.6", 439 | "model_name": "QgridModel", 440 | "state": { 441 | "_columns": { 442 | "A": { 443 | "name": "A", 444 | "type": "number" 445 | }, 446 | "B": { 447 | "name": "B", 448 | "type": "datetime" 449 | }, 450 | "C": { 451 | "name": "C", 452 | "type": "number" 453 | }, 454 | "D": { 455 | "name": "D", 456 | "type": "integer" 457 | }, 458 | "E": { 459 | "constraints": { 460 | "enum": [ 461 | "adams", 462 | "hamilton", 463 | "jefferson", 464 | "kennedy", 465 | "lincoln", 466 | "madison", 467 | "roosevelt", 468 | "washington" 469 | ] 470 | }, 471 | "name": "E", 472 | "ordered": false, 473 | "type": "any" 474 | }, 475 | "F": { 476 | "name": "F", 477 | "type": "string" 478 | }, 479 | "G": { 480 | "name": "G", 481 | "type": "boolean" 482 | }, 483 | "index": { 484 | "name": "index", 485 | "type": "integer" 486 | } 487 | }, 488 | "_df_json": "{\"schema\": {\"fields\":[{\"name\":\"index\",\"type\":\"integer\"},{\"name\":\"A\",\"type\":\"number\"},{\"name\":\"B\",\"type\":\"datetime\"},{\"name\":\"C\",\"type\":\"number\"},{\"name\":\"D\",\"type\":\"integer\"},{\"name\":\"E\",\"type\":\"any\",\"constraints\":{\"enum\":[\"adams\",\"hamilton\",\"jefferson\",\"kennedy\",\"lincoln\",\"madison\",\"roosevelt\",\"washington\"]},\"ordered\":false},{\"name\":\"F\",\"type\":\"string\"},{\"name\":\"G\",\"type\":\"boolean\"}],\"primaryKey\":[\"index\"],\"pandas_version\":\"0.20.0\"}, \"data\": [{\"index\":0,\"A\":1.0,\"B\":\"2013-01-01T00:00:00.000Z\",\"C\":-0.09128,\"D\":3,\"E\":\"washington\",\"F\":\"foo\",\"G\":true},{\"index\":1,\"A\":1.0,\"B\":\"2013-01-02T00:00:00.000Z\",\"C\":-0.57373,\"D\":3,\"E\":\"adams\",\"F\":\"bar\",\"G\":false},{\"index\":2,\"A\":1.0,\"B\":\"2013-01-03T00:00:00.000Z\",\"C\":0.4723,\"D\":3,\"E\":\"washington\",\"F\":\"buzz\",\"G\":false},{\"index\":3,\"A\":1.0,\"B\":\"2013-01-04T00:00:00.000Z\",\"C\":-0.09316,\"D\":3,\"E\":\"madison\",\"F\":\"bippity\",\"G\":false},{\"index\":4,\"A\":1.0,\"B\":\"2013-01-05T00:00:00.000Z\",\"C\":-0.20181,\"D\":3,\"E\":\"lincoln\",\"F\":\"boppity\",\"G\":false},{\"index\":5,\"A\":1.0,\"B\":\"2013-01-06T00:00:00.000Z\",\"C\":1.7561,\"D\":3,\"E\":\"jefferson\",\"F\":\"foo\",\"G\":true},{\"index\":6,\"A\":1.0,\"B\":\"2013-01-07T00:00:00.000Z\",\"C\":1.20064,\"D\":3,\"E\":\"hamilton\",\"F\":\"foo\",\"G\":true},{\"index\":7,\"A\":1.0,\"B\":\"2013-01-08T00:00:00.000Z\",\"C\":0.98097,\"D\":3,\"E\":\"roosevelt\",\"F\":\"bar\",\"G\":false},{\"index\":8,\"A\":1.0,\"B\":\"2013-01-09T00:00:00.000Z\",\"C\":0.8321,\"D\":3,\"E\":\"kennedy\",\"F\":\"zoo\",\"G\":false}]}", 489 | "_df_range": [ 490 | 0, 491 | 100 492 | ], 493 | "_interval_columns": [], 494 | "_model_module_version": "1.0.0-alpha.6", 495 | "_row_count": 9, 496 | "_sort_ascending": true, 497 | "_sort_field": "", 498 | "_view_module_version": "1.0.0-alpha.6", 499 | "grid_options": { 500 | "autoEdit": false, 501 | "defaultColumnWidth": 150, 502 | "editable": true, 503 | "enableColumnReorder": false, 504 | "enableTextSelectionOnCells": true, 505 | "explicitInitialization": true, 506 | "forceFitColumns": true, 507 | "fullWidthRows": true, 508 | "rowHeight": 28, 509 | "syncColumnCellResize": true 510 | }, 511 | "layout": "IPY_MODEL_1a834c4c69af4c48bed691594ce5e0ad", 512 | "precision": 5, 513 | "show_toolbar": false 514 | } 515 | }, 516 | "7ec042abef044645a9f8bd38a3f69faf": { 517 | "model_module": "qgrid", 518 | "model_module_version": "1.0.0-alpha.6", 519 | "model_name": "QgridModel", 520 | "state": { 521 | "_columns": { 522 | "A": { 523 | "name": "A", 524 | "type": "number" 525 | }, 526 | "B": { 527 | "name": "B", 528 | "type": "datetime" 529 | }, 530 | "C": { 531 | "name": "C", 532 | "type": "number" 533 | }, 534 | "D": { 535 | "name": "D", 536 | "type": "integer" 537 | }, 538 | "E": { 539 | "constraints": { 540 | "enum": [ 541 | "adams", 542 | "hamilton", 543 | "jefferson", 544 | "kennedy", 545 | "lincoln", 546 | "madison", 547 | "roosevelt", 548 | "washington" 549 | ] 550 | }, 551 | "name": "E", 552 | "ordered": false, 553 | "type": "any" 554 | }, 555 | "F": { 556 | "name": "F", 557 | "type": "string" 558 | }, 559 | "G": { 560 | "name": "G", 561 | "type": "boolean" 562 | }, 563 | "index": { 564 | "name": "index", 565 | "type": "integer" 566 | } 567 | }, 568 | "_df_json": "{\"schema\": {\"fields\":[{\"name\":\"index\",\"type\":\"integer\"},{\"name\":\"A\",\"type\":\"number\"},{\"name\":\"B\",\"type\":\"datetime\"},{\"name\":\"C\",\"type\":\"number\"},{\"name\":\"D\",\"type\":\"integer\"},{\"name\":\"E\",\"type\":\"any\",\"constraints\":{\"enum\":[\"adams\",\"hamilton\",\"jefferson\",\"kennedy\",\"lincoln\",\"madison\",\"roosevelt\",\"washington\"]},\"ordered\":false},{\"name\":\"F\",\"type\":\"string\"},{\"name\":\"G\",\"type\":\"boolean\"}],\"primaryKey\":[\"index\"],\"pandas_version\":\"0.20.0\"}, \"data\": [{\"index\":0,\"A\":1.0,\"B\":\"2013-01-01T00:00:00.000Z\",\"C\":0.13177,\"D\":3,\"E\":\"washington\",\"F\":\"foo\",\"G\":true},{\"index\":1,\"A\":1.0,\"B\":\"2013-01-02T00:00:00.000Z\",\"C\":-1.56846,\"D\":3,\"E\":\"adams\",\"F\":\"bar\",\"G\":false},{\"index\":2,\"A\":1.0,\"B\":\"2013-01-03T00:00:00.000Z\",\"C\":1.2584,\"D\":3,\"E\":\"washington\",\"F\":\"buzz\",\"G\":false},{\"index\":3,\"A\":1.0,\"B\":\"2013-01-04T00:00:00.000Z\",\"C\":-1.54316,\"D\":3,\"E\":\"madison\",\"F\":\"bippity\",\"G\":false},{\"index\":4,\"A\":1.0,\"B\":\"2013-01-05T00:00:00.000Z\",\"C\":0.01483,\"D\":3,\"E\":\"lincoln\",\"F\":\"boppity\",\"G\":false},{\"index\":5,\"A\":1.0,\"B\":\"2013-01-06T00:00:00.000Z\",\"C\":-0.26442,\"D\":3,\"E\":\"jefferson\",\"F\":\"foo\",\"G\":true},{\"index\":6,\"A\":1.0,\"B\":\"2013-01-07T00:00:00.000Z\",\"C\":-1.85692,\"D\":3,\"E\":\"hamilton\",\"F\":\"foo\",\"G\":true},{\"index\":7,\"A\":1.0,\"B\":\"2013-01-08T00:00:00.000Z\",\"C\":1.38498,\"D\":3,\"E\":\"roosevelt\",\"F\":\"bar\",\"G\":false},{\"index\":8,\"A\":1.0,\"B\":\"2013-01-09T00:00:00.000Z\",\"C\":0.40905,\"D\":3,\"E\":\"kennedy\",\"F\":\"zoo\",\"G\":false}]}", 569 | "_df_range": [ 570 | 0, 571 | 100 572 | ], 573 | "_interval_columns": [], 574 | "_model_module_version": "1.0.0-alpha.6", 575 | "_row_count": 9, 576 | "_sort_ascending": true, 577 | "_sort_field": "", 578 | "_view_module_version": "1.0.0-alpha.6", 579 | "grid_options": { 580 | "autoEdit": false, 581 | "defaultColumnWidth": 150, 582 | "editable": true, 583 | "enableColumnReorder": false, 584 | "enableTextSelectionOnCells": true, 585 | "explicitInitialization": true, 586 | "forceFitColumns": true, 587 | "fullWidthRows": true, 588 | "rowHeight": 28, 589 | "syncColumnCellResize": true 590 | }, 591 | "layout": "IPY_MODEL_8eb3cf5ce7da431db4a3e4e9d3d64511", 592 | "precision": 5, 593 | "show_toolbar": false 594 | } 595 | }, 596 | "8eb3cf5ce7da431db4a3e4e9d3d64511": { 597 | "model_module": "@jupyter-widgets/base", 598 | "model_module_version": "1.0.0", 599 | "model_name": "LayoutModel", 600 | "state": {} 601 | }, 602 | "fa118ab9f1c840cd83509f56d50ee163": { 603 | "model_module": "qgrid", 604 | "model_module_version": "1.0.0-alpha.6", 605 | "model_name": "QgridModel", 606 | "state": { 607 | "_columns": { 608 | "A": { 609 | "name": "A", 610 | "type": "number" 611 | }, 612 | "B": { 613 | "name": "B", 614 | "type": "datetime" 615 | }, 616 | "C": { 617 | "name": "C", 618 | "type": "number" 619 | }, 620 | "D": { 621 | "name": "D", 622 | "type": "integer" 623 | }, 624 | "E": { 625 | "constraints": { 626 | "enum": [ 627 | "adams", 628 | "hamilton", 629 | "jefferson", 630 | "kennedy", 631 | "lincoln", 632 | "madison", 633 | "roosevelt", 634 | "washington" 635 | ] 636 | }, 637 | "name": "E", 638 | "ordered": false, 639 | "type": "any" 640 | }, 641 | "F": { 642 | "name": "F", 643 | "type": "string" 644 | }, 645 | "G": { 646 | "name": "G", 647 | "type": "boolean" 648 | }, 649 | "index": { 650 | "name": "index", 651 | "type": "integer" 652 | } 653 | }, 654 | "_df_json": "{\"schema\": {\"fields\":[{\"name\":\"index\",\"type\":\"integer\"},{\"name\":\"A\",\"type\":\"number\"},{\"name\":\"B\",\"type\":\"datetime\"},{\"name\":\"C\",\"type\":\"number\"},{\"name\":\"D\",\"type\":\"integer\"},{\"name\":\"E\",\"type\":\"any\",\"constraints\":{\"enum\":[\"adams\",\"hamilton\",\"jefferson\",\"kennedy\",\"lincoln\",\"madison\",\"roosevelt\",\"washington\"]},\"ordered\":false},{\"name\":\"F\",\"type\":\"string\"},{\"name\":\"G\",\"type\":\"boolean\"}],\"primaryKey\":[\"index\"],\"pandas_version\":\"0.20.0\"}, \"data\": [{\"index\":0,\"A\":1.0,\"B\":\"2013-01-01T00:00:00.000Z\",\"C\":-0.67408,\"D\":3,\"E\":\"washington\",\"F\":\"foo\",\"G\":true},{\"index\":1,\"A\":1.0,\"B\":\"2013-01-02T00:00:00.000Z\",\"C\":-0.87122,\"D\":3,\"E\":\"adams\",\"F\":\"bar\",\"G\":false},{\"index\":2,\"A\":1.0,\"B\":\"2013-01-03T00:00:00.000Z\",\"C\":0.58722,\"D\":3,\"E\":\"washington\",\"F\":\"buzz\",\"G\":false},{\"index\":3,\"A\":1.0,\"B\":\"2013-01-04T00:00:00.000Z\",\"C\":0.14947,\"D\":3,\"E\":\"madison\",\"F\":\"bippity\",\"G\":false},{\"index\":4,\"A\":1.0,\"B\":\"2013-01-05T00:00:00.000Z\",\"C\":0.89719,\"D\":3,\"E\":\"lincoln\",\"F\":\"boppity\",\"G\":false},{\"index\":5,\"A\":1.0,\"B\":\"2013-01-06T00:00:00.000Z\",\"C\":0.41141,\"D\":3,\"E\":\"jefferson\",\"F\":\"foo\",\"G\":true},{\"index\":6,\"A\":1.0,\"B\":\"2013-01-07T00:00:00.000Z\",\"C\":0.66837,\"D\":3,\"E\":\"hamilton\",\"F\":\"foo\",\"G\":true},{\"index\":7,\"A\":1.0,\"B\":\"2013-01-08T00:00:00.000Z\",\"C\":0.42815,\"D\":3,\"E\":\"roosevelt\",\"F\":\"bar\",\"G\":false},{\"index\":8,\"A\":1.0,\"B\":\"2013-01-09T00:00:00.000Z\",\"C\":-0.49399,\"D\":3,\"E\":\"kennedy\",\"F\":\"zoo\",\"G\":false}]}", 655 | "_df_range": [ 656 | 0, 657 | 100 658 | ], 659 | "_interval_columns": [], 660 | "_model_module_version": "1.0.0-alpha.6", 661 | "_row_count": 9, 662 | "_sort_ascending": true, 663 | "_sort_field": "", 664 | "_view_module_version": "1.0.0-alpha.6", 665 | "grid_options": { 666 | "autoEdit": false, 667 | "defaultColumnWidth": 150, 668 | "editable": true, 669 | "enableColumnReorder": false, 670 | "enableTextSelectionOnCells": true, 671 | "explicitInitialization": true, 672 | "forceFitColumns": true, 673 | "fullWidthRows": true, 674 | "rowHeight": 28, 675 | "syncColumnCellResize": true 676 | }, 677 | "layout": "IPY_MODEL_3fb8c261d3e249248ea7703065634285", 678 | "precision": 5, 679 | "show_toolbar": false 680 | } 681 | } 682 | }, 683 | "version_major": 2, 684 | "version_minor": 0 685 | } 686 | } 687 | }, 688 | "nbformat": 4, 689 | "nbformat_minor": 2 690 | } 691 | -------------------------------------------------------------------------------- /postBuild: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | jupyter labextension install @jupyter-widgets/jupyterlab-manager qgrid 4 | -------------------------------------------------------------------------------- /requirements_dev.txt: -------------------------------------------------------------------------------- 1 | pandas-datareader>=0.5.0 2 | matplotlib>=2.1.1 3 | -------------------------------------------------------------------------------- /webinar_jlab_demo.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Linking qgrid to other visualizations using event callbacks\n", 8 | "===============================================\n", 9 | "\n", 10 | "The following examples use qgrid's new \"events API\" that is only available in qgrid version 1.0.3 or newer. Specifically this notebook makes use of the ``on`` methods that qgrid provides for attaching event handlers. Event handlers can be attached using the ``qgrid.on`` method to listen for events on all widgets, or using the ``QgridWidget.on`` method the to listen for events on individual QgridWidget instances. " 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "metadata": {}, 16 | "source": [ 17 | "## Example 1 - Filter matplotlib scatter plot using qgrid\n", 18 | "In this example you'll see that by listening for a QgridWidget instances's ``filter_changed`` event, we can use qgrid to filter the data that's being visualized by another control in the notebook, in this case a matplotlib scatter plot. \n", 19 | "\n", 20 | "This capability allows you to filter a visualization by ANY field in the underlying DataFrame, including fields that are not used to generate the visualization. This enables interesting workflows like using a Categorical column to mark a particular row of the DataFrame with as \"bad\", setting a filter to hide \"bad\" rows in the qgrid instance, and then seeing the \"bad\" rows also disappear from any visualizations that the qgrid instance is hooked up to.\n", 21 | "\n", 22 | "The try out a simple example of using qgrid to filter another visualization, first execute the following two cells. Once you do that you should see a qgrid instance and a matplotlib scatter plot showing the same data as the qgrid instance. Next, set some filters on the columns of the qgrid instance and watch what happens to the scatter plot. You should see it update immediately to reflect the filtering changes." 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": null, 28 | "metadata": {}, 29 | "outputs": [], 30 | "source": [ 31 | "import numpy as np\n", 32 | "import pandas as pd\n", 33 | "import qgrid\n", 34 | "randn = np.random.randn\n", 35 | "df_types = pd.DataFrame({\n", 36 | " 'A' : pd.Series(['2013-01-01', '2013-01-02', '2013-01-03', '2013-01-04',\n", 37 | " '2013-01-05', '2013-01-06', '2013-01-07', '2013-01-08', '2013-01-09'],index=list(range(9)),dtype='datetime64[ns]'),\n", 38 | " 'B' : pd.Series(randn(9),index=list(range(9)),dtype='float32'),\n", 39 | " 'C' : pd.Categorical([\"washington\", \"adams\", \"washington\", \"madison\", \"lincoln\",\"jefferson\", \"hamilton\", \"roosevelt\", \"kennedy\"]),\n", 40 | " 'D' : [\"foo\", \"bar\", \"buzz\", \"bippity\",\"boppity\", \"foo\", \"foo\", \"bar\", \"zoo\"] })\n", 41 | "df_types['E'] = df_types['D'] != 'foo'\n", 42 | "qgrid_widget = qgrid.show_grid(df_types, show_toolbar=True)\n", 43 | "qgrid_widget" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "col_opts = { \n", 53 | " 'editable': False,\n", 54 | " 'toolTip': \"Not editable\"\n", 55 | "}\n", 56 | "\n", 57 | "col_defs = {\n", 58 | " 'B': {\n", 59 | " 'editable': True,\n", 60 | " 'toolTip': \"Editable\"\n", 61 | " },\n", 62 | " 'E': {\n", 63 | " 'editable': True,\n", 64 | " 'toolTip': \"Also editable\",\n", 65 | " 'width': 30\n", 66 | " }\n", 67 | "}\n", 68 | "qgrid_widget = qgrid.show_grid(df_types, column_options=col_opts, column_definitions=col_defs, show_toolbar=True)\n", 69 | "qgrid_widget" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": null, 75 | "metadata": {}, 76 | "outputs": [], 77 | "source": [ 78 | "%matplotlib ipympl\n", 79 | "import matplotlib.pyplot as plt\n", 80 | "from traitlets import All\n", 81 | "\n", 82 | "n = 50\n", 83 | "\n", 84 | "qgrid_df = qgrid_widget.get_changed_df()\n", 85 | "x = qgrid_df.index\n", 86 | "y = qgrid_df['B']\n", 87 | "\n", 88 | "fig, ax = plt.subplots()\n", 89 | "fit = np.polyfit(x, y, deg=1)\n", 90 | "line, = ax.plot(x, fit[0] * x + fit[1], color='red')\n", 91 | "scatter, = ax.plot(x,y,ms=8,color='b',marker='o',ls='')\n", 92 | "\n", 93 | "def handle_qgrid_event(event, widget):\n", 94 | " qgrid_df = qgrid_widget.get_changed_df()\n", 95 | " x = qgrid_df.index\n", 96 | " y = qgrid_df['B']\n", 97 | " fit = np.polyfit(x, y, deg=1)\n", 98 | " line.set_data(x, fit[0] * x + fit[1])\n", 99 | " fig.canvas.draw()\n", 100 | " scatter.set_data(x, y)\n", 101 | " fig.canvas.draw()\n", 102 | "\n", 103 | "qgrid_widget.on(All, handle_qgrid_event)\n" 104 | ] 105 | }, 106 | { 107 | "cell_type": "markdown", 108 | "metadata": {}, 109 | "source": [ 110 | "## Example 2 - Logging all events\n", 111 | "In this example we'll see how you can listen for events from any qgrid instance using the `qgrid.on` method.\n", 112 | "\n", 113 | "Execute the following two cells. The first cell will create an empty output widget, and the second cell use the `on` method to listen for all events from all qgrid instances. Once the cells are executed, try interacting with any of the qgrid instances you created earlier in the notebook (i.e. by sorting, filtering, scrolling, etc). Then scroll back down to this output widget and you'll notice that any actions that you took got printed to the output widget.\n", 114 | "\n", 115 | "In practice you'd probably want to do something more interesting than just print these events to the notebook, such as log the events to a service that you use to track user interactions. This is just a proof-of-concept to show which events are available." 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": null, 121 | "metadata": {}, 122 | "outputs": [], 123 | "source": [ 124 | "import ipywidgets as widgets\n", 125 | "user_interactions = widgets.Output(layout={'border': '1px solid black'})\n", 126 | "user_interactions" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": null, 132 | "metadata": {}, 133 | "outputs": [], 134 | "source": [ 135 | "import qgrid\n", 136 | "from traitlets import All\n", 137 | "from pprint import pprint\n", 138 | "\n", 139 | "def handle_all_events(event, qgrid_widget):\n", 140 | " if event['name'] != 'json_updated':\n", 141 | " with user_interactions:\n", 142 | " pprint(event)\n", 143 | "\n", 144 | "qgrid.on(All, handle_all_events)" 145 | ] 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": null, 150 | "metadata": {}, 151 | "outputs": [], 152 | "source": [ 153 | "user_interactions.clear_output()" 154 | ] 155 | }, 156 | { 157 | "cell_type": "markdown", 158 | "metadata": {}, 159 | "source": [ 160 | "## Example 3 - Highlight visible rows in matplotlib price chart using qgrid\n", 161 | "This example is basically a repeat of Example 1, except with a line chart of some pricing data for the S&P 500 instead of a scatter plot.\n", 162 | "\n", 163 | "First, execute the following two cells. Once you do that you should see a qgrid instance and a matplotlib line chart showing the same data as the qgrid instance. Next, set some filters on the columns of the qgrid instance and watch what happens to the line chart (it should update immediately to reflect the filtering changes)." 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": null, 169 | "metadata": {}, 170 | "outputs": [], 171 | "source": [ 172 | "import pandas as pd\n", 173 | "import numpy as np\n", 174 | "import qgrid\n", 175 | "randn = np.random.randn\n", 176 | "\n", 177 | "# Get a pandas DataFrame containing the daily prices for the S&P 500 from 1/1/2014 - 1/1/2017\n", 178 | "from pandas_datareader.data import DataReader\n", 179 | "spy = DataReader(\n", 180 | " 'SPY',\n", 181 | " 'yahoo',\n", 182 | " pd.Timestamp('2014-01-01'), \n", 183 | " pd.Timestamp('2017-01-01'),\n", 184 | ")\n", 185 | "# Tell qgrid to automatically render all DataFrames and Series as qgrids.\n", 186 | "qgrid.enable()\n", 187 | "\n", 188 | "# Render the DataFrame as a qgrid automatically\n", 189 | "spy_qgrid = qgrid.show_grid(spy, grid_options={'forceFitColumns': False})\n", 190 | "spy_qgrid" 191 | ] 192 | }, 193 | { 194 | "cell_type": "code", 195 | "execution_count": null, 196 | "metadata": {}, 197 | "outputs": [], 198 | "source": [ 199 | "%matplotlib ipympl\n", 200 | "import matplotlib.pyplot as plt\n", 201 | "import datetime\n", 202 | "import matplotlib.pyplot as plt\n", 203 | "import matplotlib.dates as mdates\n", 204 | "import matplotlib.cbook as cbook\n", 205 | "from traitlets import All\n", 206 | "\n", 207 | "years = mdates.YearLocator() # every year\n", 208 | "months = mdates.MonthLocator() # every month\n", 209 | "yearsFmt = mdates.DateFormatter('%Y')\n", 210 | "\n", 211 | "n = 50\n", 212 | "qgrid_spy_df = spy_qgrid.get_changed_df()\n", 213 | "x = qgrid_spy_df.index\n", 214 | "y = qgrid_spy_df['Close']\n", 215 | "\n", 216 | "fig, ax = plt.subplots()\n", 217 | "vp_start = mdates.date2num(qgrid_spy_df.iloc[spy_qgrid._viewport_range[0]].name)\n", 218 | "vp_end = mdates.date2num(qgrid_spy_df.iloc[spy_qgrid._viewport_range[1]].name)\n", 219 | "vp_span = plt.axvspan(vp_start, vp_end, facecolor='g', alpha=0.2)\n", 220 | "line, = ax.plot(x, y)\n", 221 | "\n", 222 | "# format the ticks\n", 223 | "ax.xaxis.set_major_locator(years)\n", 224 | "ax.xaxis.set_major_formatter(yearsFmt)\n", 225 | "ax.xaxis.set_minor_locator(months)\n", 226 | "\n", 227 | "datemin = datetime.date(x.min().year, 1, 1)\n", 228 | "datemax = datetime.date(x.max().year + 1, 1, 1)\n", 229 | "ax.set_xlim(datemin, datemax)\n", 230 | "\n", 231 | "# format the coords message box\n", 232 | "def price(x):\n", 233 | " return '$%1.2f' % x\n", 234 | "ax.format_xdata = mdates.DateFormatter('%Y-%m-%d')\n", 235 | "ax.format_ydata = price\n", 236 | "ax.grid(True)\n", 237 | "\n", 238 | "# rotates and right aligns the x labels, and moves the bottom of the\n", 239 | "# axes up to make room for them\n", 240 | "fig.autofmt_xdate()\n", 241 | "\n", 242 | "def handle_viewport_changed(event, widget):\n", 243 | " qgrid_spy_df = widget.get_changed_df()\n", 244 | " viewport = spy_qgrid._viewport_range\n", 245 | " \n", 246 | " vp_start = mdates.date2num(qgrid_spy_df.iloc[viewport[0]].name)\n", 247 | " vp_end = mdates.date2num(qgrid_spy_df.iloc[viewport[1]].name)\n", 248 | "\n", 249 | " vp_span.set_xy([(vp_start, 0), (vp_start, 1), (vp_end, 1), (vp_end ,0)])\n", 250 | " \n", 251 | " \n", 252 | "spy_qgrid.on('viewport_changed', handle_viewport_changed)" 253 | ] 254 | } 255 | ], 256 | "metadata": { 257 | "kernelspec": { 258 | "display_name": "Python 3", 259 | "language": "python", 260 | "name": "python3" 261 | }, 262 | "language_info": { 263 | "codemirror_mode": { 264 | "name": "ipython", 265 | "version": 3 266 | }, 267 | "file_extension": ".py", 268 | "mimetype": "text/x-python", 269 | "name": "python", 270 | "nbconvert_exporter": "python", 271 | "pygments_lexer": "ipython3", 272 | "version": "3.6.1" 273 | }, 274 | "widgets": { 275 | "application/vnd.jupyter.widget-state+json": { 276 | "state": { 277 | "1a834c4c69af4c48bed691594ce5e0ad": { 278 | "model_module": "@jupyter-widgets/base", 279 | "model_module_version": "1.0.0", 280 | "model_name": "LayoutModel", 281 | "state": {} 282 | }, 283 | "3fb8c261d3e249248ea7703065634285": { 284 | "model_module": "@jupyter-widgets/base", 285 | "model_module_version": "1.0.0", 286 | "model_name": "LayoutModel", 287 | "state": {} 288 | }, 289 | "7aa5e1ce49fc4d0f9366bea5c684c58d": { 290 | "model_module": "qgrid", 291 | "model_module_version": "1.0.0-alpha.6", 292 | "model_name": "QgridModel", 293 | "state": { 294 | "_columns": { 295 | "A": { 296 | "name": "A", 297 | "type": "number" 298 | }, 299 | "B": { 300 | "name": "B", 301 | "type": "datetime" 302 | }, 303 | "C": { 304 | "name": "C", 305 | "type": "number" 306 | }, 307 | "D": { 308 | "name": "D", 309 | "type": "integer" 310 | }, 311 | "E": { 312 | "constraints": { 313 | "enum": [ 314 | "adams", 315 | "hamilton", 316 | "jefferson", 317 | "kennedy", 318 | "lincoln", 319 | "madison", 320 | "roosevelt", 321 | "washington" 322 | ] 323 | }, 324 | "name": "E", 325 | "ordered": false, 326 | "type": "any" 327 | }, 328 | "F": { 329 | "name": "F", 330 | "type": "string" 331 | }, 332 | "G": { 333 | "name": "G", 334 | "type": "boolean" 335 | }, 336 | "index": { 337 | "name": "index", 338 | "type": "integer" 339 | } 340 | }, 341 | "_df_json": "{\"schema\": {\"fields\":[{\"name\":\"index\",\"type\":\"integer\"},{\"name\":\"A\",\"type\":\"number\"},{\"name\":\"B\",\"type\":\"datetime\"},{\"name\":\"C\",\"type\":\"number\"},{\"name\":\"D\",\"type\":\"integer\"},{\"name\":\"E\",\"type\":\"any\",\"constraints\":{\"enum\":[\"adams\",\"hamilton\",\"jefferson\",\"kennedy\",\"lincoln\",\"madison\",\"roosevelt\",\"washington\"]},\"ordered\":false},{\"name\":\"F\",\"type\":\"string\"},{\"name\":\"G\",\"type\":\"boolean\"}],\"primaryKey\":[\"index\"],\"pandas_version\":\"0.20.0\"}, \"data\": [{\"index\":0,\"A\":1.0,\"B\":\"2013-01-01T00:00:00.000Z\",\"C\":-0.09128,\"D\":3,\"E\":\"washington\",\"F\":\"foo\",\"G\":true},{\"index\":1,\"A\":1.0,\"B\":\"2013-01-02T00:00:00.000Z\",\"C\":-0.57373,\"D\":3,\"E\":\"adams\",\"F\":\"bar\",\"G\":false},{\"index\":2,\"A\":1.0,\"B\":\"2013-01-03T00:00:00.000Z\",\"C\":0.4723,\"D\":3,\"E\":\"washington\",\"F\":\"buzz\",\"G\":false},{\"index\":3,\"A\":1.0,\"B\":\"2013-01-04T00:00:00.000Z\",\"C\":-0.09316,\"D\":3,\"E\":\"madison\",\"F\":\"bippity\",\"G\":false},{\"index\":4,\"A\":1.0,\"B\":\"2013-01-05T00:00:00.000Z\",\"C\":-0.20181,\"D\":3,\"E\":\"lincoln\",\"F\":\"boppity\",\"G\":false},{\"index\":5,\"A\":1.0,\"B\":\"2013-01-06T00:00:00.000Z\",\"C\":1.7561,\"D\":3,\"E\":\"jefferson\",\"F\":\"foo\",\"G\":true},{\"index\":6,\"A\":1.0,\"B\":\"2013-01-07T00:00:00.000Z\",\"C\":1.20064,\"D\":3,\"E\":\"hamilton\",\"F\":\"foo\",\"G\":true},{\"index\":7,\"A\":1.0,\"B\":\"2013-01-08T00:00:00.000Z\",\"C\":0.98097,\"D\":3,\"E\":\"roosevelt\",\"F\":\"bar\",\"G\":false},{\"index\":8,\"A\":1.0,\"B\":\"2013-01-09T00:00:00.000Z\",\"C\":0.8321,\"D\":3,\"E\":\"kennedy\",\"F\":\"zoo\",\"G\":false}]}", 342 | "_df_range": [ 343 | 0, 344 | 100 345 | ], 346 | "_interval_columns": [], 347 | "_model_module_version": "1.0.0-alpha.6", 348 | "_row_count": 9, 349 | "_sort_ascending": true, 350 | "_sort_field": "", 351 | "_view_module_version": "1.0.0-alpha.6", 352 | "grid_options": { 353 | "autoEdit": false, 354 | "defaultColumnWidth": 150, 355 | "editable": true, 356 | "enableColumnReorder": false, 357 | "enableTextSelectionOnCells": true, 358 | "explicitInitialization": true, 359 | "forceFitColumns": true, 360 | "fullWidthRows": true, 361 | "rowHeight": 28, 362 | "syncColumnCellResize": true 363 | }, 364 | "layout": "IPY_MODEL_1a834c4c69af4c48bed691594ce5e0ad", 365 | "precision": 5, 366 | "show_toolbar": false 367 | } 368 | }, 369 | "7ec042abef044645a9f8bd38a3f69faf": { 370 | "model_module": "qgrid", 371 | "model_module_version": "1.0.0-alpha.6", 372 | "model_name": "QgridModel", 373 | "state": { 374 | "_columns": { 375 | "A": { 376 | "name": "A", 377 | "type": "number" 378 | }, 379 | "B": { 380 | "name": "B", 381 | "type": "datetime" 382 | }, 383 | "C": { 384 | "name": "C", 385 | "type": "number" 386 | }, 387 | "D": { 388 | "name": "D", 389 | "type": "integer" 390 | }, 391 | "E": { 392 | "constraints": { 393 | "enum": [ 394 | "adams", 395 | "hamilton", 396 | "jefferson", 397 | "kennedy", 398 | "lincoln", 399 | "madison", 400 | "roosevelt", 401 | "washington" 402 | ] 403 | }, 404 | "name": "E", 405 | "ordered": false, 406 | "type": "any" 407 | }, 408 | "F": { 409 | "name": "F", 410 | "type": "string" 411 | }, 412 | "G": { 413 | "name": "G", 414 | "type": "boolean" 415 | }, 416 | "index": { 417 | "name": "index", 418 | "type": "integer" 419 | } 420 | }, 421 | "_df_json": "{\"schema\": {\"fields\":[{\"name\":\"index\",\"type\":\"integer\"},{\"name\":\"A\",\"type\":\"number\"},{\"name\":\"B\",\"type\":\"datetime\"},{\"name\":\"C\",\"type\":\"number\"},{\"name\":\"D\",\"type\":\"integer\"},{\"name\":\"E\",\"type\":\"any\",\"constraints\":{\"enum\":[\"adams\",\"hamilton\",\"jefferson\",\"kennedy\",\"lincoln\",\"madison\",\"roosevelt\",\"washington\"]},\"ordered\":false},{\"name\":\"F\",\"type\":\"string\"},{\"name\":\"G\",\"type\":\"boolean\"}],\"primaryKey\":[\"index\"],\"pandas_version\":\"0.20.0\"}, \"data\": [{\"index\":0,\"A\":1.0,\"B\":\"2013-01-01T00:00:00.000Z\",\"C\":0.13177,\"D\":3,\"E\":\"washington\",\"F\":\"foo\",\"G\":true},{\"index\":1,\"A\":1.0,\"B\":\"2013-01-02T00:00:00.000Z\",\"C\":-1.56846,\"D\":3,\"E\":\"adams\",\"F\":\"bar\",\"G\":false},{\"index\":2,\"A\":1.0,\"B\":\"2013-01-03T00:00:00.000Z\",\"C\":1.2584,\"D\":3,\"E\":\"washington\",\"F\":\"buzz\",\"G\":false},{\"index\":3,\"A\":1.0,\"B\":\"2013-01-04T00:00:00.000Z\",\"C\":-1.54316,\"D\":3,\"E\":\"madison\",\"F\":\"bippity\",\"G\":false},{\"index\":4,\"A\":1.0,\"B\":\"2013-01-05T00:00:00.000Z\",\"C\":0.01483,\"D\":3,\"E\":\"lincoln\",\"F\":\"boppity\",\"G\":false},{\"index\":5,\"A\":1.0,\"B\":\"2013-01-06T00:00:00.000Z\",\"C\":-0.26442,\"D\":3,\"E\":\"jefferson\",\"F\":\"foo\",\"G\":true},{\"index\":6,\"A\":1.0,\"B\":\"2013-01-07T00:00:00.000Z\",\"C\":-1.85692,\"D\":3,\"E\":\"hamilton\",\"F\":\"foo\",\"G\":true},{\"index\":7,\"A\":1.0,\"B\":\"2013-01-08T00:00:00.000Z\",\"C\":1.38498,\"D\":3,\"E\":\"roosevelt\",\"F\":\"bar\",\"G\":false},{\"index\":8,\"A\":1.0,\"B\":\"2013-01-09T00:00:00.000Z\",\"C\":0.40905,\"D\":3,\"E\":\"kennedy\",\"F\":\"zoo\",\"G\":false}]}", 422 | "_df_range": [ 423 | 0, 424 | 100 425 | ], 426 | "_interval_columns": [], 427 | "_model_module_version": "1.0.0-alpha.6", 428 | "_row_count": 9, 429 | "_sort_ascending": true, 430 | "_sort_field": "", 431 | "_view_module_version": "1.0.0-alpha.6", 432 | "grid_options": { 433 | "autoEdit": false, 434 | "defaultColumnWidth": 150, 435 | "editable": true, 436 | "enableColumnReorder": false, 437 | "enableTextSelectionOnCells": true, 438 | "explicitInitialization": true, 439 | "forceFitColumns": true, 440 | "fullWidthRows": true, 441 | "rowHeight": 28, 442 | "syncColumnCellResize": true 443 | }, 444 | "layout": "IPY_MODEL_8eb3cf5ce7da431db4a3e4e9d3d64511", 445 | "precision": 5, 446 | "show_toolbar": false 447 | } 448 | }, 449 | "8eb3cf5ce7da431db4a3e4e9d3d64511": { 450 | "model_module": "@jupyter-widgets/base", 451 | "model_module_version": "1.0.0", 452 | "model_name": "LayoutModel", 453 | "state": {} 454 | }, 455 | "fa118ab9f1c840cd83509f56d50ee163": { 456 | "model_module": "qgrid", 457 | "model_module_version": "1.0.0-alpha.6", 458 | "model_name": "QgridModel", 459 | "state": { 460 | "_columns": { 461 | "A": { 462 | "name": "A", 463 | "type": "number" 464 | }, 465 | "B": { 466 | "name": "B", 467 | "type": "datetime" 468 | }, 469 | "C": { 470 | "name": "C", 471 | "type": "number" 472 | }, 473 | "D": { 474 | "name": "D", 475 | "type": "integer" 476 | }, 477 | "E": { 478 | "constraints": { 479 | "enum": [ 480 | "adams", 481 | "hamilton", 482 | "jefferson", 483 | "kennedy", 484 | "lincoln", 485 | "madison", 486 | "roosevelt", 487 | "washington" 488 | ] 489 | }, 490 | "name": "E", 491 | "ordered": false, 492 | "type": "any" 493 | }, 494 | "F": { 495 | "name": "F", 496 | "type": "string" 497 | }, 498 | "G": { 499 | "name": "G", 500 | "type": "boolean" 501 | }, 502 | "index": { 503 | "name": "index", 504 | "type": "integer" 505 | } 506 | }, 507 | "_df_json": "{\"schema\": {\"fields\":[{\"name\":\"index\",\"type\":\"integer\"},{\"name\":\"A\",\"type\":\"number\"},{\"name\":\"B\",\"type\":\"datetime\"},{\"name\":\"C\",\"type\":\"number\"},{\"name\":\"D\",\"type\":\"integer\"},{\"name\":\"E\",\"type\":\"any\",\"constraints\":{\"enum\":[\"adams\",\"hamilton\",\"jefferson\",\"kennedy\",\"lincoln\",\"madison\",\"roosevelt\",\"washington\"]},\"ordered\":false},{\"name\":\"F\",\"type\":\"string\"},{\"name\":\"G\",\"type\":\"boolean\"}],\"primaryKey\":[\"index\"],\"pandas_version\":\"0.20.0\"}, \"data\": [{\"index\":0,\"A\":1.0,\"B\":\"2013-01-01T00:00:00.000Z\",\"C\":-0.67408,\"D\":3,\"E\":\"washington\",\"F\":\"foo\",\"G\":true},{\"index\":1,\"A\":1.0,\"B\":\"2013-01-02T00:00:00.000Z\",\"C\":-0.87122,\"D\":3,\"E\":\"adams\",\"F\":\"bar\",\"G\":false},{\"index\":2,\"A\":1.0,\"B\":\"2013-01-03T00:00:00.000Z\",\"C\":0.58722,\"D\":3,\"E\":\"washington\",\"F\":\"buzz\",\"G\":false},{\"index\":3,\"A\":1.0,\"B\":\"2013-01-04T00:00:00.000Z\",\"C\":0.14947,\"D\":3,\"E\":\"madison\",\"F\":\"bippity\",\"G\":false},{\"index\":4,\"A\":1.0,\"B\":\"2013-01-05T00:00:00.000Z\",\"C\":0.89719,\"D\":3,\"E\":\"lincoln\",\"F\":\"boppity\",\"G\":false},{\"index\":5,\"A\":1.0,\"B\":\"2013-01-06T00:00:00.000Z\",\"C\":0.41141,\"D\":3,\"E\":\"jefferson\",\"F\":\"foo\",\"G\":true},{\"index\":6,\"A\":1.0,\"B\":\"2013-01-07T00:00:00.000Z\",\"C\":0.66837,\"D\":3,\"E\":\"hamilton\",\"F\":\"foo\",\"G\":true},{\"index\":7,\"A\":1.0,\"B\":\"2013-01-08T00:00:00.000Z\",\"C\":0.42815,\"D\":3,\"E\":\"roosevelt\",\"F\":\"bar\",\"G\":false},{\"index\":8,\"A\":1.0,\"B\":\"2013-01-09T00:00:00.000Z\",\"C\":-0.49399,\"D\":3,\"E\":\"kennedy\",\"F\":\"zoo\",\"G\":false}]}", 508 | "_df_range": [ 509 | 0, 510 | 100 511 | ], 512 | "_interval_columns": [], 513 | "_model_module_version": "1.0.0-alpha.6", 514 | "_row_count": 9, 515 | "_sort_ascending": true, 516 | "_sort_field": "", 517 | "_view_module_version": "1.0.0-alpha.6", 518 | "grid_options": { 519 | "autoEdit": false, 520 | "defaultColumnWidth": 150, 521 | "editable": true, 522 | "enableColumnReorder": false, 523 | "enableTextSelectionOnCells": true, 524 | "explicitInitialization": true, 525 | "forceFitColumns": true, 526 | "fullWidthRows": true, 527 | "rowHeight": 28, 528 | "syncColumnCellResize": true 529 | }, 530 | "layout": "IPY_MODEL_3fb8c261d3e249248ea7703065634285", 531 | "precision": 5, 532 | "show_toolbar": false 533 | } 534 | } 535 | }, 536 | "version_major": 2, 537 | "version_minor": 0 538 | } 539 | } 540 | }, 541 | "nbformat": 4, 542 | "nbformat_minor": 2 543 | } 544 | --------------------------------------------------------------------------------