Google Colab, a cloud-based platform, streamlines Python programming and data science projects. It stands out for utilizing Google's cloud infrastructure, offering powerful computational resources without needing local installation.
With just a Google account, it provides a free and accessible environment for everyone from beginners to advanced data science practitioners.
Advantage of using Colab the colud platform for Python 🔝
Resource Availability:
Computational Power: Colab provides access to powerful GPUs and TPUs.
Memory: Colab allows for more memory, useful for handling large datasets and computations.
Free Access to GPU and TPU:
Colab provides free access to GPU and TPU resources, beneficial for machine learning tasks.
Collaboration and Sharing:
Colab facilitates real-time collaboration and easy sharing of notebooks.
Multiple users can work on the same notebook simultaneously.
Integration with Google Services:
Colab integrates seamlessly with Google Drive and other Google services.
Pre-installed Libraries and Packages:
Colab comes with pre-installed popular Python libraries and packages.
No Installation Required:
Colab is accessed through a web browser, eliminating the need for local installations.
Automatic Saving and Version History:
Colab automatically saves work to Google Drive and provides version history.
Easier Access to Data:
Colab allows seamless access to data stored in cloud services.
Learning and Exploration:
Colab is a great platform for learning and exploration. It is consistently accessible and instantly responsive the moment you initiate or embark on your journey.
Beginners can start coding without worrying about environment setup.
Colab is Google Cloud based integrated development environment (IDE) for Python and Machine Learning.
Python libraries ( including Pandas , Numpy ) are already available and you only have to import them to start using. You need one google account to start using colab.
Upload Excel or CSV file in google drive and connect from Colab Python platform using mount drive
We can keep our CSV or Excel files in google drive and use it in our Colab platform.
Upload your CSV or Excel file to any folder in google drive. We created one folder inside our Colab Notbooks folder and named it as downloads. You can give your own name to the folders.
Now you have to mount the drive to your colab file. Run this code.
from google.colab import drive
drive.mount('/content/drive')
You will be shown one link and below it there will be an text box asking for authorization code. Visit the link and collect ( copy ) your authorization code. You must be already logged in to your gmail account to get the code.
Paste the code inside textbox and then press enter.
Now your drive is mounted.
In your left panel you can see drive icon. Expand the directory structure to reach and select your file you want to use. Right click and use copy path.
Now use this path to create a variable to use in our read_excel() or read_csv() functions.
import pandas as pd
path='/content/drive/My Drive/Colab Notebooks/downloads/my_file.xlsx'
my_data = pd.read_excel(path)
Check if our required library is already available.
%pip freeze
If not available then install the same. Pytrends is an unofficial google trends api to get the data from google trends.
Here is one more code to check Availability of libraries
import imp
try:
imp.find_module('reportlab') # check reportlab library for PDF creation
found = True
except ImportError:
found = False
print(found)