Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 strange error from pandas dataframe
#1
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.
Error:
Traceback (most recent call last): File "C:\Users\crovn\AppData\Roaming\Python\Python38\site-packages\pandas\core\indexes\base.py", 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\base.py", 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\RegressionSound2.py", line 101, in <module> example_batch = normed_train_data[:10] File "C:\Users\crovn\AppData\Roaming\Python\Python38\site-packages\pandas\core\frame.py", line 2779, in __getitem__ indexer = convert_to_index_sliceable(self, key) File "C:\Users\crovn\AppData\Roaming\Python\Python38\site-packages\pandas\core\indexing.py", 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\numeric.py", 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\base.py", 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\base.py", 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\base.py", line 4848, in get_slice_bound raise err File "C:\Users\crovn\AppData\Roaming\Python\Python38\site-packages\pandas\core\indexes\base.py", line 4842, in get_slice_bound slc = self.get_loc(label) File "C:\Users\crovn\AppData\Roaming\Python\Python38\site-packages\pandas\core\indexes\numeric.py", 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\base.py", 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)
Quote
#2
If you want to get the first 10 rows of the dataframe, you need to use iloc, e.g.
normed_train_data.iloc[:10]
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Pandas DataFrame not updating HelpMePlease 3 268 Jul-11-2020, 07:19 PM
Last Post: jefsummers
  Pandas DataFrame visual Truman 8 338 Jul-10-2020, 06:11 AM
Last Post: hussainmujtaba
  Pandas DataFrame and unmatched column sritsv19 0 279 Jul-07-2020, 12:52 PM
Last Post: sritsv19
  Pandas DataFrame Concatenate problems Kristenl2784 1 200 Jul-01-2020, 01:28 AM
Last Post: hussainmujtaba
  Difference of two columns in Pandas dataframe zinho 2 505 Jun-17-2020, 03:36 PM
Last Post: zinho
  error bars with dataframe and pandas Hucky 4 428 Apr-27-2020, 02:02 AM
Last Post: Hucky
  error : value of a DataFrame is ambiguous Sonata 1 327 Apr-24-2020, 05:40 PM
Last Post: anbu23
  Python Pandas DataFrame Help AmericanEagle1989 1 273 Apr-12-2020, 12:37 PM
Last Post: AmericanEagle1989
  How does pyplot know what was plotted by the output of pandas.DataFrame(...).cumprod( codeowl 2 305 Mar-28-2020, 08:27 AM
Last Post: j.crater
  pip install pandas ERROR pythondudu 6 6,867 Mar-26-2020, 07:49 PM
Last Post: snippsat

Forum Jump:


Users browsing this thread: 1 Guest(s)