'How to add columns based on the number of the fileds in the dataframe using streamlit and python
I have a streamlit app that read a csv file and display the content as dataframe.
I need to display the column names as text_input by displaying them in a horizontal layout beside each other , by using st.columns().
The problem is that when i run the app it crash and display the below error:
StreamlitAPIException: The input argument to st.columns must be either a positive integer or a list of positive numeric weights. See documentation for more information.
Traceback:
File "F:\AIenv\streamlit\app2.py", line 1580, in <module>
main()
File "F:\AIenv\streamlit\app2.py", line 479, in main
cols = st.columns(ncol)
code:
num_new_rows = st.sidebar.number_input("Add Rows",1,50)
ncol = st.session_state.df.shape[1]
with st.form(key='add_record_form',clear_on_submit= True):
st.subheader("Add Record")
cols = st.columns(ncol)
rwdta = [
cols[i].text_input(st.session_state.df.columns[i]) for i in range(ncol)
]
Solution 1:[1]
The problem was in the type of the file. It seems that streamlit has changed the way it assigns the type of a selected file where if it is a csv:
I changed te file type from "application/vnd.ms-excel" to "text/csv".
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | vinzee |
