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 [1], which will allow you to move between Google's cloud-based memory space and your individual Google Colab file space.
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.