I'm trying to make sure there is any string issue in one column called Comment
from my dataframe headlamp
The reason is because I'm trying to export the dataframe later to excel by using .to_excel()
and the unicode error is always raised.
I have read a lot of materials online and also here to solve this issue, however, I couldn't manage it so far.
I tried to solve by using the encode()
like the code below, however, I still having the same issue.
headlamp = part_dataframe(ro, 'PN 3D', '921')
headlamp['Comment'] = headlamp.Comment.apply(lambda x: x.encode('ascii',
'ignore'))
headlamp['word'] = headlamp.Comment.str.split().apply(lambda x:
pd.value_counts(x).to_dict())
len(headlamp)
Error:
UnicodeDecodeError Traceback (most recent call last)
<ipython-input-57-29454fde650e> in <module>()
1 headlamp = part_dataframe(ro, 'PN 3D', '921')
----> 2 headlamp['Comment'] = headlamp.Comment.apply(lambda x:
x.encode('ascii', 'ignore'))
3 headlamp['word'] = headlamp.Comment.str.split().apply(lambda x:
4 pd.value_counts(x).to_dict())
5 len(headlamp)
C:\Users\Rafael\Anaconda2\envs\gl-env\lib\site-
packages\pandas\core\series.pyc in apply(self, func, convert_dtype, args,
**kwds)
2218 else:
2219 values = self.asobject
-> 2220 mapped = lib.map_infer(values, f, convert=convert_dtype)
2221
2222 if len(mapped) and isinstance(mapped[0], Series):
pandas\src\inference.pyx in pandas.lib.map_infer (pandas\lib.c:62658)()
<ipython-input-57-29454fde650e> in <lambda>(x)
1 headlamp = part_dataframe(ro, 'PN 3D', '921')
----> 2 headlamp['Comment'] = headlamp.Comment.apply(lambda x:
x.encode('ascii', 'ignore'))
3 headlamp['word'] = headlamp.Comment.str.split().apply(lambda x:
4 pd.value_counts(x).to_dict())
5 len(headlamp)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb4 in position 71:
ordinal not in range(128)
I'm complete lost on this matter, therefore, any help will be highly appreciated.
I'm using Jupyter Ipython