Google Colab is the best Notebook for Python developers and students to work online without doing any setup locally and sharing your notebooks with friends and colleges.
If you are new to working with Colab and wondering "how to upload a .csv file that you want to work with?" Well all you need to do is keep make use of the files module from the google.colab package.
Just create a code cell in a Colab and copy and execute the below code.
from google.colab import files
uploaded = files.upload()
Once you execute the cell, you will see a Choose Files option, click on it will let you select and upload files that you can use with Colab.
One the file(s) uploaded you will see logs such as,
data.csv(text/csv) - 31 bytes, last modified: n/a - 100% done
Saving data.csv to data.csv
You can read the file by simply using the filename without any path 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)
csv_file = 'data.csv'
read_from_csv_file(csv_file)
Output:
Do add a comment if you found this useful, or if you have any queries. I am happy to help!
Facing issues? Have Questions? Post them here! I am happy to answer!
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org
- How to upload and read csv file in Google Colab
- Resolving DNS_PROBE_FINISHED_NXDOMAIN Google Chrome Error
- Fix - ModuleNotFoundError: No module named google.colab
- Fetch More then 10 Links Per Page in Google Search Result
- Find Nearest Gas Station using Google Map App on your Phone
- How to get nest aware on iPhone
- Fix: Cannot contact reCAPTCHA. Check your connection and try again.
- Enable Dark Mode in Google Search
- How to Mount Google Drive in Colab Notebook
- [Fix] reCAPTCHA not working in Web Browser
- Google Celebrates Rosa Bonheur 200th birthday with a Google Doodle
- How to Subscribe to Google Nest Aware on iPhone
- Google Local Guide Program and Perks of Contributing to Google Maps
- How to remove disable google search blue triangle
- 86 Gmail keyboard shortcuts that you may find Advantageous
- How to insert image into Google Sheets cell
- How to Open a New Notebook in Google Colab
- Google Colab: How to read file from Google Drive
- How to Access Local Files in Google Colab
- Installing Google Cloud macOS SDK
- Turning Off Chat in Gmail
- How to do a Reverse Image Search Using Google Tools
- Google Search Console: HTTPS is invalid and might prevent it from being indexed
- How to Show Line Numbers in Google Colab Cells
- Fetch as Google Crawl Error or Redirected Status
- How to get query string in JavaScript HTML location.search - JavaScript
- PowerShell: The term Connect-AzureAD is not recognized as the name of a cmdlet - Powershell
- How to Run PowerShell Script as a Windows Scheduler Task - Powershell
- Android Eclipse This version of the rendering library is more recent than your version of ADT plug-in. Please update ADT plug-in - Android
- How to determine Gradle Version in Android Studio - Android-Studio
- Visual Studio Code available for Apple Mac ARM64 build for native M1 processor support - Microsoft
- How to restore closed file in Notepad++ - NotepadPlusPlus
- Unable to connect to the Internet : Google Chrome - Chrome