Unable to read csv file in Google Colab

Solution for Unable to read csv file in Google Colab
is Given Below:

I imported these libraries and trying to read a csv file on my desktop

import pandas as pd
import numpy as np

df = pd.read_csv('/Users/yoshithKotla/Desktop/canal/verymimi_M.csv')

But I get an error saying

FileNotFoundError: [Errno 2] No such file or directory: '/Users/yoshithKotla/Desktop/canal/verymimi_M.csv'

The path of the file is correct and it is present on my desktop.

You cannot read the local files present on your computer directly into the google colab environment.

To upload from your local drive, start with the following code:

from google.colab import files
uploaded = files.upload()

It will prompt you to select a file. Click on “Choose Files” then select and upload the file. Wait for the file to be 100% uploaded. You should see the name of the file once Colab has uploaded it.

Finally, type in the following code to import it into a dataframe (make sure the filename matches the name of the uploaded file).

import iodf2 = pd.read_csv(io.BytesIO(uploaded['Filename.csv']))# Dataset is now stored in a Pandas Dataframe

Reference: https://towardsdatascience.com/3-ways-to-load-csv-files-into-colab-7c14fcbdcb92

Google Colab offers its own storage space and you cannot access your local file system unless you connect to a local runtime. As fully explained by Colab itself, there are multiple ways to work around external data sources.

Probably the easiest one (especially for small files) is to directly upload your file to your notebook’s storage:

from google.colab import files
import pandas as pd

df = pd.read_csv('verymimi_M.csv')

Sometimes you might already have the file on your Google Drive. In that case, you could simply mount the drive:

from google.colab import drive
import pandas as pd

path="/content/gdrive/My Drive/" # the absolute path to your file
df = pd.read_csv(path + 'verymimi_M.csv')

Or sometimes you’d like to downlead a file from a host to your Colab storage without using your local host as mediary. In this case, wget could download any file from URL to Colab (just like in Linux — well, Colab itself runs on Linux-based hosted machine). All you need to do is:

!wget https://www.example.com/verymimi_M.csv # file URL

And then

import pandas as pd

df = pd.read_csv('verymimi_M.csv')

There are some other methods as well. You could download data from Kaggle to Google Colab, from Google Spreadsheets and so on. I hope that covers almost everything.