【问题标题】:When I'm plotting bubble chart in plotly I'm getting an error当我在 plotly 中绘制气泡图时出现错误
【发布时间】:2021-07-19 01:27:23
【问题描述】:

我正在绘制气泡图。我的代码如下。

fig = px.scatter(data, x="gdp_per_capita", y="extreme_poverty",
             size="total_cases", color="continent",
                 hover_name="location")
fig.show()

我收到了这个错误

    Invalid element(s) received for the 'size' property of scattergl.marker
    Invalid elements include: [nan, nan, nan, nan, nan, nan, nan, nan, nan, nan]

The 'size' property is a number and may be specified as:
  - An int or float in the interval [0, inf]
  - A tuple, list, or one-dimensional numpy array of the above

我已经用过了

error_bad_lines=False

在导入数据时。

有没有办法解决这个错误? 谢谢。

【问题讨论】:

  • 确保要适应大小的数据是数字的。如果还有更多的 NA,请尝试将其替换为 0。

标签: python plotly-python bubble-chart


【解决方案1】:

您在数据框中有 nan 值。您需要删除这些值。

您可以在“total_cases”列中删除包含 nan 的行

data = data.dropna(subset=['total_cases'])

或者你可以用 0 填充 NA

data['total_cases'] = data.fillna(0)

【讨论】:

    猜你喜欢
    • 2020-10-31
    • 1970-01-01
    • 1970-01-01
    • 2022-07-12
    • 2023-04-08
    • 2018-01-24
    • 2021-11-30
    • 2021-09-03
    • 1970-01-01
    相关资源
    最近更新 更多