如果你是一个用 Python 的数据科学家,那么用 Jupyter Notebook 便是大概率事宜了。作为 Jupyter Notebook 的「下一代」web 运用,Jupyter Lab 供应了比较以往更多的便捷功能,个中之一便是扩展。
现在,纵然是 Jupyter Lab 开拓者团队也对如此发达发展的第三方扩展工具社区而感到愉快了。在这篇文章中,机器学习工程师、打算机科学博士 Christopher Tao 将为读者先容 10 种 Jupter Lab 扩展工具,它们对付范例的数据科学家 / 工程师来说可以大幅提高生产力。
10 大 Jupyter Lab 扩展

目前,大多数在线资源都会利用以下命令来安装 Jupyter Lab 扩展:
当然,很多人都喜好利用这种命令。如果你是 VS-Code、Sublime 或 Atom 的用户,你大概会希望在「管理器」中直接搜索要安装的内容。Jupyter Lab 却没有供应这些功能。
如上图所示,你可以转到左侧导航栏第 4 个选项卡,即扩展管理器(extension manager)。然后就可以搜索到你须要的扩展。
现在总结一下值得推举的 10 个 Jupyter Lab 扩展。
JupyterLab 调试器
由于 Jupyter 的交互性,它受到了很多人的喜好。然而,调试功能是编码所必须的。例如,我们可以逐步调试 for 循环(for-loop )来查看内部发生了什么。大多数 IDE 工具都支持这种带有「step over」和「step into」的调试特性,但遗憾的是,Jupyter 中没有这种特性。
「jupyterlab/debugger」便是这样一个扩展,让我们可以补足 Jupyter Lab 中短缺的这个功能。
JupyterLab-TOC
JupyterLab-TOC 项目地址:https://github.com/jupyterlab/jupyterlab-toc
notebook 太长?想让你的 notebook 看起来更俊秀?或者希望 notebook 有一个目录?「jupyterlab/toc」帮你实现。
图源: https://github.com/jupyterlab/jupyterlab-toc/raw/master/toc.gif
有了这个扩展,基于用标题标记的单元格会自动天生目录(确保利用标记 ## 来指定你的标题级别)。这也是利用 Jupyter Notebook 的好方法,让你的事情更有系统性和组织性。
JupyterLab-DrawIO
JupyterLab-DrawIO 项目地址:https://github.com/QuantStack/jupyterlab-drawio
Diagram.net(原名 Draw.IO)是绘制图表的工具,它确实是 MS Visio 完美的开源替代品。借助于 jupyterlab-drawio,我们可以在 Jupyter Lab 上利用该工具。
图源:https://github.com/QuantStack/jupyterlab-drawio/raw/master/drawio.gif
JupyterLab Execution Time
JupyterLab Execution Time 项目地址:https://github.com/deshaw/jupyterlab-execute-time
Jupyter Notebook/Lab 的一个惊人特性是它能供应许多有用的魔术命令(magic command)。例如我们可以利用「%timeit」测试代码运行韶光。它将运行代码片段数百或数千次,并得到均匀值,以确保给出一个公正和准确的结果。
但有时并不须要这样精确。我们只不过想知道每个单元运行的韶光,在这种情形下,为每个单元利用「%timeit」变得不得当了。
在这种情形下,我们可以利用「jupyterlab-execute-time」。
如上图所示,「jupyterlab-execute-time」不仅显示了实行单元的韶光间隔,而且还显示了末了实行的韶光。
JupyterLab Spreadsheet
JupyterLab Spreadsheet 项目地址:https://github.com/quigleyj97/jupyterlab-spreadsheet
作为一名数据科学家或数据工程师,你不得不与电子表格打交道。但是,Jupyter 本身不支持读取 Excel 文件,这迫使我们须要打开多个工具,在 Jupyter 编码以及 Excel 之间一直地切换。
「jupyterlab-spreadsheet」可以很好地办理这类问题。它在 Jupyter Lab 中嵌入了 xls/xlsx 电子表格查看功能,因此我们可以在同一个地方得到所需的统统。
图源: https://github.com/quigleyj97/jupyterlab-spreadsheet/raw/main/screenshot.png
JupyterLab System Monitor
jupyterlab-system-monitor 项目地址:https://github.com/jtpio/jupyterlab-system-monitor
Python 不是一种高效实行的编程措辞,这意味着与其他措辞比较,它可能会花费更多的 CPU 和内存资源。Python 的最常见用例之一是数据科学。以是,我们可能想要监控自身材系硬件资源,从而把稳到 Python 代码可能冻结了操作系统。
jupyterlab-topbar-extension 你想要拥有的扩展,它可以在 Jupyter Lab UI 的顶部栏显示 CPU 和内存利用情形,这样我们就可以实时监控了。如下动图所示:
图源:https://github.com/jtpio/jupyterlab-system-monitor/raw/main/doc/screencast.gif
JupyterLab Kite
jupyterlab-kite 项目地址:https://github.com/kiteco/jupyterlab-kite
虽然我很喜好 Jupyter,但它不像其他经典 IDE 工具一样供应代码自动补全功能。Jupyter 的代码自动补全非常受限且速率很慢。
你可能听说过免费的 AI 赋能代码补全做事 Kite,它在 Sublime、VS Code 和 PyCharm 等险些所有盛行的 IDE 工具中都可以利用。通过 jupyterlab-kite (https://github.com/kiteco/jupyterlab-kite) 扩展,你也可以在 Jupyter Lab 中利用这一功能。
图源:https://github.com/kiteco/jupyterlab-kite
JupyterLab Variable Inspector
jupyterlab-variableInspector 项目地址:https://github.com/lckr/jupyterlab-variableInspector
如果你是从 R studio 或 Matlab 转向利用 Jupyter Lab 的数据科学家,则可能对这些工具供应的变量检测器非常熟习。但遗憾的是,Jupyter Lab 默认不支持这一功能。这时,jupyterlab-variableInspector 扩展可以重新支持该功能。
图源:https://github.com/lckr/jupyterlab-variableInspector/raw/master/early_demo.gif
JupyterLab Matplotlib
Matplotlib/ipympl 项目地址:https://github.com/matplotlib/ipympl
如果你是数据科学家,则 Matplotlib 是必须学习(must-learn)的 Python 库。该库是 Python 中一个根本但强大的数据可视化工具。但当我们利用 Jupyter Lab 时,交互特色消逝了。
jupyter-matplotlib 扩展可以使 Matplotlib 再次具备交互性。只须要输入一个魔术命令 %matplotlib widget 来启动它,则你的精美 3D 图表就变成交互式的。如下动图所示:
图源:https://github.com/matplotlib/ipympl/raw/master/matplotlib.gif
JupyterLab Plotly
Plotly 利用指南:https://plotly.com/python/getting-started/#jupyterlab-support-python-35
虽然 Matplotlib 是最根本和强大的数据可视化库,但在这方面我最喜好的是 Plotly 库。该库封装了很多常见图表,我们可以通过数行代码天生令人惊叹的图表。
为使 Jupyter Lab 无缝支持和显示交互的 Plotly 图表,用户须要安装 jupyterlab-plotly。