About Cluster Mapping US
Cluster Mapping US는 미국 산업 클러스터에 대한 선별 및 지속적으로 업데이트 된 데이터를 공개로 제공하는 프로젝트이고 JSON 데이터를 반환하는 API를 구축하여 HTTP 요청을 통해 액세스할 수 있습니다. 이 프로젝트는 미국 경제 개발국과 하버드 비즈니스 스쿨의 지원을 받고 있고, 별도의 API key가 없어도 접근이 가능해 유용한 데이터들을 얻을 수 있습니다.
2) API 가져오는 방법 메뉴얼
https://clustermapping.us/about/clustermappingus-data-api-documentationhttps://clustermapping.us/
[1] Python 으로 가지고 올 수 있는 데이터 대분류 확인하기
base='http://clustermapping.us/data/'
response = requests.get(base)
data = response.json()
data
{out} {'meta': 'http://clustermapping.us:4001/data/meta',
'region': 'http://clustermapping.us:4001/data/region',
'cluster': 'http://clustermapping.us:4001/data/cluster'}
메타(Meta): 어떤 변수가 있는지에 대한 데이터
지역(Region): 어느 지역이 있는지에 대한 데이터
클러스터(Cluster): 클러스터 정보 데이터
[2] Python 으로 가지고 올 수 있는 데이터 대분류(상세) 확인하기
dict 을 이용하면 상세 사이트 asset 이 나오는데, 이런 형태의 리스트 구조를 list of dictionaries 라고 한다
#메타데이터 가져오기
#Retrieves entire list of keys, labels, formats, and other data used for indicators throughout the site
base='http://clustermapping.us/data/meta/dict'
response = requests.get(base)
data = response.json()
mdict=data
mdict
{out}
{'varTypes': [{'label': 'Performance', 'key': 'performance'},
{'label': 'Business Environment', 'key': 'business'},
{'label': 'Demographics & Geography', 'key': 'structure'}],
'vars': [{'label': 'Specialization',
'key': 'specialization_tl',
'mapTypes': ['cluster'],
'colors': {'max': '#0074ea',
'middle': '#76dddd',
'zero': '#76dddd',
'min': '#fffddc',
'palette': ['#fffddc',
'#fffddc',
'#76dddd',
'#76dddd',
'#76dddd',
'#76dddd',
'#76dddd',
'#76dddd',
'#0074ea',
'#0074ea']},
'format': ',f',
'calc': True,
'calc_type': 'specialization',
'calc_source': ['cluster_emp_per_tf', 'lq_tf', 'emp_tl', 'est_tl']},
{'label': 'Employment',
'subtitle': 'Private, Non-Agricultural Employment',
'key': 'emp_tl',
'mapTypes': ['cluster'],
'colors': {'max': '#1e2a79',
'middle': '#0074ea',
'zero': '#4dc5ff',
'min': '#dcfbff',
'palette': ['#dcfbff',
'#a5eeff',
'#86ddff',
'#4dc5ff',
'#33aaff',
'#328af8',
'#0074ea',
'#1155cc',
'#003f9e',
'#1e2a79']},
'format': ',f',
'type': 'cagr',
'plot_type': 'cagr',
'plot_scale': 'log',
'spark_type': '1-rank',
'lookup': 'jobs',
'avg': True},
이 형태를 dataframe으로 바꿔
mdict = pd.DataFrame.from_dict(mdict, orient='index')
mdict
주려면 아래의 코드를 써주면 된다. 그럼 아래와 같이 dataframe 형태로 변환되어 나온다.
[3] Meta:Regions 정보 가져오기
#메타데이터 가져오기
#Retrieves valid region types
base='http://clustermapping.us/data/meta/regions'
response = requests.get(base)
data = response.json()
data
regions=data
regions
[3] Meta: Country 정보 가져오기
#메타데이터 가져오기
#Retrieves basic data, including geographic information for all the regions of a given type, e.g., [country|state|economic|msa].
#:type parameter can be:
#● Country = “country”
#● State = “state”
#● Economic Area = #“economic”
#● Micro/Macro Statistical Area = “msa”
base='http://clustermapping.us/data/meta/regions/country'
response = requests.get(base)
data = response.json()
data
country=data
country
country = pd.DataFrame(country)
country
[4] Meta: Conclusion
나머지는 전부 동일하다.
base='http://clustermapping.us/data/meta/regions/[찾고자하는 Dataset]'
response = requests.get(base)
data = response.json()
data
[Dataset]=data
[Dataset]
[Dataset]= pd.DataFrame([Dataset])
[Dataset]
에서 [Dataset] 부분에 원하는 값을 넣어주기만 하면 끝이다.
'지식 창고 > 파이썬' 카테고리의 다른 글
미국 노동 통계청 API 활용법 Tip (0) | 2023.06.20 |
---|---|
PROQUEST 파일이 너무 커서 EXPORT가 안 되는 경우, (0) | 2023.03.29 |
댓글