Фрейм данных df
:
Id timestamp C Date sig events1 Start Peak Timediff2 datadiff2 B
51253 51494 2020-01-27 06:22:08.330 19.5 2020-01-27 -1.0 0.0 NaN 1.0 NaN NaN NaN
51254 51495 2020-01-27 06:22:08.430 19.0 2020-01-27 1.0 1.0 0.0 0.0 NaN NaN NaN
51255 51496 2020-01-27 07:19:06.297 19.5 2020-01-27 1.0 0.0 1.0 0.0 3417.967 0.0 0.000000
51256 51497 2020-01-27 07:19:06.397 20.0 2020-01-27 1.0 0.0 0.0 0.0 3417.967 1.0 0.000293
51259 51500 2020-01-27 07:32:19.587 20.5 2020-01-27 1.0 0.0 0.0 0.0 793.290 1.0 0.001261
51260 51501 2020-01-27 07:32:19.687 21.0 2020-01-27
Я построил интерактивный график, используя:
import pandas as pd
import plotly.express as px
fig = px.line(x=df['Timestamp'], y=df['C'], hover_data=["B"])
fig.add_scatter(x=df['Timestamp'], y=df['C'], mode='markers', marker_color=df['A'], marker_size=5)
fig.update_layout(plot_bgcolor='#bababa', showlegend=False, width=2400, height=800)
fig.show()
Затем, чтобы добавить дополнительные данные наведения для столбца C
, я добавил hover_data=["C"]
:
fig = px.line(x=df['Timestamp'], y=df['B'], hover_data=["C"])
Возвращено
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-21-be5860c5172a> in <module>()
21 import plotly.express as px
22
---> 23 fig = px.line(x=df['Timestamp'], y=df['C'], hover_data=["B"])
24 fig.add_scatter(x=df['Timestamp'], y=df['C'], mode='markers', marker_color=df['A'], marker_size=5)
25
3 frames
/usr/local/lib/python3.6/dist-packages/plotly/express/_core.py in build_dataframe(args, attrables, array_attrables)
931 "DataFrame or an array is provided in the `data_frame` "
932 "argument. No DataFrame was provided, but argument "
--> 933 "'%s' is of type str or int." % field
934 )
935 # Check validity of column name
ValueError: String or int arguments are only possible when a DataFrame or an array is provided in the `data_frame` argument. No DataFrame was provided, but argument 'hover_data_0' is of type str or int.
Обновление:
Пробовал
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-21-be5860c5172a> in <module>()
21 import plotly.express as px
22
---> 23 fig = px.line(x=df['Timestamp'], y=df['C'], hover_data=df["B"])
24 fig.add_scatter(x=df['Timestamp'], y=df['C'], mode='markers', marker_color=df['A'], marker_size=5)
25
/usr/local/lib/python3.6/dist-packages/plotly/express/_core.py in build_dataframe(args, attrables, array_attrables)
986 else: # numpy array, list...
987 col_name = _check_name_not_reserved(field, reserved_names)
--> 988 if length and len(argument) != length:
989 raise ValueError(
990 "All arguments should have the same length. "
TypeError: object of type 'float' has no len()