Python Forum
strange error from pandas dataframe
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
strange error from pandas dataframe
I am trying to apply the command
example_batch = normed_train_data[:10]
to the pandas data frame named normed_train_data, but I am getting an error message I don't know how to fix or why its occurring. Below is the error message.
Traceback (most recent call last): File "C:\Users\crovn\AppData\Roaming\Python\Python38\site-packages\pandas\core\indexes\", line 4845, in get_slice_bound return self._searchsorted_monotonic(label, side) File "C:\Users\crovn\AppData\Roaming\Python\Python38\site-packages\pandas\core\indexes\", line 4806, in _searchsorted_monotonic raise ValueError("index must be monotonic increasing or decreasing") ValueError: index must be monotonic increasing or decreasing During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\crovn\Desktop\", line 101, in <module> example_batch = normed_train_data[:10] File "C:\Users\crovn\AppData\Roaming\Python\Python38\site-packages\pandas\core\", line 2779, in __getitem__ indexer = convert_to_index_sliceable(self, key) File "C:\Users\crovn\AppData\Roaming\Python\Python38\site-packages\pandas\core\", line 2267, in convert_to_index_sliceable return idx._convert_slice_indexer(key, kind="getitem") File "C:\Users\crovn\AppData\Roaming\Python\Python38\site-packages\pandas\core\indexes\", line 424, in _convert_slice_indexer return self.slice_indexer(key.start, key.stop, key.step, kind=kind) File "C:\Users\crovn\AppData\Roaming\Python\Python38\site-packages\pandas\core\indexes\", line 4713, in slice_indexer start_slice, end_slice = self.slice_locs(start, end, step=step, kind=kind) File "C:\Users\crovn\AppData\Roaming\Python\Python38\site-packages\pandas\core\indexes\", line 4932, in slice_locs end_slice = self.get_slice_bound(end, "right", kind) File "C:\Users\crovn\AppData\Roaming\Python\Python38\site-packages\pandas\core\indexes\", line 4848, in get_slice_bound raise err File "C:\Users\crovn\AppData\Roaming\Python\Python38\site-packages\pandas\core\indexes\", line 4842, in get_slice_bound slc = self.get_loc(label) File "C:\Users\crovn\AppData\Roaming\Python\Python38\site-packages\pandas\core\indexes\", line 508, in get_loc return super().get_loc(key, method=method, tolerance=tolerance) File "C:\Users\crovn\AppData\Roaming\Python\Python38\site-packages\pandas\core\indexes\", line 2648, in get_loc return self._engine.get_loc(self._maybe_cast_indexer(key)) File "pandas\_libs\index.pyx", line 111, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\index.pyx", line 133, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\index.pyx", line 163, in pandas._libs.index.IndexEngine._get_loc_duplicates File "pandas\_libs\index_class_helper.pxi", line 54, in pandas._libs.index.Float64Engine._maybe_get_bool_indexer KeyError: 10
I converted the normed_train_data to a csv so you can see its contents. The file is named dataframe1.csv and is attached to this thread. I tried the command
example_batch = normed_train_data[:10]
on a different data frame attached as dataframe2.csv and for some reason the command works on that one, but not on the dataframe1.csv one.

Why am I getting this error message, and How do I make this command work?

Attached Files

.csv   dataframe1.csv (Size: 28.69 KB / Downloads: 10)
.csv   dataframe2.csv (Size: 55.37 KB / Downloads: 9)
If you want to get the first 10 rows of the dataframe, you need to use iloc, e.g.

Possibly Related Threads…
Thread Author Replies Views Last Post
  HTML Decoder pandas dataframe column mbrown009 2 120 Yesterday, 06:03 PM
Last Post: mbrown009
  Use pandas to obtain cartesian product between a dataframe of int and equations? haihal 0 840 Jan-06-2023, 10:53 PM
Last Post: haihal
  pip install pandas ERROR pythondudu 7 28,189 May-24-2022, 06:14 AM
Last Post: Marya_475
  Pandas Dataframe Filtering based on rows mvdlm 0 1,141 Apr-02-2022, 06:39 PM
Last Post: mvdlm
  Pandas dataframe: calculate metrics by year mcva 1 1,860 Mar-02-2022, 08:22 AM
Last Post: mcva
  Pandas dataframe comparing anto5 0 1,031 Jan-30-2022, 10:21 AM
Last Post: anto5
  PANDAS: DataFrame | Replace and others questions moduki1 2 1,438 Jan-10-2022, 07:19 PM
Last Post: moduki1
  PANDAS: DataFrame | Saving the wrong value moduki1 0 1,277 Jan-10-2022, 04:42 PM
Last Post: moduki1
  update values in one dataframe based on another dataframe - Pandas iliasb 2 7,824 Aug-14-2021, 12:38 PM
Last Post: jefsummers
  empty row in pandas dataframe rwahdan 3 2,157 Jun-22-2021, 07:57 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020