Importing “.csv” Files Using Jupyter Notebook

@lee-rowe
2 min readMay 30, 2021

--

This will be my second blog post describing how to import CSV (Comma separated values) files into your desired platform to work with. My first post discusses how to import data into Google Colaboratory, a link to it can be found here. In this post I will be explaining methods for working specifically with Jupyter Notebook.

Method 1…

Both of the methods that I will discuss require pandas to work successfully, you can use the cell found below to import it. You will also want to have the file or files that you’re trying to work with to be in an easy to locate file path.

import pandas as pd

After you have imported pandas you will want to acquire the file path of your CSV file. Instructions on how to do this can be found here for Windows, and then for Macs. Once you have the file path copied you will want to use the code cell below to read in your file, it is important you include the “r” at the start of your file path.

df = pd.read_csv(r"C:\Users\leerowe\Desktop\data_to_upload.csv")

Method 2…

This method is quite literally the same as the first, the only differences are that you don’t need to include the “r”. Once again to start, you will need pandas imported. After that you will still need to acquire your file path, after you have it copied and ready to paste, you will want to make sure to use double backslashes “ \\ ” as seen in the cell below.

import pandas as pddf = pd.read_csv("C:\\Users\\leerowe\\Desktop\\data_to_upload.csv")
Photo by Stone Wang on Unsplash

Hopefully one of these methods give you a helpful insight into your file importing process!

--

--

@lee-rowe
@lee-rowe

Written by @lee-rowe

Data Scientist/Engineer | Create Value | if data: data.science()

No responses yet