下面是我的代码,并且看到相同的值错误,请提出建议。
import pandas as pd
import plotly.express as px
def create_graphs(excel_path,html_path):
df = pd.read_excel(excel_path)
fig = px.line(df, x = "Date", y = "CPU_excluding_jmeter", title='Metrics')
fig.show()
with open(html_path, 'a') as f:
f.write(fig.to_html(full_html=True))
f.close()
return
ValueError Traceback (most recent call last)
<ipython-input-93-1643babef93d> in <module>
29 return
30
---> 31 create_graphs('/home/karthika.s1/Desktop/Discovery_system_profile-Thu-Mar-19-11-03-35-UTC-20201.xls',"/home/karthika.s1/Desktop/HTML/graph3.html",)
<ipython-input-93-1643babef93d> in create_graphs(excel_path, html_path)
7
8 df = pd.read_excel(excel_path)
----> 9 fig = px.line(df, x = "Date", y = "Memory", title='Metrics')
10 fig.show()
11
~/.local/lib/python3.6/site-packages/plotly/express/_chart_types.py in line(data_frame, x, y, line_group, color, line_dash, hover_name, hover_data, custom_data, text, facet_row, facet_col, facet_col_wrap, error_x, error_x_minus, error_y, error_y_minus, animation_frame, animation_group, category_orders, labels, color_discrete_sequence, color_discrete_map, line_dash_sequence, line_dash_map, log_x, log_y, range_x, range_y, line_shape, render_mode, title, template, width, height)
212 a polyline mark in 2D space.
213 """
--> 214 return make_figure(args=locals(), constructor=go.Scatter)
215
216
~/.local/lib/python3.6/site-packages/plotly/express/_core.py in make_figure(args, constructor, trace_patch, layout_patch)
1363
1364 args, trace_specs, grouped_mappings, sizeref, show_colorbar = infer_config(
-> 1365 args, constructor, trace_patch
1366 )
1367 grouper = [x.grouper or one_group for x in grouped_mappings] or [one_group]
~/.local/lib/python3.6/site-packages/plotly/express/_core.py in infer_config(args, constructor, trace_patch)
1208 all_attrables += [group_attr]
1209
-> 1210 args = build_dataframe(args, all_attrables, array_attrables)
1211 if constructor in [go.Treemap, go.Sunburst] and args["path"] is not None:
1212 args = process_dataframe_hierarchy(args)
~/.local/lib/python3.6/site-packages/plotly/express/_core.py in build_dataframe(args, attrables, array_attrables)
972 "\n To use the index, pass it in directly as `df.index`."
973 )
--> 974 raise ValueError(err_msg)
975 if length and len(df_input[argument]) != length:
976 raise ValueError(
ValueError: Value of 'y' is not the name of a column in 'data_frame'.
Expected one of ['Date', ' Memory', 'CPU', ' Memory1', ' SVC-GO-CONTENT API CPU Load', ' SVC-GO-CONTENT API Memory', ' Migration API load in ', ' Migration API Memory in ', ' Events API Load in ', ' Events API Memory in ', ' Images API Load in ', ' Images API memory in ', ' Layouts API load in ', ' Layouts API memory in ', ' Recommandations API Load', ' Recommandations API memory', ' Sharks API Load', ' Sharks API memory', ' UpNext API Load', ' UpNext API memory', ' configurations API Load', ' configurations API Memory', ' Markers API load', ' Markers API memory', ' Users API Load', ' Users API Memory', ' Entitlement API Load', ' Entitlement API Memory', ' jenkins cpu', ' jenkins memory', ' CPU_excluding_jmeter'] but received: Memory
当我们使用“ CPU”列以外的其他列时遇到此错误
错误显示您有专栏
Expected one of ['Date', ' Memory', 'CPU', ' Memory1', ...
所以列名开头有空格,您必须要尊重它
y=' Memory'