我目前正在使用python上的Streamlit库为我的一个项目制作一个网络应用程序,该应用程序将从与滑块的交互中获取用户输入数据。
然而,当我试图通过字典将用户输入数据存储到数据帧中时,我会收到以下错误:
ValueError:值的长度(4)与索引的长度(1)不匹配
我尝试过使用pd.Series()方法,也尝试过使用一些参数,但我被难住了。
我觉得我在这里的数据结构类中遗漏了一些东西,我需要帮助来学习和解决这个问题。非常感谢。
此外,这是我第一篇关于堆栈溢出的文章,所以我为任何错误的格式问题道歉。
到目前为止,这是我的代码:
def user_input_features():
price_to_earnings = st.sidebar.slider('Price to Earnings', -100, 100, 0)
debt_to_equity = st.sidebar.slider('Debt to Equity', -50, 50, 0)
book_value_per_share = st.sidebar.slider('Book Value per Share', -400, 400, 0)
price_to_book_ratio = st.sidebar.slider('Price to Book Ratio', 0, 500, 0)
type_of_company = ('Is it a Tech Company?', 0, 1, 0)
annual_volatility = ('Annual Volatility Swing (In Percent)', 0, 100, 0)
# Dictionary
data = {'price_to_earnings': price_to_earnings,
'debt_to_equity': debt_to_equity,
'book_value_per_share': book_value_per_share,
'price_to_book_ratio': price_to_book_ratio,
'type_of_company': type_of_company,
'annual_volatility': annual_volatility}
features = pd.DataFrame(data, index=[0])
return features