Working with External Data

Working with External Data

Python supports file handling and allows users to handle different files i.e., to read, write, create, delete and move files, along with many other file handling options.

Pandas features a number of functions for reading many different file formats or data sources as Dataframe. You can access each of the data sources with the prefix read_.

  • read_csv
  • read_table
  • read_excel
  • read_html
  • read_json
  • Etc

Uploading files from your local file system

To work with the external file within Colab Notebooks, we can upload the data from our local file into the Google Colab file directory or upload the data on Google drive and mount the drive on Colab notebook. we will look at both options here.

Upload files on Colab notebook

When you upload the file on google Colab directly, the file will be lost when the runtime is recycled. Recycling means the Notebooks will be disconnected from the virtual machines(VMs) when left idle for too long.

Uploading file to Colab files directory:

  1. Click on the files icon on the left pane of the Colab window.
  2. Click on upload on the file navigation pane.
  3. Select the file from your local file explorer.
  4. Great! The file is now added to your files on the Colab Notebook.


Working with Data from Google Drive

  1. Upload the data from your local file to Google drive if the data is not already on your Google drive.
  2. Click on the File icon on the left side of the Colab Note.
  3. Click on Mount Google drive. Click on connect to Google Drive to grant access to Google Drive.
  4. Click the link to generate the code for verification. After authentication, the drive will be mounted on the files. From there, you can access the files from the drive.
  5. Great! The Google Drive is now mounted on the Notebook.

You can also mount the Google drive using the code below:

Mark as completed