USA_Housing.plot(kind=“scatter”, x=“longitude”, y=“latitude”, alpha=0.4,
s=USA_Housing[“Area Population”]/100, label=“Area Population”, figsize=(10,7),
c=“median_house_value”, cmap=plt.get_cmap(“jet”), colorbar=True,
sharex=False)
KeyError Traceback (most recent call last)
~\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)
in
----> 1 USA_Housing.plot(kind=“scatter”, x=“longitude”, y=“latitude”, alpha=0.4,
2 s=USA_Housing[“Area Population”]/100, label=“Area Population”, figsize=(10,7),
3 c=“median_house_value”, cmap=plt.get_cmap(“jet”), colorbar=True,
4 sharex=False)
~\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")
~\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
~\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()
~\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,
~\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]
~\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’
How can i fix it?
Please reply.