简体   繁体   English

TypeError:需要一个 integer(获取类型 str)LDAvis

[英]TypeError: an integer is required (got type str) LDAvis

I am new to Python and Data Science in general.我是 Python 和数据科学的新手。 I am trying to work on some LDA visualizations, but for some reason I keep getting the following error.我正在尝试处理一些 LDA 可视化,但由于某种原因,我不断收到以下错误。 Any help would be greatly appreciated!任何帮助将不胜感激!

Type Error: an integer is required (got type str)类型错误:需要 integer(获取类型 str)

import os
LDAvis_data_filepath = os.path.join('./ldavis_prepared_'+str(number_topics))
# # this is a bit time consuming - make the if statement True
# # if you want to execute visualization prep yourself
if 1 == 1:
    LDAvis_prepared = sklearn_lda.prepare(lda, count_data, count_vectorizer)
with open(LDAvis_data_filepath, 'wb', 'utf-8') as f:
        pickle.dump(LDAvis_prepared, f)
        #load the pre-prepared pyLDAvis data from disk
with open(LDAvis_data_filepath,'rb', 'utf-8') as f:
    pickle.dump(LDAvis_prepared, f)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-110-4459335c1578> in <module>
----> 1 with open(LDAvis_data_filepath, 'wb', 'utf-8') as f:
      2         pickle.dump(LDAvis_prepared, f)
      3         # load the pre-prepared pyLDAvis data from disk
      4 with open(LDAvis_data_filepath,'rb', 'utf-8') as f:
      5     pickle.dump(LDAvis_prepared, f)

TypeError: an integer is required (got type str)

The encoding is the 4th parameter to open , not the 3rd.编码是open的第四个参数,而不是第三个。 Two minutes looking at the documentation would have told you that.看文档两分钟就会告诉你这一点。 And your second pickle call should almost certainly be load , not dump .而且您的第二个pickle调用几乎可以肯定是load ,而不是dump

with open(LDAvis_data_filepath, 'wb', encoding='utf-8') as f:
    pickle.dump(LDAvis_prepared, f)
    #load the pre-prepared pyLDAvis data from disk
with open(LDAvis_data_filepath, 'rb', encoding='utf-8') as f:
    pickle.load(LDAvis_prepared, f)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:使用pickle需要一个整数(得到类型_io.BufferedWriter) - TypeError: an integer is required (got type _io.BufferedWriter) using pickle 类型错误:加载 pickle 文件时需要 integer(获取类型字节) - TypeError: an integer is required (got type bytes) while loading the pickle file Python TypeError:整数很奇怪 - Python TypeError: an integer is required weird TypeError:需要一个类似字节的对象,而在用pickle加载时不是&#39;str&#39; - TypeError: a bytes-like object is required, not 'str' while loading with pickle 泡菜(无文件IO):TypeError:需要一个类似字节的对象,而不是“ str” - Pickle (no file IO): TypeError: a bytes-like object is required, not 'str' python:TypeError:+不支持的操作数类型:&#39;numpy.ndarray&#39;和&#39;str&#39; - python : TypeError: unsupported operand type(s) for +: 'numpy.ndarray' and 'str' TypeError:在Python 3中打开Python 2 Pickle文件时,需要一个类似字节的对象,而不是'str' - TypeError: a bytes-like object is required, not 'str' when opening Python 2 Pickle file in Python 3 错误消息:TypeError:需要一个类似字节的对象,而不是在Python中使用Pickle接收到的“ str” - Error message: TypeError: a bytes-like object is required, not 'str' received using Pickle in Python 代码适用于Python 2但不适用于Python3 TypeError:需要类似字节的对象,而不是&#39;str&#39; - Code works in Python 2 but not Python3 TypeError: a bytes-like object is required, not 'str' 泡菜错误-需要整数 - pickle error - integer required
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM