I have a pandas dataframe like this
0 15.55
1 15.55
2 15.55
3 15.55
4 20.84
Name: Y1, dtype: float64
I want to convert the values of Y1 to categorical (i.e) if its greater than 18.25, I want it 1 else 0
Can someone please help me on how to do it
This is what i tried so far
for temp in TRAIN_ID1:
train_ID1.loc[(train_ID1['Y1'] > 18.250000), 'Y1'] = 1
train_ID1.loc[(train_ID1['Y1'] < 18.250000), 'Y1'] = 0
But im getting an error
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
TypeError: an integer is required
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
<ipython-input-118-2cccb791d834> in <module>()
1 for temp in train_ID1:
----> 2 train_ID1.loc[(train_ID1['Y1'] > 18.250000), 'Y1'] = 1
3 train_ID1.loc[(train_ID1['Y1'] < 18.250000), 'Y1'] = 0
~\Anaconda3\envs\deeplearning\lib\site-packages\pandas\core\series.py in __getitem__(self, key)
621 key = com._apply_if_callable(key, self)
622 try:
--> 623 result = self.index.get_value(self, key)
624
625 if not is_scalar(result):
~\Anaconda3\envs\deeplearning\lib\site-packages\pandas\core\indexes\base.py in get_value(self, series, key)
2558 try:
2559 return self._engine.get_value(s, k,
-> 2560 tz=getattr(series.dtype, 'tz', None))
2561 except KeyError as e1:
2562 if len(self) > 0 and self.inferred_type in ['integer', 'boolean']:
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
KeyError: 'Y1'