1. <legend id='w2ALm'><style id='w2ALm'><dir id='w2ALm'><q id='w2ALm'></q></dir></style></legend>

        <small id='w2ALm'></small><noframes id='w2ALm'>

        <tfoot id='w2ALm'></tfoot>
        • <bdo id='w2ALm'></bdo><ul id='w2ALm'></ul>

        <i id='w2ALm'><tr id='w2ALm'><dt id='w2ALm'><q id='w2ALm'><span id='w2ALm'><b id='w2ALm'><form id='w2ALm'><ins id='w2ALm'></ins><ul id='w2ALm'></ul><sub id='w2ALm'></sub></form><legend id='w2ALm'></legend><bdo id='w2ALm'><pre id='w2ALm'><center id='w2ALm'></center></pre></bdo></b><th id='w2ALm'></th></span></q></dt></tr></i><div id='w2ALm'><tfoot id='w2ALm'></tfoot><dl id='w2ALm'><fieldset id='w2ALm'></fieldset></dl></div>

        Jupyter Notebook 小部件:创建相关下拉列表

        时间:2023-09-03

          <small id='78lah'></small><noframes id='78lah'>

          • <legend id='78lah'><style id='78lah'><dir id='78lah'><q id='78lah'></q></dir></style></legend><tfoot id='78lah'></tfoot>
              <tbody id='78lah'></tbody>

                <bdo id='78lah'></bdo><ul id='78lah'></ul>

                <i id='78lah'><tr id='78lah'><dt id='78lah'><q id='78lah'><span id='78lah'><b id='78lah'><form id='78lah'><ins id='78lah'></ins><ul id='78lah'></ul><sub id='78lah'></sub></form><legend id='78lah'></legend><bdo id='78lah'><pre id='78lah'><center id='78lah'></center></pre></bdo></b><th id='78lah'></th></span></q></dt></tr></i><div id='78lah'><tfoot id='78lah'></tfoot><dl id='78lah'><fieldset id='78lah'></fieldset></dl></div>
                • 本文介绍了Jupyter Notebook 小部件:创建相关下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想在我的 Jupyter Notebook 中创建 2 个下拉小部件.下拉内容取自数据框.

                  I want to create 2 dropdown widgets in my Jupyter Notebook. The dropdown content is taken from a dataframe.

                  假设我有一个由 3 个分类变量a"、b"、c"组成的 pandas 数据框.'a' 有 3 个子类型 'a1'、'a2' 和 'a3'.'b' 和 'c' 与 a 相似,因为它们也有自己的子类型.我想创建 2 个下拉小部件:第一个下拉小部件将具有 ['a','b','c'],第二个下拉小部件将根据用户为第一个小部件选择的变量显示子类型.

                  Let's say I have a pandas dataframe consisting of 3 categorical variables 'a', 'b', 'c'. 'a' has 3 subtypes 'a1','a2' and 'a3'. 'b' and 'c' are similar to a in the sense that they also have their own subtypes. I want to create 2 dropdown widgets: the first dropdown widget will have ['a','b','c'], and the second dropdown widget will display subtypes depending on what variable the user selects for the first widget.

                  老实说,我知道如何做到这一点.我会尝试为此写一些代码:

                  I honestly have any idea how to do this. I'll try to write out some codes for this:

                  import pandas as pd
                  from IPython.display import *
                  import ipywidgets as widgets
                  from ipywidgets import *
                  
                  # Create the dataframe
                  df = pd.DataFrame([['a1','a2','a3'],
                               ['b1','b2','b3'],
                               ['c1','c2','c3']], index = ['a','b','c']).transpose()
                  
                  # Widgets
                  widget1 = Dropdown(options = ['a','b','c'])
                  display(widget1)
                  widget2 = Dropdown(???????)
                  display(widget2)
                  

                  根据我为两个下拉小部件选择的内容,我希望执行一些功能.

                  And depending on what I select for the two dropdown widgets, I want some function executed.

                  感谢任何帮助.

                  推荐答案

                  我发现了如何做到这一点.我希望这对也希望做同样事情的其他人有所帮助.

                  I found out how to do this. I hope this helps for anyone else who's also looking to do the same thing.

                  x_widget = Dropdown(options = ['a','b','c'])
                  y_widget = Dropdown()
                  
                  # Define a function that updates the content of y based on what we select for x
                  def update(*args):
                      y_widget.options = df[x_widget.value].unique().tolist()
                  x_widget.observe(update)
                  
                  # Some function you want executed
                  def random_function():
                  ...
                  
                  interact(random_function,
                           x = x_widget,
                           y = y_widget);
                  

                  这篇关于Jupyter Notebook 小部件:创建相关下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 SelectDateWidget 的 Django 表单字段 下一篇:从 tkinter 中的 Text 小部件复制格式化文本

                  相关文章

                • <i id='FIeMV'><tr id='FIeMV'><dt id='FIeMV'><q id='FIeMV'><span id='FIeMV'><b id='FIeMV'><form id='FIeMV'><ins id='FIeMV'></ins><ul id='FIeMV'></ul><sub id='FIeMV'></sub></form><legend id='FIeMV'></legend><bdo id='FIeMV'><pre id='FIeMV'><center id='FIeMV'></center></pre></bdo></b><th id='FIeMV'></th></span></q></dt></tr></i><div id='FIeMV'><tfoot id='FIeMV'></tfoot><dl id='FIeMV'><fieldset id='FIeMV'></fieldset></dl></div>
                    <legend id='FIeMV'><style id='FIeMV'><dir id='FIeMV'><q id='FIeMV'></q></dir></style></legend>
                    <tfoot id='FIeMV'></tfoot>

                  1. <small id='FIeMV'></small><noframes id='FIeMV'>

                      <bdo id='FIeMV'></bdo><ul id='FIeMV'></ul>