我正在尝试使用散点图来绘制时间序列数据。
我收到此错误。我的代码中没有任何布尔值,所以我不明白为什么它无法处理此代码。
ValueError:索引的真实值不明确。使用a.empty,a.bool(),a.item(),a.any()或a.all()。
我已经查看了数据帧的数据类型,并转置并尝试编辑时间轴数据。 Dtype是dtype('0')。
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
lambdaA:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./lambda_a_dir/
Handler: lambda_a.lambda_handler
Runtime: python3.6
lambdaB:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./lambda_b_dir/
Handler: lambda_b.lambda_handler
Runtime: python3.6
不幸的是,最终结果是错误代码。
https://www.plotly.express/ <-这是我正在遵循的密谋速成教程。
import pandas as pd
import numpy as np
import plotly_express as px
df = pd.read_excel('FreewayFDSData.xlsx', 'Volume')
df = df.set_index("Row Labels")
detector =df.columns
time = df.index
px.scatter(df, x=detector,y=time)
答案 0 :(得分:2)
我不认为您可以使用plotly_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)
答案 1 :(得分:1)
现在在我的手机上,但希望尽快提供帮助,以便稍后处理正确的格式。
数据类型肯定是这里的问题。您要设置time = df.index
,然后再在px.scatter(df, x=detector,y=time)
中为y分配时间。 df.index
的第一个值为36745_P1
。因此,据我所知,这是您的问题。您真的想绘制x和y的值是什么?