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!
- 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
- What is Bootstrap Jumbotron and how to use it - Bootstrap
- Java: Fix SAXParseException: :1:1: Content is not allowed in prolog. - Java
- How to know if you have blocked your friend Number on Android Phone - Android
- Where is adb command-line tool located? - Android
- Java Check Leap Year - Programs with Code Examples - Java
- List of Useful Mac Terminal Keyboard Shortcuts - MacOS
- Fix: Deprecated Gradle features were used in this build, making it incompatible with Gradle - Gradle
- Date to Date Difference Calculator - Tools