我想使用ipywidget以交互方式显示熊猫数据帧。到目前为止,代码获取一些选择,然后进行一些计算。对于此示例情况,它实际上并不使用输入标签。但是,我的问题是,当我想显示熊猫数据帧时,它不会被视为小部件。但是,我如何使用小部件很好地显示熊猫数据帧?最后,我想在main_box这是一个代码示例,适用于任何 jupyter 笔记本import pandas as pdimport ipywidgets as widgetsdef button_run_on_click(_): status_label.value = "running...." df = pd.DataFrame([[1,2,3],[4,5,6],[7,8,9]]) status_label.value = "" result_box = setup_ui(df) main_box.children = [selection, button_run, status_label, result_box]def setup_ui(df): return widgets.VBox([df])selection_box = widgets.Box()selection_toggles = []selected_labels = {}default_labels = ['test1', "test2"]labels = {"test1": "test1", "test2": "test2", "test3": "test3"}def update_selection(change): owner = change['owner'] name = owner.description if change['new']: owner.icon = 'check' selected_labels[name] = labels[name] else: owner.icon = "" selected_labels.pop(name)for k in sorted(labels): o = widgets.ToggleButton(description=k) o.observe(update_selection, 'value') o.value = k in default_labels selection_toggles.append(o) selection_box.children = selection_togglesstatus_label = widgets.Label()status_label.layout.width = '300px'button_run = widgets.Button(description="Run")main_box = widgets.VBox([selection_box, button_run, status_label])button_run.on_click(button_run_on_click)display(main_box)
1 回答
阿波罗的战车
TA贡献1862条经验 获得超6个赞
from IPython.display import display
import ipywidgets as widgets
def setup_ui(df):
out = widgets.Output()
with out:
display(df)
return out
如果将函数更改为此值,则可以返回包含数据帧的输出微件。setup_ui
但是,在您的函数中,它似乎未定义。这应该是别的吗?button_run_on_clickselection
- 1 回答
- 0 关注
- 107 浏览
添加回答
举报
0/150
提交
取消