Skip to content

Instantly share code, notes, and snippets.

@farhanhubble
Created March 6, 2019 11:04
Show Gist options
  • Save farhanhubble/71afb78e4303460fbfdb19757e271ba7 to your computer and use it in GitHub Desktop.
Save farhanhubble/71afb78e4303460fbfdb19757e271ba7 to your computer and use it in GitHub Desktop.
TypeError Traceback (most recent call last)
<ipython-input-44-a553646a889c> in <module>
22 for i, samples in enumerate([samples_1, samples_10, samples_100]):
23 results[clf_name][i] = \
---> 24 train_predict(clf, samples, X_train, y_train, X_test, y_test)
25
26 # Run metrics visualization for the three supervised learning models chosen
<ipython-input-36-2fd67492e721> in train_predict(learner, sample_size, X_train, y_train, X_test, y_test)
19 # TODO: Fit the learner to the training data using slicing with ‘sample_size’ using .fit(training_features[:], training_labels[:])
20 start = time() # Get start time
---> 21 learner.fit(X_train[:sample_size],y_train[:sample_size])
22 end = time() # Get end time
23
/anaconda3/lib/python3.7/site-packages/pandas/core/frame.py in __getitem__(self, key)
2674
2675 # see if we can slice the rows
-> 2676 indexer = convert_to_index_sliceable(self, key)
2677 if indexer is not None:
2678 return self._getitem_slice(indexer)
/anaconda3/lib/python3.7/site-packages/pandas/core/indexing.py in convert_to_index_sliceable(obj, key)
2324 idx = obj.index
2325 if isinstance(key, slice):
-> 2326 return idx._convert_slice_indexer(key, kind=‘getitem’)
2327
2328 elif isinstance(key, compat.string_types):
/anaconda3/lib/python3.7/site-packages/pandas/core/indexes/base.py in _convert_slice_indexer(self, key, kind)
1725 if self.is_integer() or is_index_slice:
1726 return slice(self._validate_indexer(‘slice’, key.start, kind),
-> 1727 self._validate_indexer(‘slice’, key.stop, kind),
1728 self._validate_indexer(‘slice’, key.step, kind))
1729
/anaconda3/lib/python3.7/site-packages/pandas/core/indexes/base.py in _validate_indexer(self, form, key, kind)
4143 pass
4144 elif kind in [‘iloc’, ‘getitem’]:
-> 4145 self._invalid_indexer(form, key)
4146 return key
4147
/anaconda3/lib/python3.7/site-packages/pandas/core/indexes/base.py in _invalid_indexer(self, form, key)
1861 “indexers [{key}] of {kind}“.format(
1862 form=form, klass=type(self), key=key,
-> 1863 kind=type(key)))
1864
1865 def get_duplicates(self):
TypeError: cannot do slice indexing on <class ‘pandas.core.indexes.numeric.Int64Index’> with these indexers [361.77] of <class ‘float’>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment