How to upload a .csv file to Google Colab ?
Step 1.
Create a Colab Notebook.
Go to below link and it will automatically ask you to create a notebook. Simply enter the name and hit enter.
Step 2.
Uploading the file.
First we need to upload the file(like csv, xlsx, etc) from our system to the Colab using the below code.
from google.colab import files
uploaded = files.upload()
As soon as you run the above code it will show you a “Browse” button as in below figure. Click on it and upload your file (in my case its california_house.csv
). Wait till the file is 100% uploaded. The file is now accessible through uploaded
object (as shown in above code)
So where does your csv file go? The file is uploaded to your Files section, which you can find by clicking on 3 bars to the top left of the web page as show in below figure. You can find all the uploaded files here.
Step 3.
Accessing the uploaded file.
To access our california_house.csv
file we use below code.
import pandas as pd
import iodf = pd.read_csv(io.BytesIO(uploaded['california_house.csv']))
df.head()
And the output looks as below:
The reason why we use BytesIO() is little complex and for more you can read about it here:
Thanks for reading.
Feedbacks are welcome :)
You can find me here.
brijeshgoyal0808@gmail.com