Python 使用plotly绘制时间序列数据时出错,真值不明确

Python 使用plotly绘制时间序列数据时出错,真值不明确,python,pandas,plotly,Python,Pandas,Plotly,我正在尝试使用plotly express绘制时间序列数据 我收到这个错误。我的代码中没有任何布尔值,所以我不明白为什么它不能处理这个代码 ValueError:索引的真值不明确。使用a.empty、a.bool()、a.item()、a.any()或a.all() 我已经查看了数据帧的数据类型,并对时间轴数据进行了转置和编辑。Dtype是Dtype('0') 不幸的是,最终结果是错误代码 现在正在我的手机上,但希望尽快提供帮助,以便稍后处理正确的格式设置 数据类型似乎确实是这里的问题。您正在

我正在尝试使用plotly express绘制时间序列数据

我收到这个错误。我的代码中没有任何布尔值,所以我不明白为什么它不能处理这个代码

ValueError:索引的真值不明确。使用a.empty、a.bool()、a.item()、a.any()或a.all()

我已经查看了数据帧的数据类型,并对时间轴数据进行了转置和编辑。Dtype是Dtype('0')

不幸的是,最终结果是错误代码


现在正在我的手机上,但希望尽快提供帮助,以便稍后处理正确的格式设置


数据类型似乎确实是这里的问题。您正在设置
time=df.index
,然后在
px.scatter(df,x=detector,y=time)中将时间分配给y
df.index
的第一个值是
36745_P1
。就我目前所知,这是你的问题。您真正想要绘制x和y的哪些值?

我认为您不能使用plotly\u express解决您的问题,因为
x
y
应该是字符串。检查px.scatter的输出

px.scatter?
data_frame: A 'tidy' `pandas.DataFrame`
x: (string, name of column in `data_frame`) Values from this column are used to position marks along the x axis in cartesian coordinates.
y: (string, name of column in `data_frame`) Values from this column are used to position marks along the y axis in cartesian coordinates.
如果安装plotly_express,您也可以使用plotly

import plotly.offline as py
import plotly.graph_objs as go
import pandas as pd

# here I'm using your df.head().to_dict() as dct
df = pd.DataFrame(dct)
traces = [go.Scatter(x=df.index,
                     y=df[col],
                     name=col)
          for col in df.columns]


py.iplot(traces)

如果可能的话,我想把它们全部绘制出来,因此所有检测器与所有时间要使用Plotly Express,您必须重新设置数据的形状,使其具有三列:时间、检测器、值。对于您拥有的数据形状,您可能希望使用
袖扣
来执行
df.iplot(…)
。您好,我是Plotly Express的作者,目前确实如此。我们正在考虑可能添加传递df.index或df.my_列的功能。。。讨论在此期间,我添加了更严格的验证和更好的错误消息以避免此问题:)
px.scatter?
data_frame: A 'tidy' `pandas.DataFrame`
x: (string, name of column in `data_frame`) Values from this column are used to position marks along the x axis in cartesian coordinates.
y: (string, name of column in `data_frame`) Values from this column are used to position marks along the y axis in cartesian coordinates.
import plotly.offline as py
import plotly.graph_objs as go
import pandas as pd

# here I'm using your df.head().to_dict() as dct
df = pd.DataFrame(dct)
traces = [go.Scatter(x=df.index,
                     y=df[col],
                     name=col)
          for col in df.columns]


py.iplot(traces)