Intro to Data Visualization
  • Introduction
  • Getting started
    • Introduction to Pandas
    • Accessing Files on Colab
    • Reviewing Data
      • Understanding type(data) in Pandas
    • Data Types
      • Categorical Data
      • Numeric Data
      • Temporal Data
      • Geographic Data
    • How to Check Data Type
    • Slicing and Subsetting DataFrames
    • Aggregating Data
  • Visualization Types
    • Exploratory Process
    • Explanatory Process
  • data exploration
    • Exploration Overview
    • Exploration with Plotly
      • Exploring Distributions
      • Exploring Relationships
      • Exploring with Regression Plots
      • Exploring Correlations
      • Exploring Categories
      • Exploring Time Series
      • Exploring Stocks with Candlestick
      • Exploring with Facets
      • Exploring with Subplots
    • Exploring with AI
  • Data Explanation
    • Data Explanation with Plotly
      • Using Text
      • Using Annotations
      • Using Color
      • Using Shape
      • Accessibility
      • Using Animations
    • Use Cases
  • Exercises and examples
    • Stock Market
      • Loading Yahoo! Finance Data
      • Use Cases for YF
      • Exploring YF Data
      • Understanding Boeing Data Over Time
      • Polishing the visualization
      • Analyzing with AI
      • Comparisons
    • The Gapminder Dataset
      • Loading the Gapminder Data
      • Use Cases
      • Exploring the Data
      • Exporting a Static Image
Powered by GitBook
On this page
  • 1. Uploading a Single File
  • 2. Mounting a Google Drive Folder
  • Working Directory
  • Changing the Working Directory
  • Additional Reading
  1. Getting started

Accessing Files on Colab

PreviousIntroduction to PandasNextReviewing Data

Last updated 3 months ago

There are two main methods to access data for Google Colab. First, you can upload a single file and work with it. Second, you can mount your Google Drive, and then you could access files similar to how you access files on your computer. This is best when you have multiple files.

1. Uploading a Single File

Another option is to directly upload the files from your local machine into Google Colab. To do this, we import the files library from google.colab and use the upload function.

from google.colab import files
uploaded = files.upload()

After you run the lines above, you should see the prompt.

Navigate to the file to choose that file to upload. Save all your course files to a single folder to make it easier to access later.

2. Mounting a Google Drive Folder

Second, let's connect your Google Drive to the Google Colab so you can upload files from your Google Drive folder to use. To do this, we import a library from google.colab and use the drive.mount function.

from google.colab import drive
drive.mount('/content/drive')

When you mount your Google Drive by running the lines above, you should receive a prompt to click on a link. Click the link and follow the instructions to allow Google Colab to access your Google drive. Make sure that it's the email address linked to the Google Drive that you plan to use for Colab.

Once you click the link and give Google Colab those permissions, you'll receive an authorization code. Input that authorization code into the prompt space.

Working Directory

The working directory is where the code will read and write files from. Check to see where your current working directory is using the !pwd command. The "!" indicates that this is a command line function, and "pwd" returns the current working directory.

!pwd

Changing the Working Directory

To change the working directory, you'll need to use the os package and the change directory function.

import os
os.chdir('/content/drive/My Drive/Colab Notebooks/data')

Additional Reading

For more information about syntax, review the

Python Data Science Handbook, chapter 1 section 5.
Uploading a file
Mounting a Google Drive in Google Colab