2

I am trying to tokenize tweet but I get the error: TypeError: expected string or bytes-like object

I am cleaning tweets for use in ml, so am carryout tokenization.

# remove twitter handles (@user)
def remove_pattern(input_txt, pattern):
    r = re.findall(pattern, input_txt)
    for i in r:
        input_txt = re.sub(i, '', input_txt)

    return input_txt  

# remove twitter handles and create new column with clean tweet
data_df['cleaned_tweet'] = np.vectorize(remove_pattern)(data_df['text'], "@[\w]*")
2
  • 2
    Please include the exact error message. Commented May 6, 2019 at 12:58
  • Also include more code, to see what types are in Input of your code Commented May 6, 2019 at 14:46

1 Answer 1

4

This is because the twitter text is not a string, it is an object, you have to convert object into string, write: input_txt =str(input_txt).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.