Coursera 笔记

Module 07 · [Optional] IBM Watson Studio

Hands-on Lab: Getting started with Jupyter Notebooks动手实验:Jupyter Notebook 入门

Estimated Time: 10 mins  预计时间:10 分钟

Objective(s) 目标

In this lab, you will perform basic tasks in the Jupyter notebook -
在本实验中,你将在 Jupyter 笔记本中执行基本任务——

  • Add descriptive text and code
    添加描述性文本和代码
  • Execute and render the notebook
    执行并渲染笔记本

Pre-requisite(s) 前置条件

  • IBM Cloud account  IBM Cloud 账户

Before proceeding with this lab, please ensure you have created a IBM Cloud trial account using the feature code provided to you within the course. If not please ensure you complete the previous lab: IBM Cloud Account Setup.
在进行此实验之前,请确保您已使用课程中提供的功能码创建了 IBM Cloud 试用账户。如果没有,请确保您完成之前的实验:IBM Cloud 账户设置。

  • Setting up watsonx.ai service and adding Jupyter notebook
    设置 watsonx.ai 服务并添加 Jupyter 笔记本

After creating IBM Cloud account,you must create a watsonx.ai service on IBM Cloud and add a Jupyter notebook to it. If not please ensure you complete the previous lab: Creating a watsonx.ai Project with Jupyter Notebooks.
在创建 IBM Cloud 账户后,您必须在 IBM Cloud 上创建一个 watsonx.ai 服务,并将其添加一个 Jupyter 笔记本。如果没有,请确保您完成之前的实验:使用 Jupyter 笔记本创建 watsonx.ai 项目。

Task : Add descriptive text and code to your Jupyter notebook 任务:向您的 Jupyter 笔记本添加描述性文本和代码

In this lab you will get started with Jypter notebook and learn how to add code and descriptive text to the cell. You will then execute and render the Jupyter notebook to see the final output.
在本实验中,您将开始使用 Jupyter 笔记本,并学习如何向单元格中添加代码和描述性文本。然后,您将执行并渲染 Jupyter 笔记本以查看最终输出。

There are two main cell types that we will cover:
我们将涵盖两种主要的单元格类型:

A code cell contains code to be executed in the kernel. When the code is executed, the notebook displays the output below the code cell that generated it.
代码单元格包含在内核中执行的代码。当代码被执行时,笔记本会在生成该代码的单元格下方显示输出。

A Markdown cell contains text formatted using Markdown and displays text as output when the Markdown cell is executed.
Markdown 单元格包含使用 Markdown 格式化的文本,并在执行 Markdown 单元格时显示文本作为输出。

Now that you have an open Jupyter notebook in front of you, notice that there is a blank cell is already added to your notebook and there is a Kernel selection on top right corner that displays either Python or R version which you selected at the time of creating Jupyter notebook.
现在您面前有一个打开的 Jupyter 笔记本,请注意您的笔记本中已经添加了一个空白单元格,并且在右上角有一个内核选择,显示您在创建 Jupyter 笔记本时选择的 Python 或 R 版本。

  1. Enter the text in the cell as This program prints Hello, World!.
    在单元格中输入文本为 This program prints Hello, World! 。
  2. Change the cell type to Markdown.
    将单元格类型更改为 Markdown 。
  3. Click the Run icon or press Ctrl + Enter on your keyboard to run your code. This will render the text as output.
    点击 Run 图标或在键盘上按 Ctrl + Enter 组合键以运行您的代码。这将渲染文本为输出。

  1. The result should look like this.
    结果应如下所示。

  1. To insert a new cell below, click on the icon to the far right in the cell as shown below -
    在下方插入新单元格,点击单元格最右侧的图标,如下所示 -

  1. Enter the text in the cell as print('Hello, World!'). Change the cell type to Code.
    在单元格中输入文本 print('Hello, World!') 。将单元格类型更改为 Code 。

  1. Again, click the Run icon or press Ctrl + Enter on your keyboard to run your code.
    再次点击 Run 图标或在键盘上按 Ctrl + Enter 运行您的代码。
  2. Your final Jupyter notebook appears as shown below -
    您的最终 Jupyter 笔记本如下所示 -

This concludes this tutorial.
本教程到此结束。

For more details on creating Jupyter Notebook editor on IBM watsonx.ai, please refer to this link - Quick start: Analyze data in a Jupyter notebook.
关于在IBM watsonx.ai 上创建Jupyter Notebook 编辑器的更多详细信息,请参考此链接 - 快速入门:在 Jupyter 笔记本中分析数据。

Author(s) 作者

Geetika Pal