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()
![Upload a file to Google Colab Upload a file to Google Colab](https://code2care.org/q/upload-and-read-csv-file-in-google-colab/images/Upload a file to Google Colab.jpg)
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
- [Fix] Notepad Error: Windows cannot access the specified Device or Path - Windows-11
- How to install Microsoft OneDrive on Mac Sonoma 14 - MacOS
- Java 8 Predicate default and() function Example - Java
- How to turn off Dark theme in Excel for Mac - Microsoft
- Adding Sub Headings to Bootstrap Header tags - Html
- Change Terminal Cursor Type in Mac (MacOS Shell) - MacOS
- Base64 Encoding Decoding in Python Programming - Python
- Docker - Running in Resource Saver mode - Docker