下拉菜单 - 浮点值

发布于 2025-02-09 14:19:53 字数 1963 浏览 0 评论 0原文

我正在尝试使用iPywidgets创建一个下拉列表,它需要返回变量值,此变量值可能会根据其他滑块输入值而更改。当我尝试返回变量时,我会收到错误:nameError:'awadment_one'未定义。


calculated_area = input_slider / numstorey_input_slider * 0.7
revised_area = input_slider - calculated_area
adjustment_one = revised_area / input_slider
    
location = ipywidgets.Dropdown(   
    options=[('Internal', 1), ('Roof', adjustment_one), ('External', 2) ],
    value=1,
    description='Plant Space Location: ',
)

上述方法已解决,是一个缩进的错误,但是我现在发现我无法使用iPyWidget下拉列表传递浮点数。以下是代码 - 基于下拉列表中选择的内容,该代码将映射到数据帧作为乘数。但是,当我打开Excel文档时,它仅返回值'0'。当选择屋顶时,此值实际上应为0.87,并且会根据滑块输入值而更改。

    calculated_roof_area = gia_input_slider / numstoreys_input_slider * 0.7
    revised_gia_roofinput = gia_input_slider - calculated_roof_area
    gia_adjustment_rooftop = revised_gia_roofinput / gia_input_slider
    
    plantspace = ipywidgets.Dropdown(   
    options=[('Internal', 1), ('Roof', gia_adjustment_rooftop), ('External', 2) ],
    value=1,
    description='Plant Space Location: ',
    )
    
    print(plantspace)  
    
    df = pd.read_excel(r'dataframe_final.xlsx', sheet_name='sheet1')
        
    # below recalculates the adjusted qty when the slider position changes
    
    multipliers = {
        'Building Footprint Factor': bldg_footprint_factor,
        'CAT A Fitout Yes / No': fitout_cat_dropdown,
        'GIA Factor': gia_factor,
        'GIA Adjustment - Rooftop': plantspace_dropdown
    }

    df['QP1 Multiplier'] = df['QP1'].map(multipliers)
    df['QP2 Multiplier'] = df['QP2'].map(multipliers)
    df['QP3 Multiplier'] = df['QP3'].map(multipliers)
    df['QP4 Multiplier'] = df['QP4'].map(multipliers)
    df['QP5 Multiplier'] = df['QP5'].map(multipliers)
    df['QP6 Multiplier'] = df['QP6'].map(multipliers)
    df['QP7 Multiplier'] = df['QP7'].map(multipliers)
    df['QP8 Multiplier'] = df['QP8'].map(multipliers)
    df['QP9 Multiplier'] = df['QP9'].map(multipliers)

有人可以帮忙吗?

I am trying to create a dropdown with ipywidgets, it needs to return a variable value, this variable value may change depending on other slider input values. When I try to return the variable I get the error: NameError: 'adjustment_one' Not Defined.


calculated_area = input_slider / numstorey_input_slider * 0.7
revised_area = input_slider - calculated_area
adjustment_one = revised_area / input_slider
    
location = ipywidgets.Dropdown(   
    options=[('Internal', 1), ('Roof', adjustment_one), ('External', 2) ],
    value=1,
    description='Plant Space Location: ',
)

The above method is solved and was an indenting error however I have now found that I can't pass a float value using the ipywidget dropdown. Below is the code - based on what is selected in the drop down this will be mapped to a dataframe as a multiplier. However when I open the excel document it only every returns the value '0'. This value should actually be 0.87 when Roof is selected, and will change depending on slider input values.

    calculated_roof_area = gia_input_slider / numstoreys_input_slider * 0.7
    revised_gia_roofinput = gia_input_slider - calculated_roof_area
    gia_adjustment_rooftop = revised_gia_roofinput / gia_input_slider
    
    plantspace = ipywidgets.Dropdown(   
    options=[('Internal', 1), ('Roof', gia_adjustment_rooftop), ('External', 2) ],
    value=1,
    description='Plant Space Location: ',
    )
    
    print(plantspace)  
    
    df = pd.read_excel(r'dataframe_final.xlsx', sheet_name='sheet1')
        
    # below recalculates the adjusted qty when the slider position changes
    
    multipliers = {
        'Building Footprint Factor': bldg_footprint_factor,
        'CAT A Fitout Yes / No': fitout_cat_dropdown,
        'GIA Factor': gia_factor,
        'GIA Adjustment - Rooftop': plantspace_dropdown
    }

    df['QP1 Multiplier'] = df['QP1'].map(multipliers)
    df['QP2 Multiplier'] = df['QP2'].map(multipliers)
    df['QP3 Multiplier'] = df['QP3'].map(multipliers)
    df['QP4 Multiplier'] = df['QP4'].map(multipliers)
    df['QP5 Multiplier'] = df['QP5'].map(multipliers)
    df['QP6 Multiplier'] = df['QP6'].map(multipliers)
    df['QP7 Multiplier'] = df['QP7'].map(multipliers)
    df['QP8 Multiplier'] = df['QP8'].map(multipliers)
    df['QP9 Multiplier'] = df['QP9'].map(multipliers)

Can anybody help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文