前提・実現したいこと
urlのページから表を取得したいと考えています。
そしてページを更新し、図中のNo.が1になったときに繰り返しを終えるようにしたいです。
発生している問題・エラーメッセージ
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py:7123: FutureWarning: Sorting because non-concatenation axis is not aligned. A future version of pandas will change to not sort by default. To accept the future behavior, pass 'sort=False'. To retain the current behavior and silence the warning, pass 'sort=True'. sort=sort, KeyError Traceback (most recent call last) C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance) 2896 try: -> 2897 return self._engine.get_loc(key) 2898 except KeyError: pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc() pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc() pandas\_libs\index_class_helper.pxi in pandas._libs.index.Int64Engine._check_type() KeyError: 'No.' During handling of the above exception, another exception occurred: KeyError Traceback (most recent call last) <ipython-input-19-39720a9d6156> in <module> 4 df_stock = df_stock.append(data[1][5:]) 5 ----> 6 if str(data[1]["No."].tail(1)) == 1: 7 break 8 C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py in __getitem__(self, key) 2978 if self.columns.nlevels > 1: 2979 return self._getitem_multilevel(key) -> 2980 indexer = self.columns.get_loc(key) 2981 if is_integer(indexer): 2982 indexer = [indexer] C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance) 2897 return self._engine.get_loc(key) 2898 except KeyError: -> 2899 return self._engine.get_loc(self._maybe_cast_indexer(key)) 2900 indexer = self.get_indexer([key], method=method, tolerance=tolerance) 2901 if indexer.ndim > 1 or indexer.size > 1: pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc() pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc() pandas\_libs\index_class_helper.pxi in pandas._libs.index.Int64Engine._check_type() KeyError: 'No.'
該当のソースコード
import pandas as pd url_1 = 'https://stooq.com/q/d/?s=7203.jp&i=d&d1=20190401&d2=20190920&l=' i = 1 url = url_1 + str(i) data = pd.read_html(url, header = 0) df_stock = data[1][5:].replace(",","") df_stock.head() for i in range(2,100): url = url_1 + str(i) data = pd.read_html(url) df_stock = df_stock.append(data[1][5:]) if str(data[1]["No."].tail(1)) == 1: break df_stock.head()
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/12/12 04:15
2019/12/12 08:24