fbpx

4 ways to load data in Jupyter notebook and visual studio code.

4 ways to load data in Jupyter notebook and visual studio code.

Method 1: Load data from CSV file in Jupyter Notebook and Visual Studio Code.

How to load a dataset from a csv file from your local computer to Jupyter Notebook or Visual Studio for data analysis using python and pandas.

There are 2 primary ways to accomplish this

Option 1: Load CSV File from local computer in jupyter notebook and visual studio code using python and pandas

Put the dataset in the same folder you are working with and load the data from there

Step 1: Copy the dataset into the same folder containing your notebook.

Step 2: Import pandas

Step 3: Use this line of code to load the data located in the same folder you are currently working in.

Step 4: Verify that the data is loaded correctly by using data.head().

Option 2: Load CSV File from local computer in jupyter notebook and visual studio code with python and pandas using local file path

The first step is to copy the file path/location of the dataset csv file you want to use for data analysis

How you do this on mac is a little bit different, but all the same concepts apply. This is how you do it in windows.

Step 1: Import pandas in your notebook.

Step 2: Locate the csv file you are trying to import

Step 3: Select the file –> Click on Home –> Click on Copy file path.

Step 4: Use the file path to read the CSV file. If you put in the raw file path, your notebook or visual studio code might throw an error. So, make sure to put “r” before the file path to convert the file path you copied into a regular string. This is how you do it.

Step 5: Verify that the data is loaded correctly by using data2.head().

Method 2: Load dataset from a URL in Jupyter Notebook and Visual Studio Code

How to load a dataset from a url to Jupyter Notebook or Visual Studio for data analysis using python and pandas.

If you want to convert your CSV file into a URL link that you can use for data analysis, then read this blog post.

Loading data from a URL is quite simple.

STEP 1: Get the URL that contains the data

STEP 2: Import Pandas as pd.

There are 2 ways you can execute reading data from a URL.

Option 1: You could do…

URL = "url link"
Data = pandas.read_csv(URL) then
Data.head() to verify it is loaded correctly

OR…

Option 2: you could do…

Data = pandas.read_csv("url link") then
Data.head() to verify it is loaded correctly

Either method works perfectly fine and there is no difference between them. How you choose the load the CSV file is a matter of personal preference.

Method 3: How to Unzip and Extract ZIP file in Jupyter Notebook and Visual Studio Code

How to load a dataset from a ZIP file to Jupyter Notebook or Visual Studio for data analysis using python and pandas.

To load data from a zip file in jupyter notebook or visual studio code, you have to do something a little extra. There are 2 options to load a zip file in jupyter notebook.

Option 1: How to Unzip and Extract ZIPPED Files in mac and windows

Unzip and extract the zipped files on your local computer, then follow METHOD 1 above. Or make the CSV file available online and then use the URL that contains the data to access the dataset and follow METHOD 2 above.

Option 2: How to use Wget to Unzip and Extract ZIP Files inside Jupyter Notebook and Visual Studio Code

Unzip and extract the zipped files inside jupyter notebook using code and this is how you do it.

Step 1: Install WGET using PiP or Anaconda

Step 2: Import Wget

Step 3: Get the data from the URL containing the zip file using wget inside jupyter notebook.

Step 4: After using wget to download the zipped file, you should see the zipped file in the folder you are working with.

Step 5: To unzip a zipped file inside jupyter notebook and visual studio code. You import zipfile and use the following lines of code to unzip the zipped csv file.

Step 6: After unzipping the zipped file, you should see the csv files contained in the zipped file in the location folder that you indicated.

Step 7: Load the CSV file using “loans = pandas.read_csv(‘File name’)”.

Step 8: Verify that the data is loaded correctly by using loans.head() after you have loaded the csv file using pandas read_csv.

When you have a dataset that is stored in a TAR file type instead of a ZIP file, you can still unlock it and use the CSV file inside it.

Method 4: How to Unzip and Extract TAR.GZ file in Jupyter Notebook and Visual Studio Code

How to load a dataset from a TAR file in Jupyter Notebook or Visual Studio Code for data analysis using python and pandas

There are 2 options to unlock a tar file type.

Option 1: How to Unzip and Extract .TAR Files in mac and windows

Unzip and extract the zipped files on your local computer, then follow METHOD 1 above

Or make the CSV file available online and then use the URL that contains the data to access the dataset and follow METHOD 2 above. Read this blog to learn how to create a url for your csv file dataset.

Most computers can’t unlock tar file naturally, so this is how to unzip tar files locally.

In windows, this is how you unzip tar file.

Step 1: Download this 7 zip software

Step 2: Right click on the zip file and choose unzip with 7-ZIP

In Mac, this is how you unzip tar file.

Step 1: Follow this detailed instruction by wikihow to learn different ways to unzip rar file in Mac computers.

Option 2: How to use Wget to Unzip and Extract .TAR Files inside Jupyter Notebook and Visual Studio Code

You Can Unzip and extract the tar files inside Jupyter notebook and visual studio code using a few lines of code and this is how you do it.

Step 1: Import Wget

Step 2: Get the data from the URL containing the tar file using wget inside jupyter notebook.

Step 3: After using wget to download the tar file, you should see the tar file in the folder you are working with.

Step 4: To unzip a tar file inside jupyter notebook and visual studio code, you import tar file and use the following lines of code to open the tar file.

Step 5: After extracting the tar file, you should see the folder containing the csv files contained in the location folder that you indicated.

Step 6: Change into the directory that contains the csv files.

Step 7: Load one of the csv files to verify that everything is working properly using “aisle = pandas.read_csv(‘File name’)”.

Step 8: Verify that the data is loaded correctly by using aisle.head() after you have loaded the csv file using pandas read_csv function.

Leave a Comment

Scroll to Top