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…
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)
Hey @Vivika_Martini, the error is in feedback_visualisation_app.py file as shown in the image. Can you please add or provide the repo link so that I can review the code?
As per my knowledge, I don’t think so there is any problem with the provided code snippet.
Your code is fine, but python/pandas has a problem reading the xslx files. I tried it with a csv file and it’s OK.
You should add a condition and handle depending on whether it’s a csv or xlsx (use pd.read_excel)
Hey @eri3l thank you! I tried that out and when I upload a CSV file the “name ‘df’ is not defined” error goes away. However, if a file isn’t uploaded the error remains. Do you know how to get rid of it?
This is actually the correct solution. On each run of a Streamlit app, your app runs top to bottom. On the first run, uploaded_file has a value of None, because the file uploader hasn’t been used yet. By testing for the value of None, you are building in the logic to ensure that a file has already been uploaded.
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.