KEEP GOING
[PANDAS] 시중 은행 오프라인 점포 추이 분석 본문
반응형
https://landshire.tistory.com/43
import requests
import pandas as pd
# 인증키
api = '38e7adb50a460e2c722348b2106d90cb'
url = f'http://fisis.fss.or.kr/openapi/companySearch.json?auth={api}&partDiv=A&lang=kr'
re=requests.get(url)
data = re.json()
# print(data)
banks = pd.DataFrame(data['result']['list'])
# print(banks)
# 구버전 제외
banks=banks[banks.finance_nm.str.contains('폐')==False]
print(banks)
# 국민은행, 우리은행, 농협, 신한, 하나, 기업은행만 추출
banks=banks[(banks['finance_nm']=='국민은행') | (banks['finance_nm']=='우리은행') | (banks['finance_nm']=='농협은행주식회사') |
(banks['finance_nm']=='신한은행') | (banks['finance_nm']=='하나은행')]
# print(banks)
data_banks=[]
for u,i in zip(banks['finance_cd'], banks['finance_nm']):
url3=f'http://fisis.fss.or.kr/openapi/statisticsInfoSearch.json?lang=kr&auth={api}&financeCd={u}&listNo=SA002&accountCd=A11&term=Y&startBaseMm=201612&endBaseMm=202012'
off=requests.get(url3).json()
data_banks.extend(off['result']['list'])
df=pd.DataFrame(data_banks)
df=df.sort_values('base_month', ascending=True)
df.columns=['Year','Code','Bank','Data','Account', '# of banks']
df['# of banks'] = df['# of banks'].astype(int)
df['Bank']=df['Bank'].str.replace('국민은행','KB')
df['Bank']=df['Bank'].str.replace('신한은행','ShinHan')
df['Bank']=df['Bank'].str.replace('우리은행','Woori')
df['Bank']=df['Bank'].str.replace('하나은행','Hana')
df['Bank']=df['Bank'].str.replace('중소기업은행','IBK')
df['Bank']=df['Bank'].str.replace('농협은행주식회사','NH')
print()
print(df)
print()
# print(df['# of banks'])
import plotly.express as px
fig = px.line(df, x="Year", y="# of banks", color='Bank',title='Number of Offline Banks in Kore Per Bank')
fig.show()
반응형
'python > pandas' 카테고리의 다른 글
[PANDAS] 한국은행 기준 금리 데이터 분석 (0) | 2022.05.06 |
---|---|
PANDAS 기초 실습 (iloc, loc, filter, OrderedDict) (0) | 2022.01.26 |
PANDAS 기초 실습 (iloc, to_csv, read_csv) (0) | 2022.01.26 |
PANDAS 기초 - (2) (DataFrame) (0) | 2022.01.17 |
PANDAS 기초 (Series, DataFrame) (0) | 2022.01.17 |
Comments