|
楼主 |
发表于 2021-10-8 23:50:58
|
显示全部楼层
代码:housing.plot(kind="scatter",x="longitude",y="latitude",alpha=0.1,figsize=(7,7))
报错:KeyError Traceback (most recent call last)
d:\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
2645 try:
-> 2646 return self._engine.get_loc(key)
2647 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\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'longitude'
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
<ipython-input-12-b6dc1248a5f8> in <module>
----> 1 housing.plot(kind="scatter",x="longitude",y="latitude",alpha=0.1,figsize=(7,7))
d:\Anaconda3\lib\site-packages\pandas\plotting\_core.py in __call__(self, *args, **kwargs)
790 if kind in self._dataframe_kinds:
791 if isinstance(data, ABCDataFrame):
--> 792 return plot_backend.plot(data, x=x, y=y, kind=kind, **kwargs)
793 else:
794 raise ValueError(f"plot kind {kind} can only be used for data frames")
d:\Anaconda3\lib\site-packages\pandas\plotting\_matplotlib\__init__.py in plot(data, kind, **kwargs)
59 kwargs["ax"] = getattr(ax, "left_ax", ax)
60 plot_obj = PLOT_CLASSES[kind](data, **kwargs)
---> 61 plot_obj.generate()
62 plot_obj.draw()
63 return plot_obj.result
d:\Anaconda3\lib\site-packages\pandas\plotting\_matplotlib\core.py in generate(self)
261 self._compute_plot_data()
262 self._setup_subplots()
--> 263 self._make_plot()
264 self._add_table()
265 self._make_legend()
d:\Anaconda3\lib\site-packages\pandas\plotting\_matplotlib\core.py in _make_plot(self)
968 label = None
969 scatter = ax.scatter(
--> 970 data[x].values,
971 data[y].values,
972 c=c_values,
d:\Anaconda3\lib\site-packages\pandas\core\frame.py in __getitem__(self, key)
2798 if self.columns.nlevels > 1:
2799 return self._getitem_multilevel(key)
-> 2800 indexer = self.columns.get_loc(key)
2801 if is_integer(indexer):
2802 indexer = [indexer]
d:\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
2646 return self._engine.get_loc(key)
2647 except KeyError:
-> 2648 return self._engine.get_loc(self._maybe_cast_indexer(key))
2649 indexer = self.get_indexer([key], method=method, tolerance=tolerance)
2650 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\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'longitude' |
|