【问题标题】:Assertion Error when producing ScatterText Visualisation生成 ScatterText 可视化时出现断言错误
【发布时间】:2021-07-06 15:23:20
【问题描述】:

我是 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

感谢您可能很难在信息有限的情况下提供建议,但如果有人能发现任何内容,代码和错误详细信息如下!

【问题讨论】:

  • 大概category="1" 是问题所在。除了"1" 之外,它似乎期待一个不同的值。 (也许是"Sentiment"?)
  • @0x5453 嗯,我明白你的意思,根据错误消息,“情绪”会抛出相同的错误消息:/ 我会为该变量尝试一些其他可能的值。

标签: python python-3.x data-visualization scatter-plot scatter3d


【解决方案1】:

确保数据框的情绪列中的值中至少有一个是确切的字符串“1”。

【讨论】:

  • 列中的值是整数,所以我将它们全部转换为字符串,瞧!非常感谢您的指点。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-02
  • 2020-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多