In order to read a file that you have uploaded on your Google Drive in Google Colab, you can make use of the drive module from the google.colab package.
Step 1: Mount Google Drive using drive module
The first step is to mount your drive in a Notebook code cell.
from google.colab import drive
drive.mount('/content/drive')
Once you execute this code you will see a message:

You will be asked to login to your Gmail account and authorize the access permissions to Colab.
Step 2: Copy path of your file
Next you can go to the file icon on the left sidebar in Google Drive and expand drive -> MyDrive and copy path of your file (csv, txt, xlsx or any other)
drive_csv_file_path = '/content/drive/MyDrive/data/data.csv'

Step 3: All good to use it in your Python Code!
Example:import csv
def read_from_csv_file(data_file):
with open(data_file, 'r') as file:
csv_reader = csv.reader(file)
for row in csv_reader:
print(row)
drive_csv_file_path = '/content/drive/MyDrive/data/data.csv'
read_from_csv_file(drive_csv_file_path)
-
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to Google,
- How to get nest aware on iPhone
- Fetch as Google Crawl Error or Redirected Status
- How to upload and read csv file in Google Colab
- Google Celebrates Rosa Bonheur 200th birthday with a Google Doodle
- Fix: Cannot contact reCAPTCHA. Check your connection and try again.
- Google Webmaster : An error has occurred. Please try again later
- [Fix] reCAPTCHA not working in Web Browser
- Fetch More then 10 Links Per Page in Google Search Result
- How to do a Reverse Image Search Using Google Tools
- Turning Off Chat in Gmail
- How to Mount Google Drive in Colab Notebook
- How to Hum a Song to Google to find it out! [Android and iPhone]
- Google Colab: How to read file from Google Drive
- How to Undo-Revert Sent Email in Google Gmail
- Google Local Guide Program and Perks of Contributing to Google Maps
- How to install Google Chrome using Mac Terminal
- How to Toggle Light/Dark Mode in Google Colab
- How to Upload a File to Google Colab (txt, csv, json, xml, xlsx)
- How to insert image into Google Sheets cell
- Installing Google Cloud macOS SDK
- 86 Gmail keyboard shortcuts that you may find Advantageous
- Google Search Console: HTTPS is invalid and might prevent it from being indexed
- Resolving DNS_PROBE_FINISHED_NXDOMAIN Google Chrome Error
- Enable Dark Mode in Google Search
- Page actions are temporarily disabled [Google Search Console Page Crawling]
More Posts:
- SharePoint PowerShell PnP - How to get list item by Item ID using GetItemById, Get-PnPListItem - SharePoint
- How to open SharePoint Online Modern SPFX links in new tab - SharePoint
- How to remove disable google search blue triangle - Google
- [Fix] MySQL ERROR 1054 (42S22): Unknown Column - MySQL
- What Java version is used for Minecraft 1.18 - Java
- How to use a different Python version with virtualenv - Python
- Microsoft Teams: Delay in sending and receiving messages - TM495986 - Teams
- Notepad++ Ghost typing Examples - NotepadPlusPlus