【问题标题】:My Plotly animated chart is saying The 'name' property is a string and must be specified as String我的 Plotly 动画图表说“名称”属性是一个字符串,必须指定为字符串
【发布时间】:2021-10-27 15:32:50
【问题描述】:

Plotly 抛出了一个看起来很奇怪的错误,IN 不太明白。

这是我的代码。

print(df_geo.dtypes)

import plotly.express as px
px.scatter(df_geo, x="Exp_Month", y="Rev_Month", animation_frame="Volume", animation_group="Site_Name",
           size="Volume", color="Market", hover_name="Market",
           log_x=True, size_max=55, range_x=[100,1000000], range_y=[2,100000])

这是错误信息。

Invalid value of type {typ} received for the '{name}' property of {pname}

ValueError: 
    Invalid value of type 'pandas._libs.tslibs.timestamps.Timestamp' received for the 'name' property of frame
        Received value: Timestamp('2020-01-01 00:00:00')

    The 'name' property is a string and must be specified as:
      - A string
      - A number that will be converted to a string

我想也许 Exp_Month 或 Rev_Month 有一些奇怪的字符,所以我升序和降序排序,但没有发现任何错误。此外,这两个字段都是 datetime64[ns]。 Volume 是 float64,Site_Name 和 Market 都是对象。关于我在这里做错了什么有什么想法吗?

【问题讨论】:

    标签: python python-3.x plotly


    【解决方案1】:

    我猜这个错误与时间格式有关。当我以不同的日期格式传递时,它起作用了。这是我的解决方案。

    from datetime import datetime
    def convert_datetime(dt):
        return datetime.strftime(dt, '%Y-%m-%d')
    
    df_geo['Exp_Month']= df_geo['Exp_Month'].apply(convert_datetime)
    df_geo['Rev_Month']= df_geo['Rev_Month'].apply(convert_datetime)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-31
      相关资源
      最近更新 更多