AttributeError: 'NoneType' object has no attribute 'head'

Sorry for the big code.
When I try to upload the file in CSV format, this error appears AttributeError: ‘NoneType’ object has no attribute ‘head’.
I couldn’t solve this question in the code, if someone can help me, I’ll be very happy.

Title and Subheader

st.title(“Student Performance EDA App”)
st.subheader("EDA Web App with Streamlit ")

class DataFrame_Loader():

def __init__(self):
    
    print("Loadind DataFrame")
    
def read_csv(self,data):
    self.df = pd.read_csv(data)

class EDA_Dataframe_Analysis():

def __init__(self):
    
    print("General_EDA object created")
    
def exibir(self, data):
    return data.head()

def describe(self,data):
    return data.describe()

def colunas(self,data):
    return data.columns

def aprovados(self,data):
    return data['verdict'].value_counts(normalize=True)

def scatter(self,data,x):
    return sns.scatterplot(y='G_mean',x=x,data=data)

def boxplot(self,data,x):
    return sns.boxplot(x=x,y="G_mean",data=data)

def barplot(self,data,x):
    return sns.barplot(x=x,y="G_mean",data=data)
    
def count(self,data,x):
    return sns.countplot(x=x, data = data, palette='rocket', saturation=0.9)

def heat(self,data):
    numData = data._get_numeric_data()
    var_num_corr = numData.corr()

    return sns.heatmap(var_num_corr, vmin=-1, vmax=1, annot=True, linewidth=0.01, linecolor='black', cmap='RdBu_r')

def main():

st.title("Exploratory Data Analysis")

if st.checkbox("Show/Hide"):
    st.text("Showing or Hiding Widget")
    data = st.file_uploader("Upload a Dataset", type=["csv"])
    
    if data is not None:
        df = load.read_csv(data)
        st.dataframe(df.head())
        st.success("Data Frame Loaded successfully")
    
        if st.checkbox("Exibir 5 linhas"):
            st.write(dataframe.exibir(df))

        if st.checkbox("Resumo estatístico"):
            st.write(dataframe.describe(df))

        if st.checkbox("Exibir todas as colunas"):
            st.write(dataframe.colunas(df))

        if st.checkbox(r"% de aprovados"):
            st.write(dataframe.aprovados(df))
            
        cols =('Age', 'Attrition', 'BusinessTravel', 'DailyRate', 'Department','DistanceFromHome', 'Education', 'EducationField', 'EmployeeCount','EmployeeNumber', 'EnvironmentSatisfaction', 'Gender', 'HourlyRate',
                    'JobInvolvement', 'JobLevel', 'JobRole', 'JobSatisfaction',
                    'MaritalStatus', 'MonthlyIncome', 'MonthlyRate', 'NumCompaniesWorked',
                    'Over18', 'OverTime', 'PercentSalaryHike', 'PerformanceRating',
                    'RelationshipSatisfaction', 'StandardHours', 'StockOptionLevel',
                    'TotalWorkingYears', 'TrainingTimesLastYear', 'WorkLifeBalance',
                    'YearsAtCompany', 'YearsInCurrentRole', 'YearsSinceLastPromotion',
                    'YearsWithCurrManager')
                            
        if st.checkbox("Gráfico de Dispersão"):
            occupation = st.selectbox("Dispersão Gráfica",[cols])
            st.dataframe(dataframe.scatter(data, occupation))
                    
        if st.checkbox("Gráfico BoxPlot"):
            occupation = st.selectbox("Boxplot",[cols])
            st.dataframe(dataframe.boxplot(data, occupation))
                    
        if st.checkbox("Gráfico BarPlot"):
            occupation = st.selectbox("BarPlot",[cols])
            st.dataframe(dataframe.barplot(data, occupation))
                
        if st.checkbox("Gráfico De Contagem"):
            occupation = st.selectbox("Contagem",[cols])
            st.dataframe(dataframe.count(data, occupation))
                
        if st.checkbox("Gráfico De Calor"):
            st.dataframe(dataframe.heat(data))

load = DataFrame_Loader()

dataframe = EDA_Dataframe_Analysis()

main()

Hi @caio_povill,

Thanks for posting!

This error seems to indicate that when you’re calling df.head(), the dataframe is actually empty – if you make sure that the dataframe isn’t empty, the error should go away.

Caroline :balloon:

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