-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
95 lines (79 loc) · 2.75 KB
/
index.html
File metadata and controls
95 lines (79 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<title>stlite app</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@stlite/mountable@0.31.0/build/stlite.css"
/>
</head>
<body>
<div id="root"></div>
<script src="https://cdn.jsdelivr.net/npm/@stlite/mountable@0.31.0/build/stlite.js"></script>
<script>
stlite.mount(
{
requirements: ["plotly"], // Packages to install
entrypoint: "ern_app.py", // The target file of the `streamlit run` command
files: {
"ern_app.py": `
import pandas as pd
import streamlit as st
import json
import plotly.express as px
import numpy as np
def ingress(filepath):
df['SEX'] = df['SEX'].map({1:'Male',
2:'Female'})
# convert birthday column
# Get age in years
# https://stackoverflow.com/questions/31490816/calculate-datetime-difference-in-years-months-etc-in-a-new-pandas-dataframe-c
# Tip: to convert the age column to whole numbers, rounded down, use: .astype('int') on the column
df['DOB'] = pd.to_datetime(df['DOB'], format="%d/%m/%Y", errors='coerce')
df['AGE'] = (pd.to_datetime('today').normalize() - df['DOB'])
#st.write(type(df['age'][0]))
# make column for age today
df['AGE'] = (df['AGE'] / np.timedelta64(1, 'Y')).astype('int')
return df
def number_of_children(df):
child_count = len(df['CHILD'].unique())
return child_count
def boys_girls_count(df):
counts = df['SEX'].value_counts().to_json()
counts = json.loads(counts)
return counts['Male'], counts['Female']
st.title("903 Header analysis tool")
uploaded_files = st.file_uploader('Upload 903 header here:', accept_multiple_files=True)
if uploaded_files:
loaded_files = {uploaded_file.name[:-4]: pd.read_csv(uploaded_file) for uploaded_file in uploaded_files}
df = list(loaded_files.values())[0]
df = ingress(df)
st.dataframe(df)
child_count = number_of_children(df)
boys, girls = boys_girls_count(df)
st.write(f'The number of children is: {child_count}')
st.write(f'The number of boys is: {boys}')
st.write(f'The number of girls is: {girls}')
fig = px.bar(df, x='SEX')
st.plotly_chart(fig)
# Make a bar plot for Ethnicity
fig = px.bar(df, x='ETHNIC')
st.plotly_chart(fig)
# Make a histogram plot for age
# Use google and the plotly docs for this!
fig = px.histogram(df, x='AGE')
st.plotly_chart(fig)
`,
},
},
document.getElementById("root")
);
</script>
</body>
</html>