i. Uploading file through Files explorer
You lot tin can use the upload option at the peak of the Files explorer to upload whatsoever file(s) from your local car to Google Colab.
Here is what you need to practice:
Footstep 1: Click the Files icon to open the "Files explorer" pane
Step two: Click the upload icon and select the file(s) yous wish to upload from the "File Upload" dialog window.
Stride iii: One time the upload is complete, you can read the file every bit you would normally. For instance, pd.read_csv('Salary_Data.csv')
ii. Uploading file using Colab files module
Instead of clicking the GUI, you lot can also use Python code to upload files. You can import files module from google.colab. And then call upload() to launch a "File Upload" dialog and select the file(s) you wish to upload.
from google.colab import files
uploaded = files.upload()
In one case the upload is complete, your file(s) should appear in "Files explorer" and you can read the file every bit y'all would normally.
3. Reading file from Github
Ane of the easiest ways to read data is through Github. Click on the dataset in the Github repository, then click the "Raw" push.
Copy the raw data link and pass it to the role that can accept a URL. For instance, laissez passer a raw CSV URL to Pandas read_csv():
import pandas as pd df = pd.read_csv('https://raw.githubusercontent.com/BindiChen/machine-learning/chief/data-analysis/001-pandad-pipe-role/data/train.csv')
iv. Cloning a Github repository
Y'all tin can likewise clone a Github repository into your Colab environment in the aforementioned way equally you lot would in your local machine, using git clone.
!git clone https://github.com/BindiChen/car-learning.git Once the repository is cloned, you should be able to run into its contents in "Files explorer" and you can but read the file as you would ordinarily.
v. Downloading files from the web using Linux wget command
Since Google Colab lets you practice everything which you tin in a locally hosted Jupyter Notebook, you lot tin besides use Linux shell command similar ls, dir, pwd, cd etc using !.
Among those available Linux commands, the wget allows you to download files using HTTP, HTTPS, and FTP protocols.
In its simplest form, when used without any selection, wget will download the resource specified in the URL to the current directory, for instance:
Rename file
Sometimes, you lot may desire to save the downloaded file under a different name. To do that, but pass the -O choice followed past the new name:
!wget https://case.com/cats_and_dogs_filtered.nothing \
-O new_cats_and_dogs_filtered.aught Save file to a specific location
Past default, wget will save files in the current working directory. To salve the file to a specific location, use the -P option:
!wget https://example.com/cats_and_dogs_filtered.nada \
-P /tmp/ Invalid HTTPS SSL certificate
If yous want to download a file over HTTPS from a host that has an invalid SSL certificate, you can pass the --no-check-document selection:
!wget https://example.com/cats_and_dogs_filtered.aught \
--no-bank check-document Multiple files at once
If you want to download multiple files at once, apply the -i selection followed by the path to a file containing a listing of the URLs to be downloaded. Each URL needs to be on a dissever line.
!wget -i dataset-urls.txt The following is an instance shows dataset-urls.txt:
http://example-1.com/dataset.aught
https://example-2.com/train.csv
http://example-three.com/test.csv 6. Accessing Google Drive by mounting it locally
You lot tin use the drive module from google.colab to mount your Google Drive to Colab.
from google.colab import bulldoze drive.mountain('/content/drive')
Executing the above statement, yous will be provided an hallmark link and a text box to enter your dominance lawmaking.
Click the hallmark link and follow the steps to generate your potency code. Re-create the code displayed and paste it into the text box as shown above. Once it is mounted, you should get a message like:
Mounted at /content/drive After that, you should be able to explore the contents via "Files explorer" and read the data as you would normally.
Finally, to unmount your Google Drive:
drive.flush_and_unmount() 7. Loading Kaggle datasets
It is possible to download whatever dataset seamlessly from Kaggle into your Google Colab. Here is what you demand to do:
Pace 1: Download your Kaggle API Token: Get to Account and curlicue down to the API section.
Past clicking "Create New API Token", a kaggle.json file will be generated and downloaded to your local machine.
Stride two: Upload kaggle.json to your Colab project: for instance, you tin can import files module from google.colab, and call upload() to launch a File Upload dialog and select the kaggle.json from your local auto.
Step iii: Update KAGGLE_CONFIG_DIR path to the current working directory. You tin run !pwd to go the current working directory and assign the value to os.environ['KAGGLE_CONFIG_DIR'] :
Step 4: Finally, you should be able to run the following Kaggle API to download datasets:
!kaggle competitions download -c titanic !kaggle datasets download -d alexanderbader/forbes-billionaires-2021-30
Annotation for the competition dataset, the Kaggle API should exist bachelor under the Data tab
For the full general dataset, the Kaggle API tin can be accessed as follows:
Conclusion
Google Colab is a great tool for individuals who want to take advantage of the capabilities of high-end computing resources (like GPUs, TPUs) without being restricted by their price.
In this article, nosotros have gone through most of the ways yous can meliorate your Google Colab experience by loading external information into Google Colab. I hope this article volition assist you to salve time in learning Colab and Data Assay.
Thanks for reading. Stay tuned if y'all are interested in the practical attribute of machine learning.
You may exist interested in some of my Pandas manufactures:
- 10 tricks for Converting numbers and strings to datetime in Pandas
- Using Pandas method chaining to improve code readability
- How to do a Custom Sort on Pandas DataFrame
- All the Pandas shift() you should know for information analysis
- When to use Pandas transform() part
- Pandas concat() tricks you should know
- Difference between apply() and transform() in Pandas
- All the Pandas merge() you should know
- Working with datetime in Pandas DataFrame
- Pandas read_csv() tricks y'all should know
- 4 tricks you should know to parse date columns with Pandas read_csv()
More than tutorials tin exist found on my Github
DOWNLOAD HERE
Posted by: nealnany1956.blogspot.com
Post a Comment