How to upload .sav (spss) file via st.uploader

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)

Hey @haider_ali,

Can you share a sample .sav file for us to test with?

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.

kindly share the code you have used for uploading .sav file. i have tried multiple datasets.

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.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.