EME 210
Data Analytics for Energy Systems

(link is external) (link is external)

Importing Files: Option 3

PrintPrint

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)

Click here for a transcript.

Hi. In this video, I want to explain how to insert a text cell, and how to edit some of the text there. So, if we're going back to this example, we've already done some mathematical operations here. I might want to explain what I've done. And so, I can hover over, and I can add a text cell by clicking this button. And anything I type here will give me some formatted text. And I have different formatting options here. I can change this, designated as a heading, bold, italicize, etc. These are all operations that you may already be familiar with from something like Microsoft Word. And so, I can explain what I've done. I can say, here I've calculated z as x plus y.

On the right-hand side it gives me a preview of what I've typed. When I move away from this, it just gives me the result, so my explanatory text here. And I can always go back and edit this. Again, if I want to stylize it a bit and italicize some of these mathematical variables, I can do that. I can insert a hyperlink. Something that might be useful for some of the homework problems in this course would be to insert an image. So, if I click on, insert image, it gives me a dialog and I can navigate to anywhere. to upload an image here. This is just an example image. And it shows as a bunch of gobbledygook, not a whole lot, but if I again navigate away from the cell, let this scroll to the very top here. If I scroll back down, it does have just the image there. Okay?

I can always delete what I have by clicking this button here. I can add comments to it. I can also move cells around in the document by using these arrows. So, I can move this down below, here. But I don't really want to do that because this cell depends on x and y's, we've discussed before. And that's about it.

Credit: © Penn State is licensed under CC BY-NC-SA 4.0(link is external)

  Try It: Apply Your Coding Skills in Google Colab

  1. Click the Google Colab file used in the video is linked here(link is external).
  2. 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.
  3. 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