Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import plotly.express as px
|
| 3 |
+
import streamlit as st
|
| 4 |
+
|
| 5 |
+
# Configuring the Streamlit App:
|
| 6 |
+
st.set_page_config(
|
| 7 |
+
page_title='MAK Analytics Portal',
|
| 8 |
+
page_icon='📊'
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
# Adding Titles and Subtitles:
|
| 12 |
+
st.title(':rainbow[Data Analytics Portal]')
|
| 13 |
+
st.subheader(':gray[Explore Data with ease.]',divider='rainbow')
|
| 14 |
+
|
| 15 |
+
# File Upload Feature:
|
| 16 |
+
file = st.file_uploader('Drop csv,tsv or excel file', type=['csv', 'xlsx','tsv'])
|
| 17 |
+
if file:
|
| 18 |
+
if file.name.endswith('csv'):
|
| 19 |
+
data = pd.read_csv(file)
|
| 20 |
+
elif file.name.endswith('tsv'):
|
| 21 |
+
data=pd.read_tsv(file)
|
| 22 |
+
else:
|
| 23 |
+
data = pd.read_excel(file)
|
| 24 |
+
st.dataframe(data)
|
| 25 |
+
st.info('File is successfully Uploaded', icon='✔️')
|
| 26 |
+
|
| 27 |
+
# Exploring Basic Information:
|
| 28 |
+
st.subheader(':rainbow[Basic information of the dataset]',divider='rainbow')
|
| 29 |
+
tab1, tab2, tab3, tab4 = st.tabs(['Summary', 'Top and Bottom Rows', 'Data Types', 'Columns'])
|
| 30 |
+
|
| 31 |
+
with tab1:
|
| 32 |
+
st.write(f'There are {data.shape[0]} rows in dataset and {data.shape[1]} columns in the dataset')
|
| 33 |
+
st.subheader(':gray[Statistical summary of the dataset]')
|
| 34 |
+
st.dataframe(data.describe())
|
| 35 |
+
with tab2:
|
| 36 |
+
st.subheader(':gray[Top Rows]')
|
| 37 |
+
toprows = st.slider('Number of rows you want', 1, data.shape[0], key='topslider')
|
| 38 |
+
st.dataframe(data.head(toprows))
|
| 39 |
+
st.subheader(':gray[Bottom Rows]')
|
| 40 |
+
bottomrows = st.slider('Number of rows you want', 1, data.shape[0], key='bottomslider')
|
| 41 |
+
st.dataframe(data.tail(bottomrows))
|
| 42 |
+
with tab3:
|
| 43 |
+
st.subheader(':grey[Data types of column]')
|
| 44 |
+
st.dataframe(data.dtypes)
|
| 45 |
+
with tab4:
|
| 46 |
+
st.subheader('Column Names in Dataset')
|
| 47 |
+
st.write(list(data.columns))
|
| 48 |
+
|
| 49 |
+
# Column Value Counts:
|
| 50 |
+
st.subheader(':rainbow[Column Values To Count]',divider='rainbow')
|
| 51 |
+
with st.expander('Value Count'):
|
| 52 |
+
col1, col2 = st.columns(2)
|
| 53 |
+
with col1:
|
| 54 |
+
column = st.selectbox('Choose Column name', options=list(data.columns))
|
| 55 |
+
with col2:
|
| 56 |
+
toprows = st.number_input('Top rows', min_value=1, step=1)
|
| 57 |
+
|
| 58 |
+
count = st.button('Count')
|
| 59 |
+
if count:
|
| 60 |
+
result = data[column].value_counts().reset_index().head(toprows)
|
| 61 |
+
st.dataframe(result)
|
| 62 |
+
st.subheader('Visualization', divider='gray')
|
| 63 |
+
fig = px.bar(data_frame=result, x=column, y='count', text='count', template='plotly_white')
|
| 64 |
+
st.plotly_chart(fig)
|
| 65 |
+
fig = px.line(data_frame=result, x=column, y='count', text='count', template='plotly_white')
|
| 66 |
+
st.plotly_chart(fig)
|
| 67 |
+
fig = px.pie(data_frame=result, names=column, values='count')
|
| 68 |
+
st.plotly_chart(fig)
|
| 69 |
+
|
| 70 |
+
# Grouping Data for Deeper Insights:
|
| 71 |
+
st.subheader(':rainbow[Groupby : Simplify your data analysis]', divider='rainbow')
|
| 72 |
+
st.write('The groupby lets you summarize data by specific categories and groups')
|
| 73 |
+
with st.expander('Group By your columns'):
|
| 74 |
+
col1, col2, col3 = st.columns(3)
|
| 75 |
+
with col1:
|
| 76 |
+
groupby_cols = st.multiselect('Choose your column to groupby', options=list(data.columns))
|
| 77 |
+
with col2:
|
| 78 |
+
operation_col = st.selectbox('Choose column for operation', options=list(data.columns))
|
| 79 |
+
with col3:
|
| 80 |
+
operation = st.selectbox('Choose operation', options=['sum', 'max', 'min', 'mean', 'median', 'count'])
|
| 81 |
+
|
| 82 |
+
if groupby_cols:
|
| 83 |
+
result = data.groupby(groupby_cols).agg(
|
| 84 |
+
ans=(operation_col, operation)
|
| 85 |
+
).reset_index()
|
| 86 |
+
|
| 87 |
+
st.dataframe(result)
|
| 88 |
+
|
| 89 |
+
st.subheader(':gray[Data Visualization]', divider='gray')
|
| 90 |
+
graphs = st.selectbox('Choose your graphs', options=['line', 'bar', 'scatter', 'pie', 'sunburst'])
|
| 91 |
+
if graphs == 'line':
|
| 92 |
+
x_axis = st.selectbox('Choose X axis', options=list(result.columns))
|
| 93 |
+
y_axis = st.selectbox('Choose Y axis', options=list(result.columns))
|
| 94 |
+
color = st.selectbox('Color Information', options=[None] + list(result.columns))
|
| 95 |
+
fig = px.line(data_frame=result, x=x_axis, y=y_axis, color=color, markers='o')
|
| 96 |
+
st.plotly_chart(fig)
|
| 97 |
+
elif graphs == 'bar':
|
| 98 |
+
x_axis = st.selectbox('Choose X axis', options=list(result.columns))
|
| 99 |
+
y_axis = st.selectbox('Choose Y axis', options=list(result.columns))
|
| 100 |
+
color = st.selectbox('Color Information', options=[None] + list(result.columns))
|
| 101 |
+
facet_col = st.selectbox('Column Information', options=[None] + list(result.columns))
|
| 102 |
+
fig = px.bar(data_frame=result, x=x_axis, y=y_axis, color=color, facet_col=facet_col, barmode='group')
|
| 103 |
+
st.plotly_chart(fig)
|
| 104 |
+
elif graphs == 'scatter':
|
| 105 |
+
x_axis = st.selectbox('Choose X axis', options=list(result.columns))
|
| 106 |
+
y_axis = st.selectbox('Choose Y axis', options=list(result.columns))
|
| 107 |
+
color = st.selectbox('Color Information', options=[None] + list(result.columns))
|
| 108 |
+
size = st.selectbox('Size Column', options=[None] + list(result.columns))
|
| 109 |
+
fig = px.scatter(data_frame=result, x=x_axis, y=y_axis, color=color, size=size)
|
| 110 |
+
st.plotly_chart(fig)
|
| 111 |
+
elif graphs == 'pie':
|
| 112 |
+
values = st.selectbox('Choose Numerical Values', options=list(result.columns))
|
| 113 |
+
names = st.selectbox('Choose labels', options=list(result.columns))
|
| 114 |
+
fig = px.pie(data_frame=result, values=values, names=names)
|
| 115 |
+
st.plotly_chart(fig)
|
| 116 |
+
elif graphs == 'sunburst':
|
| 117 |
+
path = st.multiselect('Choose your Path', options=list(result.columns))
|
| 118 |
+
fig = px.sunburst(data_frame=result, path=path, values='ans')
|
| 119 |
+
st.plotly_chart(fig)
|