Developing & Running Code in Notebooks

This section provides an overview of how to write and execute code within notebooks.

In Data Science Lab (DSLab), users can write and execute code in notebooks for data science projects. Notebooks are composed of code cells that can be run to process data, train models, and generate results. This guide explains how to create, run, and manage code cells within a notebook, as well as how to use various options available for code cells.

Writing Code & Running a Code Cell within Notebook

Steps to Write and Run Code in a Notebook

Navigation path: Data Science Lab > Workspace > Repo Folder > Notebook

1

Open the Notebook

  • Navigate to the Workspace tab for a data science project.

  • Select a notebook from the Repo folder.

  • Open the selected notebook by clicking on it.

2

Add a Code Cell

  • To insert the first code cell, click the Add pre-cell icon.

    • A new notebook automatically includes a default code cell upon creation.

  • A new code cell will be added to the notebook.

3

Write Code in the Cell

  • Enter the code in the available Code cell.

  • Use the Python language to build your code.

  • Example:

import pandas as pd
df = pd.read_csv('data.csv')
df.head()
4

Run the Code Cell

  • Click the Run cell icon to execute the code.

  • The Run cell button will change into an Interrupt cell icon while the code is running.

  • Once the code has run successfully, a checkmark will appear next to the Run cell icon.

  • The output of the code will be displayed below the cell.

5

Additional Code Cell

  • After running the code, another code cell will automatically be added below the previous cell.

6

Save the Notebook

  • Click the Save icon to save the notebook and preserve all the changes.

  • The user can keep the Auto Save option enabled to auto-save the code modification within the notebook.

Clearing the Output of a Code Cell

Clear Output:

  • If you need to clear the output of a code cell, click on the Clear Output icon provided next to the code cell output.

  • This will remove the output displayed below the cell, keeping the code intact.

Running a Code Cell

Options for a Code Cell

By clicking on a code cell, the following options are available for managing and modifying the cell:

Sl. No.

Icon

Name

Action

1

Code Assist

Adds an AI powered assist

cell below in the notebook.

2

Move the cell up

Moves the code cell upwards in the notebook.

3

Move the cell down

Moves the code cell downwards in the notebook.

4

Delete Cell

Deletes the selected code cell from the notebook.

5

More Actions

Opens additional actions, including: Cut Cell, Copy Cell, Paste Cell, Transform, Save Model, Predict, and Save Artifact..

Note: The +Code and +Markdown options provided at the bottom of each cell allow users to insert a new code or markdown cell after the current one.

Important Notes

  • Kernel: Before running any notebook cell, ensure that the Kernel is up and running.

    • If the user attempts to run a notebook cell before the Kernel is started/restarted, a warning message will be displayed.

  • Code Execution: Cells should be executed in sequence to maintain the flow of data processing and model training.