> For the complete documentation index, see [llms.txt](https://docs.bdb.ai/data-science-lab-4/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bdb.ai/data-science-lab-4/repo-sync-project/tabs-for-a-data-science-lab-project/tabs-for-pyspark-environment/notebook/notebook-page/cells-for-.ipynb-files/using-a-code-cell.md).

# Using a Code Cell

Write & Run Code in a Notebook.

You can write and execute code using the Notebook interface. This section covers the steps to write and run a sample code in the Code cell of the Data Science Notebook.

{% hint style="success" %}
*Check out the given walk-through on how to use a Code Cell under a .ipynb file.*
{% endhint %}

{% embed url="<https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1QeOywZjV1cHo55cMW8u%2Fuploads%2FbdhZbVbhSd94FisKAID0%2FRunning%20Code%20in%20the%20PySpark%20ENV%20RSP.mp4?alt=media&token=508b50bd-250c-4b5a-9fba-218d542cd2c2>" %}
***Running a Code cell with a code***
{% endembed %}

{% hint style="info" %}
*<mark style="color:green;">Please Note:</mark> A Code cell gets added by default while creating a new .ipynb file. The above-given video displays inserting a new code cell to introduce the user other way to insert a code cell.*
{% endhint %}

## Running Code inside a Code Cell

* Create a new Notebook and open it.
* A cell to write and execute code opens under the selected .ipynb file by default.

<figure><img src="https://4082649235-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1QeOywZjV1cHo55cMW8u%2Fuploads%2FnxdaOu7yZ5OOrNpcVKtN%2Fimage.png?alt=media&amp;token=b56ea3e4-5191-432b-abe1-5454fbdd3177" alt=""><figcaption><p><em><strong>Accessing a Code cell within the Notebook interface</strong></em></p></figcaption></figure>

* Load a dataset into the given .ipynb file.
* Click the ***Run cell*** icon to run the code.

<figure><img src="https://4082649235-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1QeOywZjV1cHo55cMW8u%2Fuploads%2FIw4kk0EGlmUnNErnYfrU%2Fimage.png?alt=media&amp;token=96ff9e46-3e4d-4164-b33f-aff64770383c" alt=""><figcaption><p><em><strong>Running a code cell with a relevant code</strong></em></p></figcaption></figure>

{% hint style="info" %}
*<mark style="color:green;">Please Note:</mark> The Code cells also get code from the selected Notebook operations by using the right-side panel and selecting a specific option. E.g., The user can use the Datasets tab to get an added data set to the code cell.*
{% endhint %}

* The ***Run*** cell button gets changed into the ***Interrupt cell*** icon while running the code.

<figure><img src="https://4082649235-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1QeOywZjV1cHo55cMW8u%2Fuploads%2FT3IFnUVa2n5HLTWxOdsi%2Fimage.png?alt=media&amp;token=c92047b6-ed97-4717-a326-a5aa72b85db1" alt=""><figcaption><p><em><strong>A</strong></em> <em><strong>Code Cell while Running action is going on</strong></em></p></figcaption></figure>

* Once the code has run successfully a checkmark appears below the ***Run cell*** icon.
* Add new code cell gets added, insert the Show function in that cell.
* Run the code cell.
* The dataset preview appears below.

<figure><img src="https://4082649235-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1QeOywZjV1cHo55cMW8u%2Fuploads%2FRvCqzZoI0eOAswuKa7sS%2Fimage.png?alt=media&amp;token=0b9af47c-21e9-4007-985b-0c13421baf24" alt=""><figcaption><p><em><strong>Displaying the Data Preview based on the  inserted dataset.</strong></em></p></figcaption></figure>

* Another code cell gets added below (as shown in the following image).
* Click the ***Save*** icon provided for the Notebook.

<figure><img src="https://4082649235-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1QeOywZjV1cHo55cMW8u%2Fuploads%2FZwMN8N3izrdfudZeWIHj%2Fimage.png?alt=media&amp;token=ecba8bc3-70b6-4db7-8789-06bf618183c8" alt=""><figcaption></figcaption></figure>

* A notification message appears to indicate the completion of the action.
* The Notebook status gets changed as saved and the new updates get saved in it.

<figure><img src="https://4082649235-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1QeOywZjV1cHo55cMW8u%2Fuploads%2FCh2uQm43QxtFLE2kE9S0%2Fimage.png?alt=media&amp;token=bb6ebd88-ddcb-4ba9-af52-9fdc8c859287" alt=""><figcaption></figcaption></figure>

## ​Various Options provided to a Code Cell

By clicking on an inserted Code cell, some code related options get displayed as shown in the below-given image:

<table><thead><tr><th width="93">Sl. No.</th><th width="92">Icon </th><th width="173">Name</th><th>Action</th></tr></thead><tbody><tr><td>1</td><td><img src="https://content.gitbook.com/content/1QeOywZjV1cHo55cMW8u/blobs/vyoJIezJDdvUkL0i3mrx/image.png" alt=""></td><td>Move the cell up</td><td>Moves the cell upwards</td></tr><tr><td>2</td><td><img src="https://content.gitbook.com/content/1QeOywZjV1cHo55cMW8u/blobs/SMJW4moToNpEIDinCv2h/image.png" alt=""></td><td>Move the cell down</td><td>Moves the cell downwards</td></tr><tr><td>3</td><td><img src="https://4082649235-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1QeOywZjV1cHo55cMW8u%2Fuploads%2F3Sb8cFc1xvHS3K9c39Ep%2Fimage.png?alt=media&amp;token=c16c04ca-4d1a-4fad-af38-4af21b6b1c79" alt="" data-size="original"></td><td>Delete Cell</td><td>Deletes the code cell.</td></tr></tbody></table>

{% hint style="info" %}
*<mark style="color:green;">Please Note:</mark>*

* *The **+Code** and **+Markdown** options provided at the bottom of a cell inserts a new cell after the given code/ Markdown cell.*    &#x20;
* *Refer the* [***Data Science Lab Quick Start Flow***](https://docs.bdb.ai/data-science-lab-4/data-science-lab-quick-start-flow) *page to get an overview of the **Data Science Lab** module in nutshell.*&#x20;
  {% endhint %}
