How to resolve this error?

import streamlit as st
import pandas as pd

dataset = st.file_uploader("upload file here", type = ['csv'])
df = pd.read_csv(dataset)
st.write('## Data set')
st.dataframe(df,3000,500)

By running above code i am getting this

error:- ValueError: Invalid file path or buffer object type: <class ‘NoneType’>

After uploading file the error is disappearing. what should I do?

Hi Pavan_Cheyutha,

The reason you are getting the error is that the variable dataset will be equal None when you have not uploaded a dataset yet. One way to fix your problem would be

import streamlit as st
import pandas as pd

dataset = st.file_uploader("upload file here", type = ['csv'])
if dataset is not None:
    df = pd.read_csv(dataset)
    st.write('## Data set')
    st.dataframe(df,3000,500)

See also the examples in the docs

Best,
Peter

3 Likes

Thank you very much…