Google colab is one of the goto tool for anyone working in python for data science projects. I often test my code in Google colab with sometime using their GPU power for larger datasets. However, the major issue and most of the time the first step is to upload dataset to Google colab workspace so that we can access it. After that we start with the work of cleaning and making the dataset into a format which can be utilized by machine learning algorithms for prediction activities.
This blog provides an simple yet effective method which I am using from way long to import my csv files into Google colab. You can import excel as well as other formats also using the same technique.
Import the required packages
The packages we will use are pandas, files and io.
import pandas as pd from google.colab import files import io
File in our storage need to be uploaded in colab workspace
Following code will be used
from google.colab import files uploaded = files.upload()
An option similar to following will be activated using which you can select file which you wish to import.
Then select the file from the desired folder.
Store the uploaded file as a dataframe
import io df = pd.read_csv(io.BytesIO(uploaded['iris.csv']))
As the file is stored in the from of dataframe, several activities and modifications can be done using functions available in Pandas library.
Hopefully, this method will solve your problem of importing data into google colab.
Dr. Rajinder Sandhu