How to use Python in Google Colab integrated directly with Power BI to analyze patent data

This blog post will show you how to load and transform patent data and connect Power BI with Google Colab. Google Colab is a free cloud service that allows you to run Jupyter notebooks in the cloud. Jupyter notebooks are a great way to share your code and data analysis with others. Power BI is a business intelligence tool that allows you to visualize your data and create reports. Connecting Power BI with Google Colab allows you to easily share your data visualizations with others. Let’s get started!

What is a patent?

A patent is an exclusive right granted for an invention, which is a product or a process that provides, in general, a new way of doing something or offers a new technical solution to a problem. To get a patent, technical information about the invention must be disclosed to the public in a patent application.

What is WIPO?

WIPO is the global forum for intellectual property (IP) services, policy, information, and cooperation. WIPO’s activities include hosting forums to discuss and shape international IP rules and policies, providing global services that register and protect IP in different countries, resolving transboundary IP disputes, helping connect IP systems through uniform standards and infrastructure, and serving as a general reference database on all IP matters; this includes providing reports and statistics on the state of IP protection or innovation both globally and in specific countries.[7] WIPO also works with governments, nongovernmental organizations (NGOs), and individuals to utilize IP for socioeconomic development. If you need more information about WIPO, click here.

This video can demonstrate the Power BI functionality we will use today

Now, you understand what a patent is and what WIPO is. Let’s start our experiment!

First, we will load the patent data from WIPO. In this experiment, we will use the authority file from 2022.

Python
from powerbiclient import Report, models
from powerbiclient.authentication import DeviceCodeLoginAuthentication
import pandas as pd
from google.colab import drive
from google.colab import output
from urllib import request
import zipfile
import requests

# mount Google Drive
drive.mount('/content/gdrive')

file_url = "https://patentscope.wipo.int/search/static/authority/2022.zip"
	
r = requests.get(file_url, stream = True)

with open("/content/gdrive/My Drive/2022.zip", "wb") as file:
	for block in r.iter_content(chunk_size = 1024):
		if block:
			file.write(block)
   
compressed_file = zipfile.ZipFile('/content/gdrive/My Drive/2022.zip')

csv_file = compressed_file.open('2022.csv')

data = pd.read_csv(csv_file, delimiter=";", names=["Publication Number","Publication Date","Title","Kind Code","Application No","Classification","Applicant","Url"])

#Show the head data
data.head()

Now, we have the data let’s do some transformation to prepare to load in the Power BI report.

Python
# Transformations of the csv file dowloaded from wipo

#remove the two fisrt lines
data = data.iloc[1:]
data = data.iloc[1:]

#create a new column with the Classification name
data["Classification_Name"] = data["Classification"].str[:1]

#Modify this column with the classification description
data["Classification_Name"] = data["Classification_Name"].replace({
    'A': 'Human Necessities', 
    'B': 'Performing Operations and Transporting', 
    'C': 'Chemistry and Metallurgy', 
    'D': 'Textiles and Paper', 
    'E': 'Fixed Constructions', 
    'F': 'Mechanical Engineering', 
    'G': 'Physics', 
    'H': 'Electricity'
  }
)

#Show again the head data
data.head()

#Save the Excel file in google drive to share with the Power BI report.
data.to_excel("gdrive/MyDrive/datasets/Result_WIPO2022.xlsx")

After that, we will connect to Power BI and show the report inside Google Colab.

Python
# Import the DeviceCodeLoginAuthentication class to authenticate against Power BI and initiate the Micrsofot device authentication
device_auth = DeviceCodeLoginAuthentication()

group_id="YOU HAVE TO PUT HERE YOUR POWER BI GROUP ID OR WORKSPACE ID"
report_id="YOU HAVE TO PUT HERE YOUR POWER BI REPORT ID"

report = Report(group_id=group_id, report_id=report_id, auth=device_auth)
report.set_size(1024, 1600)
output.enable_custom_widget_manager()

# Show the power BI report with the wipo downloaded data.
report

Click here, to see this report in full-screen mode.

Follow here the Google Colab file with the Python code. If you want the Power BI report click here.

Conclusion

In this blog post, we showed you how to load data from external datasets, and transform and load in Power BI reports inside Google Colab. By following these steps, you can start using Google Colab and Power BI to analyze your data with Python and easily share it with others!

That’s it for today!

Author: Lawrence Teixeira

With over 30 years of expertise in the Technology sector and 18 years in leadership roles as a CTO/CIO, he excels at spearheading the development and implementation of strategic technological initiatives, focusing on system projects, advanced data analysis, Business Intelligence (BI), and Artificial Intelligence (AI). Holding an MBA with a specialization in Strategic Management and AI, along with a degree in Information Systems, he demonstrates an exceptional ability to synchronize cutting-edge technologies with efficient business strategies, fostering innovation and enhancing organizational and operational efficiency. His experience in managing and implementing complex projects is vast, utilizing various methodologies and frameworks such as PMBOK, Agile Methodologies, Waterfall, Scrum, Kanban, DevOps, ITIL, CMMI, and ISO/IEC 27001, to lead data and technology projects. His leadership has consistently resulted in tangible improvements in organizational performance. At the core of his professional philosophy is the exploration of the intersection between data, technology, and business, aiming to unleash innovation and create substantial value by merging advanced data analysis, BI, and AI with a strategic business vision, which he believes is crucial for success and efficiency in any organization.

Leave a Reply

Discover more from 💡Tech News & Insights

Subscribe now to keep reading and get access to the full archive.

Continue reading