所以我这样做了:
def get_quotes(ticker:str, start_date:datetime.date, end_date:datetime.date)->list:
'''Downloads the quotes from Yahoo finance'''
start_month = str(start_date.month-1)
start_day = str(start_date.day)
start_year = str(start_date.year)
end_month = str(end_date.month-1)
end_day = str(end_date.day)
end_year = str(end_date.year)
try:
list = []
quote = 'http://ichart.yahoo.com/table.csv?s='+ticker+'&a'+start_month+'&b='+start_day+"&c="+start_year+'&d='+end_month+'&e='+ end_day +'&f='+end_year+'&g=d'
response = urllib.request.urlopen(quote)
data = response.read()
string_data = data.decode(encoding='utf-8')
lines = string_data.splitlines()
for x in lines:
data = [y for y in x.split(',')]
list.append(data[0:5])
return list
except URLError:
print('Page not found! Please enter a valid ticker')
但结果列表是:[['Date', 'Open', 'High', 'Low', 'Close'], ['2011-10-10', '26.58', '26.97', '26.47',
'26.94'], ['2011-10-07', '26.34', '26.51', '26.20', '26.25'], ['2011-10-06', '25.90', '26.40', '25.70' ', '26.34']]
什么时候应该是:['Date', 'Open', 'High', 'Low', 'Close'], ['2011-10-10', '26.58', '26.97', '26.47', '26.94 '], ['2011-10-07', '26.34', '26.51', '26.20', '26.25'], ['2011-10-06', '25.90', '26.40', '25.70', '26.34']
我可以以某种方式消除双重列表吗?