Webスクレイピングについて勉強していて、アマゾンの売り上げページをスクレイピングして取ったデータ(json形式)を整形するコードを書いて先週まではきちんと実行できていたのですが、本日実行したところエラーが返ってきました。これはどういう意味のエラーなのでしょうか。
英語を読んでもよくわからないので質問させていただきます。
どこら辺のことがstringではないのでしょうか。コードにはどこにも nan という変数はつかってないです。
Traceback (most recent call last):
File "amazon.py", line 32, in <module>
plt.bar(x, y, align="center") # 中央寄せ
File "C:\Users\hoge\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 2775, in bar
ret = ax.bar(*args, **kwargs)
File "C:\Users\hoge\Anaconda3\lib\site-packages\matplotlib_init_.py", line 1867, in inner
return func(ax, *args, **kwargs)
File "C:\Users\hoge\Anaconda3\lib\site-packages\matplotlib\axes_axes.py", line 2212, in bar
self._process_unit_info(xdata=x, ydata=height, kwargs=kwargs)
File "C:\Users\hoge\Anaconda3\lib\site-packages\matplotlib\axes_base.py", line 2167, in _process_unit_info
self.xaxis.update_units(xdata)
File "C:\Users\hoge\Anaconda3\lib\site-packages\matplotlib\axis.py", line 1469, in update_units
default = self.converter.default_units(data, self)
File "C:\Users\hoge\Anaconda3\lib\site-packages\matplotlib\category.py", line 115, in default_units
axis.set_units(UnitData(data))
File "C:\Users\hoge\Anaconda3\lib\site-packages\matplotlib\category.py", line 182, in init
self.update(data)
File "C:\Users\hoge\Anaconda3\lib\site-packages\matplotlib\category.py", line 201, in update
raise TypeError("{val!r} is not a string".format(val=val))
TypeError: nan is not a string
python
1class UnitData(object): 2 def __init__(self, data=None): 3 """Create mapping between unique categorical values 4 and integer identifiers 5 ---------- 6 data: iterable 7 sequence of string values 8 """ 9 self._mapping = OrderedDict() 10 self._counter = itertools.count(start=0) 11 if data is not None: 12 self.update(data) 13 14 def update(self, data): 15 """Maps new values to integer identifiers. 16 17 Paramters 18 --------- 19 data: iterable 20 sequence of string values 21 22 Raises 23 ------ 24 TypeError 25 If the value in data is not a string, unicode, bytes type 26 """ 27 data = np.atleast_1d(np.array(data, dtype=object)) 28 29 for val in OrderedDict.fromkeys(data): 30 if not isinstance(val, VALID_TYPES): 31 raise TypeError("{val!r} is not a string".format(val=val)) 32 if val not in self._mapping: 33 self._mapping[val] = next(self._counter) 34
回答1件
あなたの回答
tips
プレビュー