I am new to Python and am learning few things.
I have a dataset which is coded with strings. A list columns contains the names of all the columns in the list.
columns = ['median', 'p25th', 'p75th']
In this dataset, numbers are stored in the form of strings. Some of the columns do not carry numbers & are represented as UN like this:
['110000' '75000' '73000' '70000' '65000' 'UN' '62000']
['95000' '55000' '50000' '43000' 'UN' '31500' '48000']
['125000' '90000' '105000' '80000' '75000' '102000' 'UN' '109000']
I need to replace UN with NaN using np.nan. I used this code below:
for column in columns:
recent_grads.loc[column =='UN', column] = np.nan
But I keep getting this error:
Traceback (most recent call last):
File "", line 15, in recent_grads.loc[column =='UN', column] = np.nan
File "", line 194, in setitem self._setitem_with_indexer(indexer, value) File "", line 332, in _setitem_with_indexer key, _ = convert_missing_indexer(idx)
File "", line 2049, in convert_missing_indexer raise KeyError("cannot use a single bool to index into setitem") KeyError: 'cannot use a single bool to index into setitem'
Can you please tell where I am going wrong? Sorry if this sounds too basic.