def exchange(start_date, end_date):
ex = pd.DataFrame()
getdate = pd.date_range(start= str(start_date) , end = str(end_date)).to_series()
getdate2 = getdate[getdate.apply(lambda x: x.weekday() != 6)]
getdate = getdate2.apply(lambda x: x.strftime("%Y%m%d")).to_list()
for day in getdate:
url = 'https://www.koreaexim.go.kr/site/program/financial/exchangeJSONauthkey=saPiIxk9gPEc9xqcqaXZL4UXXUWQ6oV7&searchdate='+f"{day}"+'&data=AP01'
response = pd.read_json(requests.get(url).text)
response['numeric'] = day
ex = pd.concat([ex,response])
ex1 = ex.rename(columns={'cur_unit':'country','deal_bas_r':'value'})
ex1['value'] = ex1['value'].str.replace(pat=r',',repl=r'',regex=True).apply(float)
exa = ex1[ex1['country']=='USD']
exa['value_rate1'] = exa['value'].shift()
exa['netchange'] = round(((exa['value'] - exa['value_rate1'])/exa['value_rate1'])*100,2)
exa = exa.tail(1)
exb = ex1[ex1['country']=='EUR']
exb['value_rate1'] = exb['value'].shift()
exb['netchange'] = round(((exb['value'] - exb['value_rate1'])/exb['value_rate1'])*100,2)
exb = exb.tail(1)exc = ex1[ex1['country']=='JPY(100)']exc['value_rate1'] = exc['value'].shift()exc['netchange'] = round(((exc['value'] - exc['value_rate1'])/exc['value_rate1'])*100,2)exc = exc.tail(1)exd = ex1[ex1['country']=='CNH']exd['value_rate1'] = exd['value'].shift()exd['netchange'] = round(((exd['value'] - exd['value_rate1'])/exd['value_rate1'])*100,2)exd = exd.tail(1)exall = pd.concat([exa,exb,exc,exd])exall = exall.drop(columns={'value_rate1'})exall = exall[['value','netchange','numeric','country']]return exall
공부중인데
이걸 실행하면
UnboundLocalError: local variable 'exall' referenced before assignment
오류가 발생하는데..
한줄씩 실행하면 문제가 없단말야
뭐가 문제고 어떻게 고쳐야하는거야??