
Importing Files: Option 3
Read It: Importing Files
The final demonstration for reading in CSV files is the "Upload Files" method. Similar to the "Drag and Drop" method, this method also requires your CSV file be stored somewhere on your local computer. However, instead of manually moving the file into the Google Colab space, as previously shown, we are going to create a special "upload" button which will be able to connect to your local computer. This method does involve a new library, namely the IO library(link is external), which will allow you to move between Google's cloud-based memory space and your individual Google Colab file space.
Watch It: Video - Importing Files: Option 3 (5:47 minutes)
Try It: Apply Your Coding Skills in Google Colab
- Click the Google Colab file used in the video is linked here(link is external).
- Go to the Colab file and click "File" then "Save a copy in Drive", this will create a new Colab file that you can edit in your own Google Drive account.
- Once you have it saved in your Drive, try to implement the following code to import a file of your choice by mounting your Google Drive:
Note that you must be logged into your PSU Google Workspace in order to access the file.
1 2 3 4 5 6 7 8 9 | from google.colab import files uploaded = files.upload() import io import pandas as pd df = pd.read_csv(io.BytesIO(uploaded[ 'yourfilename.csv' ])) |
Once you have implemented this code on your own, come back to this page to test your knowledge.
Assess It: Check Your Knowledge
Knowledge Check
FAQ