This is the error i’m getting
JavaScript
x
8
1
TypeError Traceback (most recent call last)
2
Input In [141], in <cell line: 2>()
3
1 repl = {'Y':'1', 'N':'0'}
4
----> 2 prices_dataframe['col_state'] = prices_dataframe['col_state'].replace(repl, regex=True)
5
6
TypeError: 'bool' object is not subscriptable
7
8
This is what i have tried
repl = {‘Y’:’1′, ‘N’:’0′} prices_dataframe[‘col_state’] = prices_dataframe[‘col_state’].replace(repl, regex=True)
Advertisement
Answer
The replace()
method is unique to strings, and at some point the value you are trying to replace is being a boolean (True or False). If you still want to replace it, you can transform the value into a string:
JavaScript
1
2
1
prices_dataframe['col_state'] = str(prices_dataframe['col_state']).replace(repl, regex=True)
2