Initially, I was getting this error (error:- ValueError: Invalid file path or buffer object type: <class ‘NoneType’>) so I added this bit to my code which resolved the problem:
if uploaded_file is not None:
df = pd.read_csv(uploaded_file)
st.write("Data Set")
st.dataframe(df,3000,500)
But then I got this error which I can’t seem to resolve, I tried making the df variable global and also made a function but neither worked…
This is a snippet of my code:
import streamlit as st
import pandas as pd
from pandas import DataFrame
import matplotlib.pyplot as plt
import plotly.express as px
#configuration
st.set_option('deprecation.showfileUploaderEncoding', False)
st.title("Data Visualisation App")
# Add sidebar
st.sidebar.subheader("Visualisation settings")
# Setup file upload
global df
uploaded_file = st.sidebar.file_uploader(label="Upload your Excel file", type = ['csv','xlsx'])
if uploaded_file is not None:
df = pd.read_csv(uploaded_file)
st.write("Data Set")
st.dataframe(df,3000,500)
if st.checkbox('Show raw data'):
st.subheader('Raw data')
st.write(df)