I have a series of tokens that I am attempting to vectorize. However, I keep getting the error message "TypeError: expected string or bytes-like object".
My text tokens:
tokens_raw
0 [kitchen, getting, children, ready, school, ru...
1 [shanghai, appointed, manager, taco, bell, chi...
2 [april, uber, announced, acquisition, otto, sa... etc.....
My code:
# list of tokens from text documents
tokens_raw = articles_df_60k['processed_content']
# create the transform
vectorizer = TfidfVectorizer(sublinear_tf=True, min_df=5, lowercase=False,
encoding='latin-1', ngram_range=(1, 2))
# tokenize and build vocab
vectorizer.fit(tokens_raw)
# summarize
print("vocabulary count:", vectorizer.vocabulary_, sep='\n')
print('\n')
print("inverse document frequency:", vectorizer.idf_, sep='\n')
print('\n')
# encode document
vector = vectorizer.transform(tokens_raw)
# summarize encoded vector
print("vector shape:", vector_raw.shape, sep='\n')
print('\n')
print("vector array:", vector_raw.toarray(), sep='\n')
Again, the error message is "TypeError: expected string or bytes-like object". It works if I just input
tokens_raw[0]
however, trying to apply it to all the rows turns back the error message. Any guidance, explanations, or solutions would be much appreciated.