Open In App

How To Load Csv File In Jupyter Notebook?

Last Updated : 26 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Loading a CSV file in Jupyter Notebook is an important step for data analysis and manipulation. Pandas library provides an easy way to read CSV files and work with tabular data in Python. Let's see how we can load csv file.

Step 1: Install Pandas Library

Make sure we have installed Pandas Library, if not then install it using the following command:

!pip install pandas

Step2: Import Pandas

Firstly we need to import Pandas library.

Python
import pandas as pd

Step3: Load the CSV File - Standard Pandas Operation (pd.read_csv)

  • Use the pd.read_csv() function to load the CSV file. We need to provide the file path as an argument.
  • If the file is in the same directory as our notebook we can just provide the filename. We are using zomato dataset which can be downloaded from here.
Python
df = pd.read_csv('zomato.csv')

Step4: Check the Data

After loading the CSV we can see first few rows of the DataFrame to ensure it loaded correctly:

Python
df.head()

Output:

output1
Dataset Rows

Handling Unicode Error In Jupyter Notebook

When working with CSV files we might encounter a UnicodeDecodeError when file contains characters outside the standard ASCII character set. This issue occurs when the default encoding used by Python's read_csv() function typically UTF-8 may not match the encoding of the CSV file.

Unicode error encountered while loading a CSV file is given below. We can see error message indicating the UnicodeError and line of code where the error occurred.

error
ERROR

Handling Unicode Error

To handle this error one common approach is to specify the correct encoding parameter when using the read_csv function. The encoding parameter we will use here is encoding='latin-1'.

Other common encodings include:

  • 'utf-8'
  • 'utf-16'
  • 'cp1252'
Python
import pandas as pd
df= pd.read_csv('/content/zomato.csv',encoding='latin-1')
df.head()

Output:

output1
OUTPUT

With these simple steps we can start exploring and analyzing data from CSV files in Jupyter Notebook.


Next Article
Practice Tags :

Similar Reads