生成 ScatterText 可视化时出现断言错误
Assertion Error when producing ScatterText Visualisation
我是 scattertext 的新手并且已经编写了应该产生交互式 html 可视化的代码。
import spacy
import pandas as pd
import scattertext as st
twitterData = pd.read_csv("stock_data.csv")
twitterData.dtypes
nlp = spacy.load("en_core_web_sm")
corpus = st.CorpusFromPandas(
twitterData, category_col="Sentiment", text_col="Text", nlp=nlp
).build()
sent = st.produce_scattertext_explorer(
corpus,
category="1",
category_name="Positive",
not_category_name="Negative",
width_in_pixels=1000,
)
open("StockMarketSentiment.html", "wb").write(html.encode("utf-8"))
但是,我按照在线模板编写的代码会抛出断言错误,因为我是软件开发的新手,所以我很难理解哪里出了问题。
Traceback (most recent call last):
File "/Users/lukeashton/PycharmProjects/Project/venv/Visualiser.py", line 15, in <module>
sent = st.produce_scattertext_explorer(corpus,
File "/Users/lukeashton/PycharmProjects/Project/venv/lib/python3.8/site-packages/scattertext/__init__.py", line 594, in produce_scattertext_explorer
scatter_chart_data = scatter_chart_explorer.to_dict(
File "/Users/lukeashton/PycharmProjects/Project/venv/lib/python3.8/site-packages/scattertext/ScatterChartExplorer.py", line 115, in to_dict
json_data = ScatterChart.to_dict(self,
File "/Users/lukeashton/PycharmProjects/Project/venv/lib/python3.8/site-packages/scattertext/ScatterChart.py", line 276, in to_dict
assert category in all_categories
AssertionError
Process finished with exit code 1
感谢可能很难以如此有限的信息提供建议,但代码和错误详细信息如下,如果有人能发现任何东西!
确保数据框的情绪列中至少有一个值是准确的字符串“1”。
我是 scattertext 的新手并且已经编写了应该产生交互式 html 可视化的代码。
import spacy
import pandas as pd
import scattertext as st
twitterData = pd.read_csv("stock_data.csv")
twitterData.dtypes
nlp = spacy.load("en_core_web_sm")
corpus = st.CorpusFromPandas(
twitterData, category_col="Sentiment", text_col="Text", nlp=nlp
).build()
sent = st.produce_scattertext_explorer(
corpus,
category="1",
category_name="Positive",
not_category_name="Negative",
width_in_pixels=1000,
)
open("StockMarketSentiment.html", "wb").write(html.encode("utf-8"))
但是,我按照在线模板编写的代码会抛出断言错误,因为我是软件开发的新手,所以我很难理解哪里出了问题。
Traceback (most recent call last):
File "/Users/lukeashton/PycharmProjects/Project/venv/Visualiser.py", line 15, in <module>
sent = st.produce_scattertext_explorer(corpus,
File "/Users/lukeashton/PycharmProjects/Project/venv/lib/python3.8/site-packages/scattertext/__init__.py", line 594, in produce_scattertext_explorer
scatter_chart_data = scatter_chart_explorer.to_dict(
File "/Users/lukeashton/PycharmProjects/Project/venv/lib/python3.8/site-packages/scattertext/ScatterChartExplorer.py", line 115, in to_dict
json_data = ScatterChart.to_dict(self,
File "/Users/lukeashton/PycharmProjects/Project/venv/lib/python3.8/site-packages/scattertext/ScatterChart.py", line 276, in to_dict
assert category in all_categories
AssertionError
Process finished with exit code 1
感谢可能很难以如此有限的信息提供建议,但代码和错误详细信息如下,如果有人能发现任何东西!
确保数据框的情绪列中至少有一个值是准确的字符串“1”。