Data analysis app

Hiya, I’m trying to plot a line graph using two specific columns (x-axis: data from column 5 and y-axis: data from column 8) from my data frame, but am unsure of how to do this. I would be really grateful to have some assistance with this! :grin:

This is my code so far:

import streamlit as st
import pandas as pd

st.set_option('deprecation.showfileUploaderEncoding', False)

st.title("Student Feedback Visualisation App")

# Add sidebar
st.sidebar.subheader("Visualisation settings")

# Setup file upload
uploaded_file = st.sidebar.file_uploader(label="Upload your Excel file", type = ['csv','xlsx'])

global df

if uploaded_file is not None:

        df = pd.read_csv(uploaded_file)
    except Exception as e:
        df = pd.read_excel(uploaded_file)

    if st.checkbox('Show raw data'):
        st.subheader('Raw data')
except Exception as e:
    st.write("Please upload a file to the application by going to the sidebar")
1 Like

Hey, maybe this could help:

fig, ax = plt.subplots()
ax.plot(df['col_name_5'], df['col_name_8'])

Awesome thank you @alican ! I tried it out and it did plot the correct axes, but the formatting is bit weird.

Is the df empty? You can handle formatting with matplotlib functionalities.

Great thank you! No, the df isn’t empty I just haven’t uploaded the file yet :slight_smile:

I see in that case, maybe first upload it to see if the formatting is okay. If not, you can change range, tick frequency, text size of the axes to get it right, using matplotlib.

1 Like

@alican Will do, thank you!
On a separate note, is it possible to average the data in a column according to the day it was added? I’m trying to plot the average score each day

Yes using a conditional selection, in pseudo-code

for day in days:
        score_vals_per_day = df['score_col'][df['date_col']==day]
        mean of score_vals_per_day
1 Like