i am new to streamlit. I am trying to upload spss file via st.uploader but i am getting this error.
TypeError: expected str, bytes or os.PathLike object, not UploadedFile
#Folloaing is the code
file = st.file_uploader(“Please choose a file”)
if file is not None:
#To read file as bytes:
bytes_data = file.getvalue()
st.write(bytes_data)
#To convert to a string based IO:
stringio = StringIO(file.getvalue().decode("latin1")) #(when i tried utf-8 i got cant convert utf-8 at a axx position. so i changed it to latin1 but now i am getting above metioned error)
st.write(stringio)
#To read file as string:
string_data = stringio.read()
st.write(string_data)
#Can be used wherever a "file-like" object is accepted:
df= pd.read_spss(file)
I don’t have your data and the code in your post is not properly formatted, so I had to make up the data and guess how the code actually looks like. With those caveats, the code works for me.
i have tried multiple datasets. its not about datasets. May be there is an issue with my code. if you have uploaded .sav file. Kindly share syntax. i wanna figure out the mistake i am making in the code. thanks
I don’t have a .sav file to try so I used a .csv file instead. The code is the same except I used pd.read_csv(file) instead of pd.read_spss(file) in the last line.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.