Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| import seaborn as sns | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| import io | |
| def save_plot(fig): | |
| buf = io.BytesIO() | |
| fig.savefig(buf, format="png") | |
| buf.seek(0) | |
| return buf | |
| def main(): | |
| st.title("Distribution Curve Plotting 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}") | |
| # Distribution Plot | |
| fig_dist, ax_dist = plt.subplots(figsize=(6, 5)) | |
| sns.histplot(data, kde=True, ax=ax_dist, bins=20, color='blue') | |
| ax_dist.set_title(f"Distribution Plot of {selected_column}") | |
| st.pyplot(fig_dist) | |
| st.download_button("Download Distribution Plot", save_plot(fig_dist), file_name="distribution_plot.png", mime="image/png") | |
| # Standard Deviation Plot | |
| fig_std, ax_std = plt.subplots(figsize=(6, 5)) | |
| sns.lineplot(x=data.index, y=data, ax=ax_std, label='Data') | |
| ax_std.axhline(y=np.mean(data), color='r', linestyle='--', label='Mean') | |
| ax_std.axhline(y=np.mean(data) + std_dev, color='g', linestyle='--', label='+1 Std Dev') | |
| ax_std.axhline(y=np.mean(data) - std_dev, color='g', linestyle='--', label='-1 Std Dev') | |
| ax_std.legend() | |
| ax_std.set_title(f"Standard Deviation Plot of {selected_column}") | |
| st.pyplot(fig_std) | |
| st.download_button("Download Standard Deviation Plot", save_plot(fig_std), file_name="std_dev_plot.png", mime="image/png") | |
| else: | |
| st.warning("No numeric columns found in the uploaded file.") | |
| if __name__ == "__main__": | |
| main() |