![](/img/trans.png)
[英]i need to put the grade calculation into a function and i really don't know where to start
[英]i don't know where i have to put this lines
我開始用一本沒有基礎的書學習 python:/
我在關注這些例子
def index_global(d, symbol, start_date='', end_date='', page=1):
end_date = date_format(end_date)
if start_date == '':
start_date = end_date - pd.DateOffset(months=1)
start_date = date_format(start_date)
url = 'https://finance.naver.com/world/worldDayListJson.nhn?symbol='+symbol+'&fdtc=0&page='+str(page)
raw = urlopen(url)
data = json.load(raw)
if len(data) > 0:
for n in range(len(data)):
date = pd.to_datetime(data[n]['xymd']).date()
if date <= end_date and date >= start_date:
# start_date와 end_date 사이에서 데이터 저장
# 종가 처리
price = float(data[n]['clos'])
# 딕셔너리에 저장
d[date] = price
elif date < start_date:
# start_date 이전이면 함수 종료
return (d)
if len(data) == 10:
page += 1
index_global(d, symbol, start_date, end_date, page)
return (d)
在此定義之后,我需要添加
historical_indices = dict()
start_date = '2019-01-01'
end_date = '2019-3-31'
for key, value in indices.items():
s = dict()
s = index_global(s, key, start_date)
historical_indices[value] = s
prices_df = pd.DataFrame(historical_indices)
我真的不知道我必須把這個放在哪里我真的需要你的幫助!
我開始用一本沒有基礎的書學習 python:/
我在關注這些例子
def index_global(d, symbol, start_date='', end_date='', page=1):
end_date = date_format(end_date)
if start_date == '':
start_date = end_date - pd.DateOffset(months=1)
start_date = date_format(start_date)
url = 'https://finance.naver.com/world/worldDayListJson.nhn?symbol='+symbol+'&fdtc=0&page='+str(page)
raw = urlopen(url)
data = json.load(raw)
if len(data) > 0:
for n in range(len(data)):
date = pd.to_datetime(data[n]['xymd']).date()
if date <= end_date and date >= start_date:
# start_date와 end_date 사이에서 데이터 저장
# 종가 처리
price = float(data[n]['clos'])
# 딕셔너리에 저장
d[date] = price
elif date < start_date:
# start_date 이전이면 함수 종료
return (d)
if len(data) == 10:
page += 1
index_global(d, symbol, start_date, end_date, page)
return (d)
在此定義之后,我需要添加
historical_indices = dict()
start_date = '2019-01-01'
end_date = '2019-3-31'
for key, value in indices.items():
s = dict()
s = index_global(s, key, start_date)
historical_indices[value] = s
prices_df = pd.DataFrame(historical_indices)
我真的不知道我必須把這個放在哪里我真的需要你的幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.