plotting / app.py
Shivraj8615's picture
Create app.py
eb4f0b0 verified
raw
history blame
1.84 kB
import streamlit as st
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
def main():
st.title("Excel Column Analysis Dashboard")
uploaded_file = st.file_uploader("Upload an Excel file", type=["xls", "xlsx"])
if uploaded_file is not None:
df = pd.read_excel(uploaded_file)
st.write("Preview of Data:")
st.write(df.head())
numeric_columns = df.select_dtypes(include=[np.number]).columns.tolist()
if numeric_columns:
selected_column = st.selectbox("Select a column for analysis (as named in the Excel file)", numeric_columns)
if selected_column:
data = df[selected_column].dropna()
std_dev = np.std(data, ddof=1)
st.write(f"**Calculated Standard Deviation:** {std_dev:.4f}")
fig, axes = plt.subplots(1, 2, figsize=(12, 5))
sns.histplot(data, kde=True, ax=axes[0], bins=20, color='blue')
axes[0].set_title(f"Distribution Plot of {selected_column}")
sns.lineplot(x=data.index, y=data, ax=axes[1], label='Data')
axes[1].axhline(y=np.mean(data), color='r', linestyle='--', label='Mean')
axes[1].axhline(y=np.mean(data) + std_dev, color='g', linestyle='--', label='+1 Std Dev')
axes[1].axhline(y=np.mean(data) - std_dev, color='g', linestyle='--', label='-1 Std Dev')
axes[1].legend()
axes[1].set_title(f"Standard Deviation Plot of {selected_column}")
st.pyplot(fig)
else:
st.warning("No numeric columns found in the uploaded file.")
if __name__ == "__main__":
main()