When trying to get a value count for some columns in my data frame, I get this error saying the index must be monotonic, but the is_monotonic property says that the index is already that way. The majority of the columns in the dataframe after importing a csv don't return this error, but a few do.
I've tried some of the tactics mentioned here, but can't seem to get it working.
Doing this:
import pandas as pd
data = pd.read_csv('info/train.csv')
print('Monotonic?: ', data['net_booking_value_monthly'].index.is_monotonic)
print(data['net_booking_value_monthly'].value_counts(dropna=False)[:10])
Gives me this:
Monotonic?: True
Traceback (most recent call last):
File "/Users/person/venvs/science/lib/python3.6/site-packages/pandas/core/indexes/base.py", line 3484, in get_slice_bound
return self._searchsorted_monotonic(label, side)
File "/Users/person/venvs/science/lib/python3.6/site-packages/pandas/core/indexes/base.py", line 3443, 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:
etc. etc.
It's doing my head in that the is_monotonic property is True, but the value count returns this error. The input CSV file is pretty big and I can't share it, but is there anything I should look for in there that would cause this?
Pandas version is 0.20.2.