import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import pandas_datareader as data
start ='2010-01-01'
end = '2019-12-31'
df=data.DataReader('AppL', 'yahoo', start, end)
df.head()
- ---错误-----
TypeError Traceback (most recent call last)
/tmp/ipykernel_1028/3510576555.py in <module>
2 end = '2019-12-31'
3
----> 4 df=data.DataReader('AppL', 'yahoo', start, end)
5 df.head()
~/conda/envs/python/lib/python3.7/site-packages/pandas/util/_decorators.py in wrapper(*args, **kwargs)
205 else:
206 kwargs[new_arg_name] = new_arg_value
--> 207 return func(*args, **kwargs)
208
209 return cast(F, wrapper)
~/conda/envs/python/lib/python3.7/site-packages/pandas_datareader/data.py in DataReader(name, data_source, start, end, retry_count, pause, session, api_key)
376 retry_count=retry_count,
377 pause=pause,
--> 378 session=session,
379 ).read()
380
~/conda/envs/python/lib/python3.7/site-packages/pandas_datareader/base.py in read(self)
251 # If a single symbol, (e.g., 'GOOG')
252 if isinstance(self.symbols, (string_types, int)):
--> 253 df = self._read_one_data(self.url, params=self._get_params(self.symbols))
254 # Or multiple symbols, (e.g., ['GOOG', 'AAPL', 'MSFT'])
255 elif isinstance(self.symbols, DataFrame):
~/conda/envs/python/lib/python3.7/site-packages/pandas_datareader/yahoo/daily.py in _read_one_data(self, url, params)
151 try:
152 j = json.loads(re.search(ptrn, resp.text, re.DOTALL).group(1))
--> 153 data = j["context"]["dispatcher"]["stores"]["HistoricalPriceStore"]
154 except KeyError:
155 msg = "No data fetched for symbol {} using {}"
TypeError: string indices must be integers
请帮助我解决这段代码中的错误。
1条答案
按热度按时间abithluo1#
根据documentation,您可以使用以下代码在
start_date
和end_date
之间从yahoo finance下载数据:这将产生一个**Pandas Dataframe **。
代码:
输出:
注:
如果您想要多个股票代码: