0

My code:

top_n_words_lsa = get_top_n_words(15, lsa_keys,small_document_term_matrix, small_count_vectorizer)

for i in range(len(top_n_words_lsa)):
    print("Topic {}: ".format(i+1), top_n_words_lsa[i])

The error:

UnicodeEncodeError                        Traceback (most recent call last)
<ipython-input-74-54b25b105242> in <module>()
----> 1 top_n_words_lsa = get_top_n_words(15, lsa_keys,small_document_term_matrix, small_count_vectorizer)
      2 
      3 for i in range(len(top_n_words_lsa)):
      4     print("Topic {}: ".format(i+1), top_n_words_lsa[i])

<ipython-input-62-3df6ba694883> in get_top_n_words(n, keys, document_term_matrix, count_vectorizer)
     23             temp_word_vector[:,index] = 1
     24             the_word = count_vectorizer.inverse_transform(temp_word_vector)[0][0]
---> 25             topic_words.append(the_word.encode('ascii').decode('utf-8'))
     26         top_words.append(" ".join(topic_words))
     27     return top_words

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
Robert
  • 7,394
  • 40
  • 45
  • 64
  • 1
    Does this answer your question? [UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 20: ordinal not in range(128)](https://stackoverflow.com/questions/9942594/unicodeencodeerror-ascii-codec-cant-encode-character-u-xa0-in-position-20) – Ulrich Eckhardt Dec 06 '21 at 18:21
  • Please do a bit of research up front first: I located that duplicate by just searching for the error message. As a new user here, please also take the [tour] and read [ask]. – Ulrich Eckhardt Dec 06 '21 at 18:22

0 Answers0