Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +79 -38
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,81 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
|
| 10 |
-
If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
|
| 11 |
-
forums](https://discuss.streamlit.io).
|
| 12 |
-
|
| 13 |
-
In the meantime, below is an example of what you can do with just a few lines of code:
|
| 14 |
-
"""
|
| 15 |
-
|
| 16 |
-
num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
|
| 17 |
-
num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
|
| 18 |
-
|
| 19 |
-
indices = np.linspace(0, 1, num_points)
|
| 20 |
-
theta = 2 * np.pi * num_turns * indices
|
| 21 |
-
radius = indices
|
| 22 |
-
|
| 23 |
-
x = radius * np.cos(theta)
|
| 24 |
-
y = radius * np.sin(theta)
|
| 25 |
-
|
| 26 |
-
df = pd.DataFrame({
|
| 27 |
-
"x": x,
|
| 28 |
-
"y": y,
|
| 29 |
-
"idx": indices,
|
| 30 |
-
"rand": np.random.randn(num_points),
|
| 31 |
-
})
|
| 32 |
-
|
| 33 |
-
st.altair_chart(alt.Chart(df, height=700, width=700)
|
| 34 |
-
.mark_point(filled=True)
|
| 35 |
-
.encode(
|
| 36 |
-
x=alt.X("x", axis=None),
|
| 37 |
-
y=alt.Y("y", axis=None),
|
| 38 |
-
color=alt.Color("idx", legend=None, scale=alt.Scale()),
|
| 39 |
-
size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
|
| 40 |
-
))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import re
|
| 4 |
+
import io
|
| 5 |
+
|
| 6 |
+
st.set_page_config(page_title="Excel to Cleaned CSV", layout="centered")
|
| 7 |
+
|
| 8 |
+
st.title("📊 Clean Admission Excel Data")
|
| 9 |
+
st.write("Upload the Excel file and download the cleaned CSV file.")
|
| 10 |
+
|
| 11 |
+
uploaded_file = st.file_uploader("Upload your Excel file", type=["xlsx"])
|
| 12 |
+
|
| 13 |
+
if uploaded_file is not None:
|
| 14 |
+
try:
|
| 15 |
+
# Read and clean data
|
| 16 |
+
df_raw = pd.read_excel(uploaded_file, skiprows=4)
|
| 17 |
+
|
| 18 |
+
df_raw.columns = [
|
| 19 |
+
'S.No', 'District', 'Institution Name',
|
| 20 |
+
'V Minorities Sanctioned', 'V Minorities Admitted',
|
| 21 |
+
'V NonMinorities Sanctioned', 'V NonMinorities Admitted',
|
| 22 |
+
'Course',
|
| 23 |
+
'Inter Minorities Sanctioned', 'Inter Minorities Admitted',
|
| 24 |
+
'Inter NonMinorities Sanctioned', 'Inter NonMinorities Admitted'
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
# Remove last row
|
| 28 |
+
df_raw = df_raw.iloc[:-1]
|
| 29 |
+
|
| 30 |
+
# Clean Institution Name
|
| 31 |
+
df_raw['Institution Name'] = df_raw['Institution Name'].astype(str).apply(
|
| 32 |
+
lambda x: re.sub(r'\([^)]*\)', '', x).replace('Boys', 'B').replace('Girls', 'G').strip()
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
# Convert numeric cols
|
| 36 |
+
numeric_cols = [
|
| 37 |
+
'V Minorities Sanctioned', 'V Minorities Admitted',
|
| 38 |
+
'V NonMinorities Sanctioned', 'V NonMinorities Admitted',
|
| 39 |
+
'Inter Minorities Sanctioned', 'Inter Minorities Admitted',
|
| 40 |
+
'Inter NonMinorities Sanctioned', 'Inter NonMinorities Admitted'
|
| 41 |
+
]
|
| 42 |
+
for col in numeric_cols:
|
| 43 |
+
df_raw[col] = pd.to_numeric(df_raw[col], errors='coerce').fillna(0).astype(int)
|
| 44 |
+
|
| 45 |
+
# Process Class V
|
| 46 |
+
df_v = df_raw[['S.No', 'District', 'Institution Name',
|
| 47 |
+
'V Minorities Sanctioned', 'V Minorities Admitted',
|
| 48 |
+
'V NonMinorities Sanctioned', 'V NonMinorities Admitted']].copy()
|
| 49 |
+
df_v['Class'] = 'V'
|
| 50 |
+
df_v['Sanctioned'] = df_v['V Minorities Sanctioned'] + df_v['V NonMinorities Sanctioned']
|
| 51 |
+
df_v['Admitted'] = df_v['V Minorities Admitted'] + df_v['V NonMinorities Admitted']
|
| 52 |
+
|
| 53 |
+
# Process Inter
|
| 54 |
+
df_inter = df_raw[['S.No', 'District', 'Institution Name',
|
| 55 |
+
'Inter Minorities Sanctioned', 'Inter Minorities Admitted',
|
| 56 |
+
'Inter NonMinorities Sanctioned', 'Inter NonMinorities Admitted']].copy()
|
| 57 |
+
df_inter['Class'] = 'Inter 1st Year'
|
| 58 |
+
df_inter['Sanctioned'] = df_inter['Inter Minorities Sanctioned'] + df_inter['Inter NonMinorities Sanctioned']
|
| 59 |
+
df_inter['Admitted'] = df_inter['Inter Minorities Admitted'] + df_inter['Inter NonMinorities Admitted']
|
| 60 |
+
|
| 61 |
+
# Combine and calculate
|
| 62 |
+
df_final = pd.concat([df_v, df_inter], ignore_index=True)
|
| 63 |
+
df_final['Vacancies'] = df_final['Sanctioned'] - df_final['Admitted']
|
| 64 |
+
df_final = df_final[['S.No', 'District', 'Institution Name', 'Class', 'Sanctioned', 'Admitted', 'Vacancies']]
|
| 65 |
+
|
| 66 |
+
# Download CSV
|
| 67 |
+
csv_buffer = io.StringIO()
|
| 68 |
+
df_final.to_csv(csv_buffer, index=False)
|
| 69 |
+
csv_data = csv_buffer.getvalue()
|
| 70 |
+
|
| 71 |
+
st.success("✅ File processed successfully!")
|
| 72 |
+
|
| 73 |
+
st.download_button(
|
| 74 |
+
label="📥 Download Cleaned CSV",
|
| 75 |
+
data=csv_data,
|
| 76 |
+
file_name="cleaned_admission_data.csv",
|
| 77 |
+
mime="text/csv"
|
| 78 |
+
)
|
| 79 |
|
| 80 |
+
except Exception as e:
|
| 81 |
+
st.error(f"❌ Error processing file: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|