3 回答

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超13個(gè)贊
可能不是解決它的最優(yōu)雅的方法,但在你選擇你的點(diǎn)之后,你可以輸入:
d = t.to_dict() df = pd.DataFrame(d['data'][0]['cells']['values'], index =d['data'][0]['header']['values']).T
t 是類型plotly.graph_objs._figurewidget.FigureWidget
我使用 jupyter notebook,所以我在代碼下方的一個(gè)單元格中編寫了這些代碼行,我得到了一個(gè)包含所選事件的新 df

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超13個(gè)贊
假設(shè)以下代碼突出顯示您關(guān)心的點(diǎn):
def selection_fn(trace,points,selector): t.data[0].cells.values = [df.loc[points.point_inds][col] for col in ['ID','Classification','Driveline','Hybrid']]
更改它以返回?cái)?shù)據(jù)框:
def selection_fn(trace,points,selector): return pd.df([df.loc[points.point_inds][col] for col in ['ID','Classification','Driveline','Hybrid'] if col in {selection}])
列表推導(dǎo)需要更改為僅循環(huán)您要返回的點(diǎn)。文檔中的示例列表理解:
[(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]

TA貢獻(xiàn)1854條經(jīng)驗(yàn) 獲得超8個(gè)贊
更好的解決方案:
def selection_fn(trace, points, selector):
t.data[0].cells.values = [
df.loc[points.point_inds][col]
for col in ["ID", "Classification", "Driveline", "Hybrid"]]
selection_fn.df1 = df.loc[points.point_inds]
print(selection_fn.df1)
添加回答
舉報(bào)