I'm new to scattertext and have written the code which should produce an interactive html visualisation.
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"))
However, the code that I have written, following a template online, throws an assertion error and as I'm a newbie at software development i'm struggling to understand where Im going wrong.
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
Appreciate it may be hard to offer advice with such limited info but the code & error details are below if anyone can spot anything!
Make sure at least in of the values in the sentiment column of your data frame is the exact string "1".