Get corporate number at once via gbizinfo with python

Introduction

Is there something like this? I have obtained toB company information, but CRM does not have a corporate number. There is basic information such as the corporate name and the year of establishment. What should be used as the join key when joining with a dataset of another list in such a case? I think I'm worried.

All company information can be combined into one piece of information as long as there is a corporate number set by the government. For example, suppose you may want to join table A and table B as follows:

Table A (company information)

company name Year of establishment Prefectures
hoge fuga 3

Table B (contact information)

company name Estimated amount Order status
hoge 3000 First connection

Try using gbizinfo

Anyone who has come into contact with database languages such as sql will know. The DB load is applied to the combination of character strings. As long as you have a corporate number, you can use it as a common combination key. The Ministry of Economy, Trade and Industry's gbizinfo is convenient for obtaining a corporate number. It has this service REST API! Therefore, it is very easy to get a corporate number. https://info.gbiz.go.jp/api/index.html

Later, you will need X-hojinInfo-api-token for headers information. You need to apply for API usage in advance.

Try to call it with python

Sample data

Suppose you have data that contains only the company name and the year of establishment, as shown below. I would like to include the corporate number in this data. The method at the time of request is GET

company name Year of establishment
Rakuten Mobile, Inc. 2018
Matsuya Foods Co., Ltd. 2018

Try to request

request.py


import json
import pandas as pd
import requests

class CorporateNumbers:
    def __init__(self):
        self.headers = {
            "Accept": "application/json",
            "X-hojinInfo-api-token": "###token###"
        }
        self.endpoint_url = 'https://info.gbiz.go.jp/hojin/v1/hojin'
    def _create_taeger_company_dataframe(self):
        df = pd.read_clipboard()
        return df
    def _get_corporate_number(self,df):
        #df = self._create_taeger_company_dataframe()
        name = df.name
        founded_year = df.founded
        results = []
        for name,founded in zip(name,founded_year):
            data = {
                'name':name,
                'founded':founded
            }
            res = requests.get(
                url = self.endpoint_url,
                headers = self.headers,
                params = data
            )
            json = res.json()['hojin-infos']
            results.extend(json)
            df = pd.io.json.json_normalize(results)
        return df
    def _merge_dataframe(self):
        df1 = self._create_taeger_company_dataframe()
        df2 = self._get_corporate_number(df = df1)
        df3 = pd.merge(df1,df2,on='name',how='left')
        return df3

result

スクリーンショット 2020-11-17 23.13.45.png

Recommended Posts

Get corporate number at once via gbizinfo with python
Convert memo at once with Python 2to3
Convert multiple proto files at once with python
Get date with python
Get data from database via ODBC with Python (Access)
Get Twitter timeline with python
Get Youtube data with python
ABC161D Lunlun Number with python3
Get thread ID with python
Get started with Python! ~ ② Grammar ~
Get stock price with Python
Get home directory with python
Get keyboard events with python
Get Alembic information with Python
Get Python list elements with multiple indexes (number) Simple method
Number recognition in images with Python
Get started with Python! ~ ① Environment construction ~
Link to get started with python
Cropping images at once [python] [Pillow]
Get reviews with python googlemap api
random French number generator with python
Get the weather with Python requests
Get web screen capture with python
Get the weather with Python requests 2
[Python] Get economic data with DataReader
How to get started with Python
[Small story] Get timestamp with Python
Get Qiita trends with Python scraping
Replace all at once with sed
Get started with Python in Blender
Get weather information with Python & scraping
Send email via gmail with Python 3.4.3.
Get the number of searches with a regular expression. SeleniumBasic VBA Python
Get the number of articles accessed and likes with Qiita API + Python
Get additional data in LDAP with python
Get property information by scraping with python
Get html from element with Python selenium
[Note] Get data from PostgreSQL with Python
Send newsletters all at once with Gmail
[Python] Get the variable name with str
Get Started with TopCoder in Python (2020 Edition)
Get out of multiple loops at once
[Python] Get Python package information with PyPI API
How Python beginners get started with Python with Progete
Let's get along with Python # 0 (Environment construction)
Get AKB member's Google+ ID at once
[Blender x Python] Let's get started with Blender Python !!
[Python] How to save images on the Web at once with Beautiful Soup
Get a lot of Twitter tweets at once
Python hand play (let's get started with AtCoder?)
[Python] Get the files in a folder with Python
Get the weather in Osaka via WebAPI (python)
Get a ticket for a theme park with python
Erase image files at once with one liner
Calculate the total number of combinations with python
Get stock price data with Quandl API [Python]
I tried to get CloudWatch data with Python
Get git branch name and tag name with python
[Python] Get rid of dating with regular expressions
[python] [vscode] When you get angry with space-tab-mixed
Get CPU information of Raspberry Pi with Python