Kurioserweise ja, obwohl print(df2.index.values) und print(df2.index) unterschiedliche Ergebnisse liefern. Komplettes traceback:
Code: Alles auswählen
KeyError Traceback (most recent call last)
<ipython-input-3-7707213faada> in <module>
7 index = [1,2,3,4,5])
8
----> 9 df2.plot(kind="scatter", x = df2.index.values, y = "b", xticks=((40700, 40710, 40813, 41012, 41024)))
10
11 #ax = plt.axes()
C:\ProgramData\Anaconda3\lib\site-packages\pandas\plotting\_core.py in __call__(self, *args, **kwargs)
736 if kind in self._dataframe_kinds:
737 if isinstance(data, ABCDataFrame):
--> 738 return plot_backend.plot(data, x=x, y=y, kind=kind, **kwargs)
739 else:
740 raise ValueError(
C:\ProgramData\Anaconda3\lib\site-packages\pandas\plotting\_matplotlib\__init__.py in plot(data, kind, **kwargs)
59 ax = plt.gca()
60 kwargs["ax"] = getattr(ax, "left_ax", ax)
---> 61 plot_obj = PLOT_CLASSES[kind](data, **kwargs)
62 plot_obj.generate()
63 plot_obj.draw()
C:\ProgramData\Anaconda3\lib\site-packages\pandas\plotting\_matplotlib\core.py in __init__(self, data, x, y, s, c, **kwargs)
928 # the handling of this argument later
929 s = 20
--> 930 super().__init__(data, x, y, s=s, **kwargs)
931 if is_integer(c) and not self.data.columns.holds_integer():
932 c = self.data.columns[c]
C:\ProgramData\Anaconda3\lib\site-packages\pandas\plotting\_matplotlib\core.py in __init__(self, data, x, y, **kwargs)
867 if is_integer(y) and not self.data.columns.holds_integer():
868 y = self.data.columns[y]
--> 869 if len(self.data[x]._get_numeric_data()) == 0:
870 raise ValueError(self._kind + " requires x column to be numeric")
871 if len(self.data[y]._get_numeric_data()) == 0:
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py in __getitem__(self, key)
2984 if is_iterator(key):
2985 key = list(key)
-> 2986 indexer = self.loc._convert_to_indexer(key, axis=1, raise_missing=True)
2987
2988 # take() does not accept boolean indexers
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexing.py in _convert_to_indexer(self, obj, axis, is_setter, raise_missing)
1283 # When setting, missing keys are not allowed, even with .loc:
1284 kwargs = {"raise_missing": True if is_setter else raise_missing}
-> 1285 return self._get_listlike_indexer(obj, axis, **kwargs)[1]
1286 else:
1287 try:
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexing.py in _get_listlike_indexer(self, key, axis, raise_missing)
1090
1091 self._validate_read_indexer(
-> 1092 keyarr, indexer, o._get_axis_number(axis), raise_missing=raise_missing
1093 )
1094 return keyarr, indexer
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexing.py in _validate_read_indexer(self, key, indexer, axis, raise_missing)
1175 raise KeyError(
1176 "None of [{key}] are in the [{axis}]".format(
-> 1177 key=key, axis=self.obj._get_axis_name(axis)
1178 )
1179 )
KeyError: "None of [Int64Index([1, 2, 3, 4, 5], dtype='int64')] are in the [columns]"