I took the data in Python to create the panel data for econometrics. (It is a memorandum)
Python runtime environment Acquisition of Ministry of Internal Affairs and Communications API You can get it by registering as a user from here.
def_TakeData
import requests,urllib
import pandas as pd
import numpy as np
import json
def get_json(base_url,params):
params_str=urllib.parse.urlencode(params)
url=base_url+params_str
json=requests.get(url).json()
return json
def take_data(dataid):
appID="Enter the appID"
base_url="http://api.e-stat.go.jp/rest/2.1/app/json/getStatsData?"
params={
"appId":appID,
"lang":"J",
"statsDataId":dataid,
"metaGetFlg":"Y",
"cntGetFlg":"N",
"sectionHeaderFlg":"1"
}
data=get_json(base_url,params)
return data
take
data=take_data(XXXXX)
json format data is converted
url is
http://api.e-stat.go.jp/rest/2.1/app/getStatsData?appId=1lang=J&statsDataId=(Enter the data ID here) & metaGetFlg = Y & cntGetFlg = N & sectionHeaderFlg = 1
The above format.
You can easily refer to the API request URL from the Ministry of Internal Affairs and Communications website.
json->DataFrame
Example
df=pd.DataFrame(data['GET_STATS_DATA']['STATISTICAL_DATA']['DATA_INF']['VALUE'])
#Convert json data to pandas DataFrame(Example)
Store the desired data in the DataFrame.
-`data['GET_STATS_DATA']['STATISTICAL_DATA']['CLASS_INF']['CLASS_OBJ']`
You can see what data is in json with the above code.
Now you have a DataFrame that is easy to operate
It was easier to use than the Twitter API, so I'll do my best to make more details.
I am a beginner in Python, so please point out any mistakes.