How to : Analyse BigQuery with DataLab & Python(2 of 3)

How to : Analyse BigQuery with DataLab & Python(2 of 3)

Google Cloud Datalab is an interactive tool created to explore, analyze, transform and visualize data and build machine learning models on Google Cloud Platform(GCP). By default, it runs on Google Compute Engine and connects to multiple cloud services easily so you can focus on your data analytics tasks.

Pre-requisite – Setup Datalab, can refer my previous blog before continue with this blog.

Assume the Datalab setup in place. In this blog we are going to see the simple steps of connecting BigData sample data from Datalab and analyzing with python.

Once in Datalab home page, click “+Notebook” to create new notebook.

Run (“Shift” + “Enter”) the following command in your terminal to install the latest version of the BigQuery Python client library, including the Pandas library,

!pip install --upgrade google-cloud-bigquery

Will get a similar screen

Test is the notebook basics with a hello world

To simply the code writing and retrieve the data via SQL like command, run the code:

%load_ext google.cloud.bigquery

All the basics configurations are in place, let’s try to query few records from bigquery “Crime” sample database. For this demo, going to get crime record in UK by year.

**Behind the scenes, %%bigquery uses the BigQuery Python client library to run the given query, convert the results to a Pandas Dataframe, optionally save the results to a variable, and finally display the results.

Anyone knows SQL, will find easy to query the Bigquery data now. Another case, top 5 crimes in 2016

Now have created connection between Google Datalab & Bigquery. And able to generate output tables using SQL like command. In my next blog, will be covering on how to use graphical outputs using python libraries. Cheers, stay tune guys.

To view or add a comment, sign in

More articles by Sasitharan Ravindar

  • CASE Study: Grab Holdings

    Recently, I have completed the Disruptive Strategy course with Online Harvard Business School. Putting the learning to…

  • Grounded, Not Guessing: A RAG Chatbot POC

    Last week in Petaling Jaya, I joined a small Digital Transformation & AI community session. One topic lit up the room:…

  • From “rule-based headaches” to a quick win with Azure Content Safety

    During a recent meetup, a friend who moderates content at an SME in Malaysia told me two things that are really adding…

  • After Years in IT, I Finally Touched My Work—Literally

    I’ve always wanted to work on a project that would produce a tangible outcome in the real world—something I could…

    2 Comments
  • Job Market - My Unpopular Opinion

    The History During COVID-19 pandemic lockdowns, governments especially the major economy started to lower the central…

  • Robots are Our Friend

    Recently I had a chance to attend a Cobot(a.k.

  • PROJECT MANAGER VS PROGRAM MANAGER

    Project Manager, is a much more famous term compared to Program Manager. Even sometimes used interchangeably.

  • WHY ONE SOLUTION WILL NOT FIT ALL

    Sometimes, a project is developed with the mindset that it is built once and rolled out and we are done. But, in real…

  • AI’S WEAKNESS – THE YEAR 2023

    Humans start to envy Ai’s capability. Worry about job loss due to multiple industry disruptions and the way of working…

  • AI & Robotics Is NOT Optional

    AI & Robotics are NOT optional but a necessity. Why? Both technologies can work independently or integrated to bring…

Explore content categories