Open In App

How to upload a dataset in Jupyter Notebook?

Last Updated : 21 Aug, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Jupyter Notebook is a web-based powerful IDE tool that helps with data analysis, visualization and narrative multi-media. Uploading a dataset is a very common task when working in the Jupyter Notebook. It is widely used by data analysts, data scientists, researchers and other developers to perform data analysis, machine learning tasks and other scientific computations.

Different ways to use Jupyter Notebook

There are many different ways to use Jupyter Notebook. Let’s see some of the ways:

  • It provides a variety of techniques to improve coding and data science experiences as it acts as an interactive workspace for writing and running codes, making it perfect for testing and prototyping.
  • It supports a number of programming languages and it makes it easier to create data-driven presentations.
  • The markdown support enables users to create accessible documents by combining codes, visual representations and descriptive text.

Installing the Jupyter Notebook

Installing Jupyter is simple and improves coding and data analysis skills. Make sure Python is installed on your local machine before you start. Then use the following command to install Jupyter:

pip install jupyter

We can also use the Anaconda platform which includes Jupyter Notebook, a further option. Jupyter Notebook is also supported through extensions in well-known code editors such as VS code. whatever method you choose, these installation options provide accessibility, allowing a user to use its robust features with ease. You can install Jupyter Notebook can be used in Windows, Linux, MacOS and all the OS where Python can be installed.

How to Launch Jupyter Notebook

Jupyter Notebook is simple and its launch method makes interactive scripting and data processing possible. After we install Jupyter using pip or Anaconda, start by opening your terminal or command prompt and navigating the required directory. After typing “Jupyter notebook” press enter, which will initiate a local server, and default web browser will open up, displaying its interface where you can create new notebooks, open the existing ones, etc. Type the following command in cmd or command prompt:

jupyter notebook

Useful Features of Jupyter Notebook

One of the interesting facts is that , it conceals features that improve the data science experience.

  • Magic Commands (% and %%) makes it possible to take shortcuts, such as timing the execution of code or running it in many different languages.
  • Jupyter notebook provides a lots keyboard shortcut, which can save a lots of time, We can check the keyboard shortcut by pressing the “H” from keyboard or Moving to Help to keyboard Shortcut
  • We can also define our own shortcuts through the Help menu by selecting Edit Keyboard Shortcuts.
  • We can install the different packages directly using pip command in jupyter notebook

Upload the dataset in Jupyter Notebook

Now , we will see how to upload a dataset in a Jupyter Notebook. Here we are going to see four different methods on how to upload a dataset in a Jupyter Notebook. The following methods are:

1. Using Upload Option

Another way to upload dataset is , Jupyter Notebook displays an upload button on the dashboard. This button will allow you to select and upload your dataset in the notebook. One the dataset is uploaded , you can access the file.

Jupyter Notebook -Geeksforgeeks

Read the dataset using pandas.read_csv

To read the dataset in a Jupyter Notebook , we need to follow some steps:-

  • Open the notebook and import the library. Using pd.read_csv command we will read the file.

Syntax : df = pd.read_csv(‘dataset.csv’)

  • Use df.head() or df.tail() to display the rows from starting or from the bottom (by default the rows displayed are 5).

Syntax: df.head()

Syntax: df.tail()

For example,

Python3




df = pd.read_csv('/content/drive/MyDrive/Train_Dataset.csv')
df.head()


Output:

OUtput-Jupyter Notebook

Output

2. Using Absolute Filepath

Another way to read the dataset in the notebook is by using an Absolute file path. You can provide the full path of the dataset if the dataset is located in different location or directory. For example,

Syntax: df = pd.read_csv(‘path/to/the/dataset.csv’)

3. Read Non-CSV formats

You can also use different libraries for Non – CSV formats like Excel, JSON , etc.

Syntax: df = pd.read_excel(‘file_path’)

Syntax: df = pd.read_json(‘file_path’)

These are some of the ways that can be used to upload a dataset in a Jupyter Notebook. Keep in mind , the method you choose will always depend on the type of the dataset and the location of the dataset. As a result, the capacity to upload datasets within jupyter notebook is a fundamental capability that enables data analysts and researchers to engage in through analysis. Being a user friendly interface , its easier for a user to work on notebook.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads