0
from textblob import TextBlob as tb
from sqlalchemy import create_engine
import pandas as pd

first i had created engine using sqlalchemy as engine=create_engine("mysql+mysqldb://root:ja@localhost:3306/listing")

Then i used pandas read_sql command to read the data from database.

df=pd.read_sql('select locationId,text from location_reviews',engine)

I am getting this error when trying to convert the text column from string to textblob UnicodeDecodeError: 'ascii' codec can't decode byte 0x93 in position 284: ordinal not in range(128) I am using sqlalchemy and df = pd.read_sql(query,engine) for reading the data from sql. Then i tried to convert the text column in textblob using

df['text']=df.text.apply(lambda x: tb(x))

and getting the above error.

jarry jafery
  • 1,018
  • 1
  • 14
  • 25
  • Your sql contains non-ascii data. How did you create your data frame? Show your code (or better yet, a simplified _working_ example). Which line gives you the error? Show the stack trace. Could the problem be when you create the dataframe? – alexis May 29 '17 at 08:39

1 Answers1

0

This implies you've got a unicode character in the text that you're trying to convert to TextBlob. You might want to try to make sure no unicode character sneaks by.

Try unidecode, something along these lines:

from unidecode import unidecode
df['text']=df.text.apply(lambda x: tb(unidecode(x)))
ystark
  • 565
  • 9
  • 18
  • not working giving back same error – jarry jafery May 29 '17 at 07:15
  • Then the error is possibly occurring before this point in the code. Can you figure out where the error occurs? You might want to apply unidecode to the entire df. – ystark May 29 '17 at 07:41
  • Solved the problem using https://stackoverflow.com/questions/18649512/unicodedecodeerror-ascii-codec-cant-decode-byte-0xe2-in-position-13-ordinal – jarry jafery May 29 '17 at 19:33