├── .DS_Store
├── Chapter01
├── clt_app
│ ├── clt_demo.py
│ ├── example.py
│ └── hello_world.py
└── plotting_app
│ └── plot_demo.py
├── Chapter02
└── penguin_app
│ ├── penguins.csv
│ ├── penguins.py
│ └── requirements.txt
├── Chapter03
└── trees_app
│ ├── .streamlit
│ └── config.toml
│ ├── trees.csv
│ └── trees.py
├── Chapter04
└── penguin_ml
│ ├── feature_importance.png
│ ├── output_penguin.pickle
│ ├── penguins.csv
│ ├── penguins_ml.py
│ ├── penguins_streamlit.py
│ ├── random_forest_penguin.pickle
│ └── requirements.txt
├── Chapter05
└── penguin_ml
│ ├── feature_importance.png
│ ├── output_penguin.pickle
│ ├── penguins.csv
│ ├── penguins_ml.py
│ ├── penguins_streamlit.py
│ ├── random_forest_penguin.pickle
│ └── requirements.txt
├── Chapter06
└── pretty_trees
│ ├── pretty_trees.py
│ └── trees.csv
├── Chapter07
└── components_example
│ ├── gist_example.py
│ ├── penguin_animated.py
│ ├── penguins.csv
│ ├── tree_animated.py
│ └── trees.csv
├── Chapter08
└── penguin_ml
│ ├── feature_importance.png
│ ├── output_penguin.pickle
│ ├── penguins.csv
│ ├── penguins_ml.py
│ ├── penguins_streamlit.py
│ ├── random_forest_penguin.pickle
│ └── requirements.txt
├── Chapter09
└── job_application_example
│ ├── Screen Shot 2020-11-30 at 1.48.16 PM.png
│ ├── airport_location.csv
│ ├── haversine.png
│ ├── job_problems.md
│ └── job_streamlit.py
├── LICENSE
└── README.md
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Getting-started-with-Streamlit-for-Data-Science/50677d3f08c78f796b05cb1caf76246df3ff08ff/.DS_Store
--------------------------------------------------------------------------------
/Chapter01/clt_app/clt_demo.py:
--------------------------------------------------------------------------------
1 | import streamlit as st
2 | import numpy as np
3 | import matplotlib.pyplot as plt
4 |
5 |
6 |
7 | perc_heads = st.number_input(label='Chance of Coins Landing on Heads', min_value=0.0, max_value=1.0, value=.5)
8 | graph_title = st.text_input(label='Graph Title')
9 | binom_dist = np.random.binomial(1, perc_heads, 1000)
10 | list_of_means = []
11 | for i in range(0, 1000):
12 | list_of_means.append(np.random.choice(binom_dist, 100, replace=True).mean())
13 |
14 |
15 |
16 | fig, ax = plt.subplots()
17 | plt.hist(list_of_means, range=[0,1])
18 | plt.title(graph_title)
19 | st.pyplot(fig)
--------------------------------------------------------------------------------
/Chapter01/clt_app/example.py:
--------------------------------------------------------------------------------
1 | import streamlit as st
2 | import numpy as np
3 | import matplotlib.pyplot as plt
4 |
5 | with st.form('first form'):
6 | perc_heads = st.number_input(label='Chance of Coins Landing on Heads', min_value=0.0, max_value=1.0, value=.5)
7 | graph_title = st.text_input(label='Graph Title')
8 | my_submit_button = st.form_submit_button()
9 |
10 | binom_dist = np.random.binomial(1, perc_heads, 1000)
11 | list_of_means = []
12 | for i in range(0, 1000):
13 | list_of_means.append(np.random.choice(binom_dist, 100, replace=True).mean())
14 |
15 | fig, ax = plt.subplots()
16 | plt.hist(list_of_means, range=[0,1])
17 | plt.title(graph_title)
18 | st.pyplot(fig)
--------------------------------------------------------------------------------
/Chapter01/clt_app/hello_world.py:
--------------------------------------------------------------------------------
1 | import streamlit as st
2 |
3 | st.write('Hello World')
--------------------------------------------------------------------------------
/Chapter01/plotting_app/plot_demo.py:
--------------------------------------------------------------------------------
1 | import streamlit as st
2 | import time
3 | import numpy as np
4 |
5 | progress_bar = st.sidebar.progress(0)
6 | status_text = st.sidebar.empty()
7 | last_rows = np.random.randn(1, 1)
8 | chart = st.line_chart(last_rows)
9 |
10 | for i in range(1, 101):
11 | new_rows = last_rows[-1, :] + np.random.randn(50, 1).cumsum(axis=0)
12 | status_text.text("%i%% Complete" % i)
13 | chart.add_rows(new_rows)
14 | progress_bar.progress(i)
15 | last_rows = new_rows
16 | time.sleep(0.05)
17 |
18 | progress_bar.empty()
19 |
20 | # Streamlit widgets automatically run the script from top to bottom. Since
21 | # this button is not connected to any other logic, it just causes a plain
22 | # rerun.
23 | st.button("Re-run")
--------------------------------------------------------------------------------
/Chapter02/penguin_app/penguins.csv:
--------------------------------------------------------------------------------
1 | species,island,bill_length_mm,bill_depth_mm,flipper_length_mm,body_mass_g,sex,year
2 | Adelie,Torgersen,39.1,18.7,181.0,3750.0,male,2007
3 | Adelie,Torgersen,39.5,17.4,186.0,3800.0,female,2007
4 | Adelie,Torgersen,40.3,18.0,195.0,3250.0,female,2007
5 | Adelie,Torgersen,,,,,,2007
6 | Adelie,Torgersen,36.7,19.3,193.0,3450.0,female,2007
7 | Adelie,Torgersen,39.3,20.6,190.0,3650.0,male,2007
8 | Adelie,Torgersen,38.9,17.8,181.0,3625.0,female,2007
9 | Adelie,Torgersen,39.2,19.6,195.0,4675.0,male,2007
10 | Adelie,Torgersen,34.1,18.1,193.0,3475.0,,2007
11 | Adelie,Torgersen,42.0,20.2,190.0,4250.0,,2007
12 | Adelie,Torgersen,37.8,17.1,186.0,3300.0,,2007
13 | Adelie,Torgersen,37.8,17.3,180.0,3700.0,,2007
14 | Adelie,Torgersen,41.1,17.6,182.0,3200.0,female,2007
15 | Adelie,Torgersen,38.6,21.2,191.0,3800.0,male,2007
16 | Adelie,Torgersen,34.6,21.1,198.0,4400.0,male,2007
17 | Adelie,Torgersen,36.6,17.8,185.0,3700.0,female,2007
18 | Adelie,Torgersen,38.7,19.0,195.0,3450.0,female,2007
19 | Adelie,Torgersen,42.5,20.7,197.0,4500.0,male,2007
20 | Adelie,Torgersen,34.4,18.4,184.0,3325.0,female,2007
21 | Adelie,Torgersen,46.0,21.5,194.0,4200.0,male,2007
22 | Adelie,Biscoe,37.8,18.3,174.0,3400.0,female,2007
23 | Adelie,Biscoe,37.7,18.7,180.0,3600.0,male,2007
24 | Adelie,Biscoe,35.9,19.2,189.0,3800.0,female,2007
25 | Adelie,Biscoe,38.2,18.1,185.0,3950.0,male,2007
26 | Adelie,Biscoe,38.8,17.2,180.0,3800.0,male,2007
27 | Adelie,Biscoe,35.3,18.9,187.0,3800.0,female,2007
28 | Adelie,Biscoe,40.6,18.6,183.0,3550.0,male,2007
29 | Adelie,Biscoe,40.5,17.9,187.0,3200.0,female,2007
30 | Adelie,Biscoe,37.9,18.6,172.0,3150.0,female,2007
31 | Adelie,Biscoe,40.5,18.9,180.0,3950.0,male,2007
32 | Adelie,Dream,39.5,16.7,178.0,3250.0,female,2007
33 | Adelie,Dream,37.2,18.1,178.0,3900.0,male,2007
34 | Adelie,Dream,39.5,17.8,188.0,3300.0,female,2007
35 | Adelie,Dream,40.9,18.9,184.0,3900.0,male,2007
36 | Adelie,Dream,36.4,17.0,195.0,3325.0,female,2007
37 | Adelie,Dream,39.2,21.1,196.0,4150.0,male,2007
38 | Adelie,Dream,38.8,20.0,190.0,3950.0,male,2007
39 | Adelie,Dream,42.2,18.5,180.0,3550.0,female,2007
40 | Adelie,Dream,37.6,19.3,181.0,3300.0,female,2007
41 | Adelie,Dream,39.8,19.1,184.0,4650.0,male,2007
42 | Adelie,Dream,36.5,18.0,182.0,3150.0,female,2007
43 | Adelie,Dream,40.8,18.4,195.0,3900.0,male,2007
44 | Adelie,Dream,36.0,18.5,186.0,3100.0,female,2007
45 | Adelie,Dream,44.1,19.7,196.0,4400.0,male,2007
46 | Adelie,Dream,37.0,16.9,185.0,3000.0,female,2007
47 | Adelie,Dream,39.6,18.8,190.0,4600.0,male,2007
48 | Adelie,Dream,41.1,19.0,182.0,3425.0,male,2007
49 | Adelie,Dream,37.5,18.9,179.0,2975.0,,2007
50 | Adelie,Dream,36.0,17.9,190.0,3450.0,female,2007
51 | Adelie,Dream,42.3,21.2,191.0,4150.0,male,2007
52 | Adelie,Biscoe,39.6,17.7,186.0,3500.0,female,2008
53 | Adelie,Biscoe,40.1,18.9,188.0,4300.0,male,2008
54 | Adelie,Biscoe,35.0,17.9,190.0,3450.0,female,2008
55 | Adelie,Biscoe,42.0,19.5,200.0,4050.0,male,2008
56 | Adelie,Biscoe,34.5,18.1,187.0,2900.0,female,2008
57 | Adelie,Biscoe,41.4,18.6,191.0,3700.0,male,2008
58 | Adelie,Biscoe,39.0,17.5,186.0,3550.0,female,2008
59 | Adelie,Biscoe,40.6,18.8,193.0,3800.0,male,2008
60 | Adelie,Biscoe,36.5,16.6,181.0,2850.0,female,2008
61 | Adelie,Biscoe,37.6,19.1,194.0,3750.0,male,2008
62 | Adelie,Biscoe,35.7,16.9,185.0,3150.0,female,2008
63 | Adelie,Biscoe,41.3,21.1,195.0,4400.0,male,2008
64 | Adelie,Biscoe,37.6,17.0,185.0,3600.0,female,2008
65 | Adelie,Biscoe,41.1,18.2,192.0,4050.0,male,2008
66 | Adelie,Biscoe,36.4,17.1,184.0,2850.0,female,2008
67 | Adelie,Biscoe,41.6,18.0,192.0,3950.0,male,2008
68 | Adelie,Biscoe,35.5,16.2,195.0,3350.0,female,2008
69 | Adelie,Biscoe,41.1,19.1,188.0,4100.0,male,2008
70 | Adelie,Torgersen,35.9,16.6,190.0,3050.0,female,2008
71 | Adelie,Torgersen,41.8,19.4,198.0,4450.0,male,2008
72 | Adelie,Torgersen,33.5,19.0,190.0,3600.0,female,2008
73 | Adelie,Torgersen,39.7,18.4,190.0,3900.0,male,2008
74 | Adelie,Torgersen,39.6,17.2,196.0,3550.0,female,2008
75 | Adelie,Torgersen,45.8,18.9,197.0,4150.0,male,2008
76 | Adelie,Torgersen,35.5,17.5,190.0,3700.0,female,2008
77 | Adelie,Torgersen,42.8,18.5,195.0,4250.0,male,2008
78 | Adelie,Torgersen,40.9,16.8,191.0,3700.0,female,2008
79 | Adelie,Torgersen,37.2,19.4,184.0,3900.0,male,2008
80 | Adelie,Torgersen,36.2,16.1,187.0,3550.0,female,2008
81 | Adelie,Torgersen,42.1,19.1,195.0,4000.0,male,2008
82 | Adelie,Torgersen,34.6,17.2,189.0,3200.0,female,2008
83 | Adelie,Torgersen,42.9,17.6,196.0,4700.0,male,2008
84 | Adelie,Torgersen,36.7,18.8,187.0,3800.0,female,2008
85 | Adelie,Torgersen,35.1,19.4,193.0,4200.0,male,2008
86 | Adelie,Dream,37.3,17.8,191.0,3350.0,female,2008
87 | Adelie,Dream,41.3,20.3,194.0,3550.0,male,2008
88 | Adelie,Dream,36.3,19.5,190.0,3800.0,male,2008
89 | Adelie,Dream,36.9,18.6,189.0,3500.0,female,2008
90 | Adelie,Dream,38.3,19.2,189.0,3950.0,male,2008
91 | Adelie,Dream,38.9,18.8,190.0,3600.0,female,2008
92 | Adelie,Dream,35.7,18.0,202.0,3550.0,female,2008
93 | Adelie,Dream,41.1,18.1,205.0,4300.0,male,2008
94 | Adelie,Dream,34.0,17.1,185.0,3400.0,female,2008
95 | Adelie,Dream,39.6,18.1,186.0,4450.0,male,2008
96 | Adelie,Dream,36.2,17.3,187.0,3300.0,female,2008
97 | Adelie,Dream,40.8,18.9,208.0,4300.0,male,2008
98 | Adelie,Dream,38.1,18.6,190.0,3700.0,female,2008
99 | Adelie,Dream,40.3,18.5,196.0,4350.0,male,2008
100 | Adelie,Dream,33.1,16.1,178.0,2900.0,female,2008
101 | Adelie,Dream,43.2,18.5,192.0,4100.0,male,2008
102 | Adelie,Biscoe,35.0,17.9,192.0,3725.0,female,2009
103 | Adelie,Biscoe,41.0,20.0,203.0,4725.0,male,2009
104 | Adelie,Biscoe,37.7,16.0,183.0,3075.0,female,2009
105 | Adelie,Biscoe,37.8,20.0,190.0,4250.0,male,2009
106 | Adelie,Biscoe,37.9,18.6,193.0,2925.0,female,2009
107 | Adelie,Biscoe,39.7,18.9,184.0,3550.0,male,2009
108 | Adelie,Biscoe,38.6,17.2,199.0,3750.0,female,2009
109 | Adelie,Biscoe,38.2,20.0,190.0,3900.0,male,2009
110 | Adelie,Biscoe,38.1,17.0,181.0,3175.0,female,2009
111 | Adelie,Biscoe,43.2,19.0,197.0,4775.0,male,2009
112 | Adelie,Biscoe,38.1,16.5,198.0,3825.0,female,2009
113 | Adelie,Biscoe,45.6,20.3,191.0,4600.0,male,2009
114 | Adelie,Biscoe,39.7,17.7,193.0,3200.0,female,2009
115 | Adelie,Biscoe,42.2,19.5,197.0,4275.0,male,2009
116 | Adelie,Biscoe,39.6,20.7,191.0,3900.0,female,2009
117 | Adelie,Biscoe,42.7,18.3,196.0,4075.0,male,2009
118 | Adelie,Torgersen,38.6,17.0,188.0,2900.0,female,2009
119 | Adelie,Torgersen,37.3,20.5,199.0,3775.0,male,2009
120 | Adelie,Torgersen,35.7,17.0,189.0,3350.0,female,2009
121 | Adelie,Torgersen,41.1,18.6,189.0,3325.0,male,2009
122 | Adelie,Torgersen,36.2,17.2,187.0,3150.0,female,2009
123 | Adelie,Torgersen,37.7,19.8,198.0,3500.0,male,2009
124 | Adelie,Torgersen,40.2,17.0,176.0,3450.0,female,2009
125 | Adelie,Torgersen,41.4,18.5,202.0,3875.0,male,2009
126 | Adelie,Torgersen,35.2,15.9,186.0,3050.0,female,2009
127 | Adelie,Torgersen,40.6,19.0,199.0,4000.0,male,2009
128 | Adelie,Torgersen,38.8,17.6,191.0,3275.0,female,2009
129 | Adelie,Torgersen,41.5,18.3,195.0,4300.0,male,2009
130 | Adelie,Torgersen,39.0,17.1,191.0,3050.0,female,2009
131 | Adelie,Torgersen,44.1,18.0,210.0,4000.0,male,2009
132 | Adelie,Torgersen,38.5,17.9,190.0,3325.0,female,2009
133 | Adelie,Torgersen,43.1,19.2,197.0,3500.0,male,2009
134 | Adelie,Dream,36.8,18.5,193.0,3500.0,female,2009
135 | Adelie,Dream,37.5,18.5,199.0,4475.0,male,2009
136 | Adelie,Dream,38.1,17.6,187.0,3425.0,female,2009
137 | Adelie,Dream,41.1,17.5,190.0,3900.0,male,2009
138 | Adelie,Dream,35.6,17.5,191.0,3175.0,female,2009
139 | Adelie,Dream,40.2,20.1,200.0,3975.0,male,2009
140 | Adelie,Dream,37.0,16.5,185.0,3400.0,female,2009
141 | Adelie,Dream,39.7,17.9,193.0,4250.0,male,2009
142 | Adelie,Dream,40.2,17.1,193.0,3400.0,female,2009
143 | Adelie,Dream,40.6,17.2,187.0,3475.0,male,2009
144 | Adelie,Dream,32.1,15.5,188.0,3050.0,female,2009
145 | Adelie,Dream,40.7,17.0,190.0,3725.0,male,2009
146 | Adelie,Dream,37.3,16.8,192.0,3000.0,female,2009
147 | Adelie,Dream,39.0,18.7,185.0,3650.0,male,2009
148 | Adelie,Dream,39.2,18.6,190.0,4250.0,male,2009
149 | Adelie,Dream,36.6,18.4,184.0,3475.0,female,2009
150 | Adelie,Dream,36.0,17.8,195.0,3450.0,female,2009
151 | Adelie,Dream,37.8,18.1,193.0,3750.0,male,2009
152 | Adelie,Dream,36.0,17.1,187.0,3700.0,female,2009
153 | Adelie,Dream,41.5,18.5,201.0,4000.0,male,2009
154 | Gentoo,Biscoe,46.1,13.2,211.0,4500.0,female,2007
155 | Gentoo,Biscoe,50.0,16.3,230.0,5700.0,male,2007
156 | Gentoo,Biscoe,48.7,14.1,210.0,4450.0,female,2007
157 | Gentoo,Biscoe,50.0,15.2,218.0,5700.0,male,2007
158 | Gentoo,Biscoe,47.6,14.5,215.0,5400.0,male,2007
159 | Gentoo,Biscoe,46.5,13.5,210.0,4550.0,female,2007
160 | Gentoo,Biscoe,45.4,14.6,211.0,4800.0,female,2007
161 | Gentoo,Biscoe,46.7,15.3,219.0,5200.0,male,2007
162 | Gentoo,Biscoe,43.3,13.4,209.0,4400.0,female,2007
163 | Gentoo,Biscoe,46.8,15.4,215.0,5150.0,male,2007
164 | Gentoo,Biscoe,40.9,13.7,214.0,4650.0,female,2007
165 | Gentoo,Biscoe,49.0,16.1,216.0,5550.0,male,2007
166 | Gentoo,Biscoe,45.5,13.7,214.0,4650.0,female,2007
167 | Gentoo,Biscoe,48.4,14.6,213.0,5850.0,male,2007
168 | Gentoo,Biscoe,45.8,14.6,210.0,4200.0,female,2007
169 | Gentoo,Biscoe,49.3,15.7,217.0,5850.0,male,2007
170 | Gentoo,Biscoe,42.0,13.5,210.0,4150.0,female,2007
171 | Gentoo,Biscoe,49.2,15.2,221.0,6300.0,male,2007
172 | Gentoo,Biscoe,46.2,14.5,209.0,4800.0,female,2007
173 | Gentoo,Biscoe,48.7,15.1,222.0,5350.0,male,2007
174 | Gentoo,Biscoe,50.2,14.3,218.0,5700.0,male,2007
175 | Gentoo,Biscoe,45.1,14.5,215.0,5000.0,female,2007
176 | Gentoo,Biscoe,46.5,14.5,213.0,4400.0,female,2007
177 | Gentoo,Biscoe,46.3,15.8,215.0,5050.0,male,2007
178 | Gentoo,Biscoe,42.9,13.1,215.0,5000.0,female,2007
179 | Gentoo,Biscoe,46.1,15.1,215.0,5100.0,male,2007
180 | Gentoo,Biscoe,44.5,14.3,216.0,4100.0,,2007
181 | Gentoo,Biscoe,47.8,15.0,215.0,5650.0,male,2007
182 | Gentoo,Biscoe,48.2,14.3,210.0,4600.0,female,2007
183 | Gentoo,Biscoe,50.0,15.3,220.0,5550.0,male,2007
184 | Gentoo,Biscoe,47.3,15.3,222.0,5250.0,male,2007
185 | Gentoo,Biscoe,42.8,14.2,209.0,4700.0,female,2007
186 | Gentoo,Biscoe,45.1,14.5,207.0,5050.0,female,2007
187 | Gentoo,Biscoe,59.6,17.0,230.0,6050.0,male,2007
188 | Gentoo,Biscoe,49.1,14.8,220.0,5150.0,female,2008
189 | Gentoo,Biscoe,48.4,16.3,220.0,5400.0,male,2008
190 | Gentoo,Biscoe,42.6,13.7,213.0,4950.0,female,2008
191 | Gentoo,Biscoe,44.4,17.3,219.0,5250.0,male,2008
192 | Gentoo,Biscoe,44.0,13.6,208.0,4350.0,female,2008
193 | Gentoo,Biscoe,48.7,15.7,208.0,5350.0,male,2008
194 | Gentoo,Biscoe,42.7,13.7,208.0,3950.0,female,2008
195 | Gentoo,Biscoe,49.6,16.0,225.0,5700.0,male,2008
196 | Gentoo,Biscoe,45.3,13.7,210.0,4300.0,female,2008
197 | Gentoo,Biscoe,49.6,15.0,216.0,4750.0,male,2008
198 | Gentoo,Biscoe,50.5,15.9,222.0,5550.0,male,2008
199 | Gentoo,Biscoe,43.6,13.9,217.0,4900.0,female,2008
200 | Gentoo,Biscoe,45.5,13.9,210.0,4200.0,female,2008
201 | Gentoo,Biscoe,50.5,15.9,225.0,5400.0,male,2008
202 | Gentoo,Biscoe,44.9,13.3,213.0,5100.0,female,2008
203 | Gentoo,Biscoe,45.2,15.8,215.0,5300.0,male,2008
204 | Gentoo,Biscoe,46.6,14.2,210.0,4850.0,female,2008
205 | Gentoo,Biscoe,48.5,14.1,220.0,5300.0,male,2008
206 | Gentoo,Biscoe,45.1,14.4,210.0,4400.0,female,2008
207 | Gentoo,Biscoe,50.1,15.0,225.0,5000.0,male,2008
208 | Gentoo,Biscoe,46.5,14.4,217.0,4900.0,female,2008
209 | Gentoo,Biscoe,45.0,15.4,220.0,5050.0,male,2008
210 | Gentoo,Biscoe,43.8,13.9,208.0,4300.0,female,2008
211 | Gentoo,Biscoe,45.5,15.0,220.0,5000.0,male,2008
212 | Gentoo,Biscoe,43.2,14.5,208.0,4450.0,female,2008
213 | Gentoo,Biscoe,50.4,15.3,224.0,5550.0,male,2008
214 | Gentoo,Biscoe,45.3,13.8,208.0,4200.0,female,2008
215 | Gentoo,Biscoe,46.2,14.9,221.0,5300.0,male,2008
216 | Gentoo,Biscoe,45.7,13.9,214.0,4400.0,female,2008
217 | Gentoo,Biscoe,54.3,15.7,231.0,5650.0,male,2008
218 | Gentoo,Biscoe,45.8,14.2,219.0,4700.0,female,2008
219 | Gentoo,Biscoe,49.8,16.8,230.0,5700.0,male,2008
220 | Gentoo,Biscoe,46.2,14.4,214.0,4650.0,,2008
221 | Gentoo,Biscoe,49.5,16.2,229.0,5800.0,male,2008
222 | Gentoo,Biscoe,43.5,14.2,220.0,4700.0,female,2008
223 | Gentoo,Biscoe,50.7,15.0,223.0,5550.0,male,2008
224 | Gentoo,Biscoe,47.7,15.0,216.0,4750.0,female,2008
225 | Gentoo,Biscoe,46.4,15.6,221.0,5000.0,male,2008
226 | Gentoo,Biscoe,48.2,15.6,221.0,5100.0,male,2008
227 | Gentoo,Biscoe,46.5,14.8,217.0,5200.0,female,2008
228 | Gentoo,Biscoe,46.4,15.0,216.0,4700.0,female,2008
229 | Gentoo,Biscoe,48.6,16.0,230.0,5800.0,male,2008
230 | Gentoo,Biscoe,47.5,14.2,209.0,4600.0,female,2008
231 | Gentoo,Biscoe,51.1,16.3,220.0,6000.0,male,2008
232 | Gentoo,Biscoe,45.2,13.8,215.0,4750.0,female,2008
233 | Gentoo,Biscoe,45.2,16.4,223.0,5950.0,male,2008
234 | Gentoo,Biscoe,49.1,14.5,212.0,4625.0,female,2009
235 | Gentoo,Biscoe,52.5,15.6,221.0,5450.0,male,2009
236 | Gentoo,Biscoe,47.4,14.6,212.0,4725.0,female,2009
237 | Gentoo,Biscoe,50.0,15.9,224.0,5350.0,male,2009
238 | Gentoo,Biscoe,44.9,13.8,212.0,4750.0,female,2009
239 | Gentoo,Biscoe,50.8,17.3,228.0,5600.0,male,2009
240 | Gentoo,Biscoe,43.4,14.4,218.0,4600.0,female,2009
241 | Gentoo,Biscoe,51.3,14.2,218.0,5300.0,male,2009
242 | Gentoo,Biscoe,47.5,14.0,212.0,4875.0,female,2009
243 | Gentoo,Biscoe,52.1,17.0,230.0,5550.0,male,2009
244 | Gentoo,Biscoe,47.5,15.0,218.0,4950.0,female,2009
245 | Gentoo,Biscoe,52.2,17.1,228.0,5400.0,male,2009
246 | Gentoo,Biscoe,45.5,14.5,212.0,4750.0,female,2009
247 | Gentoo,Biscoe,49.5,16.1,224.0,5650.0,male,2009
248 | Gentoo,Biscoe,44.5,14.7,214.0,4850.0,female,2009
249 | Gentoo,Biscoe,50.8,15.7,226.0,5200.0,male,2009
250 | Gentoo,Biscoe,49.4,15.8,216.0,4925.0,male,2009
251 | Gentoo,Biscoe,46.9,14.6,222.0,4875.0,female,2009
252 | Gentoo,Biscoe,48.4,14.4,203.0,4625.0,female,2009
253 | Gentoo,Biscoe,51.1,16.5,225.0,5250.0,male,2009
254 | Gentoo,Biscoe,48.5,15.0,219.0,4850.0,female,2009
255 | Gentoo,Biscoe,55.9,17.0,228.0,5600.0,male,2009
256 | Gentoo,Biscoe,47.2,15.5,215.0,4975.0,female,2009
257 | Gentoo,Biscoe,49.1,15.0,228.0,5500.0,male,2009
258 | Gentoo,Biscoe,47.3,13.8,216.0,4725.0,,2009
259 | Gentoo,Biscoe,46.8,16.1,215.0,5500.0,male,2009
260 | Gentoo,Biscoe,41.7,14.7,210.0,4700.0,female,2009
261 | Gentoo,Biscoe,53.4,15.8,219.0,5500.0,male,2009
262 | Gentoo,Biscoe,43.3,14.0,208.0,4575.0,female,2009
263 | Gentoo,Biscoe,48.1,15.1,209.0,5500.0,male,2009
264 | Gentoo,Biscoe,50.5,15.2,216.0,5000.0,female,2009
265 | Gentoo,Biscoe,49.8,15.9,229.0,5950.0,male,2009
266 | Gentoo,Biscoe,43.5,15.2,213.0,4650.0,female,2009
267 | Gentoo,Biscoe,51.5,16.3,230.0,5500.0,male,2009
268 | Gentoo,Biscoe,46.2,14.1,217.0,4375.0,female,2009
269 | Gentoo,Biscoe,55.1,16.0,230.0,5850.0,male,2009
270 | Gentoo,Biscoe,44.5,15.7,217.0,4875.0,,2009
271 | Gentoo,Biscoe,48.8,16.2,222.0,6000.0,male,2009
272 | Gentoo,Biscoe,47.2,13.7,214.0,4925.0,female,2009
273 | Gentoo,Biscoe,,,,,,2009
274 | Gentoo,Biscoe,46.8,14.3,215.0,4850.0,female,2009
275 | Gentoo,Biscoe,50.4,15.7,222.0,5750.0,male,2009
276 | Gentoo,Biscoe,45.2,14.8,212.0,5200.0,female,2009
277 | Gentoo,Biscoe,49.9,16.1,213.0,5400.0,male,2009
278 | Chinstrap,Dream,46.5,17.9,192.0,3500.0,female,2007
279 | Chinstrap,Dream,50.0,19.5,196.0,3900.0,male,2007
280 | Chinstrap,Dream,51.3,19.2,193.0,3650.0,male,2007
281 | Chinstrap,Dream,45.4,18.7,188.0,3525.0,female,2007
282 | Chinstrap,Dream,52.7,19.8,197.0,3725.0,male,2007
283 | Chinstrap,Dream,45.2,17.8,198.0,3950.0,female,2007
284 | Chinstrap,Dream,46.1,18.2,178.0,3250.0,female,2007
285 | Chinstrap,Dream,51.3,18.2,197.0,3750.0,male,2007
286 | Chinstrap,Dream,46.0,18.9,195.0,4150.0,female,2007
287 | Chinstrap,Dream,51.3,19.9,198.0,3700.0,male,2007
288 | Chinstrap,Dream,46.6,17.8,193.0,3800.0,female,2007
289 | Chinstrap,Dream,51.7,20.3,194.0,3775.0,male,2007
290 | Chinstrap,Dream,47.0,17.3,185.0,3700.0,female,2007
291 | Chinstrap,Dream,52.0,18.1,201.0,4050.0,male,2007
292 | Chinstrap,Dream,45.9,17.1,190.0,3575.0,female,2007
293 | Chinstrap,Dream,50.5,19.6,201.0,4050.0,male,2007
294 | Chinstrap,Dream,50.3,20.0,197.0,3300.0,male,2007
295 | Chinstrap,Dream,58.0,17.8,181.0,3700.0,female,2007
296 | Chinstrap,Dream,46.4,18.6,190.0,3450.0,female,2007
297 | Chinstrap,Dream,49.2,18.2,195.0,4400.0,male,2007
298 | Chinstrap,Dream,42.4,17.3,181.0,3600.0,female,2007
299 | Chinstrap,Dream,48.5,17.5,191.0,3400.0,male,2007
300 | Chinstrap,Dream,43.2,16.6,187.0,2900.0,female,2007
301 | Chinstrap,Dream,50.6,19.4,193.0,3800.0,male,2007
302 | Chinstrap,Dream,46.7,17.9,195.0,3300.0,female,2007
303 | Chinstrap,Dream,52.0,19.0,197.0,4150.0,male,2007
304 | Chinstrap,Dream,50.5,18.4,200.0,3400.0,female,2008
305 | Chinstrap,Dream,49.5,19.0,200.0,3800.0,male,2008
306 | Chinstrap,Dream,46.4,17.8,191.0,3700.0,female,2008
307 | Chinstrap,Dream,52.8,20.0,205.0,4550.0,male,2008
308 | Chinstrap,Dream,40.9,16.6,187.0,3200.0,female,2008
309 | Chinstrap,Dream,54.2,20.8,201.0,4300.0,male,2008
310 | Chinstrap,Dream,42.5,16.7,187.0,3350.0,female,2008
311 | Chinstrap,Dream,51.0,18.8,203.0,4100.0,male,2008
312 | Chinstrap,Dream,49.7,18.6,195.0,3600.0,male,2008
313 | Chinstrap,Dream,47.5,16.8,199.0,3900.0,female,2008
314 | Chinstrap,Dream,47.6,18.3,195.0,3850.0,female,2008
315 | Chinstrap,Dream,52.0,20.7,210.0,4800.0,male,2008
316 | Chinstrap,Dream,46.9,16.6,192.0,2700.0,female,2008
317 | Chinstrap,Dream,53.5,19.9,205.0,4500.0,male,2008
318 | Chinstrap,Dream,49.0,19.5,210.0,3950.0,male,2008
319 | Chinstrap,Dream,46.2,17.5,187.0,3650.0,female,2008
320 | Chinstrap,Dream,50.9,19.1,196.0,3550.0,male,2008
321 | Chinstrap,Dream,45.5,17.0,196.0,3500.0,female,2008
322 | Chinstrap,Dream,50.9,17.9,196.0,3675.0,female,2009
323 | Chinstrap,Dream,50.8,18.5,201.0,4450.0,male,2009
324 | Chinstrap,Dream,50.1,17.9,190.0,3400.0,female,2009
325 | Chinstrap,Dream,49.0,19.6,212.0,4300.0,male,2009
326 | Chinstrap,Dream,51.5,18.7,187.0,3250.0,male,2009
327 | Chinstrap,Dream,49.8,17.3,198.0,3675.0,female,2009
328 | Chinstrap,Dream,48.1,16.4,199.0,3325.0,female,2009
329 | Chinstrap,Dream,51.4,19.0,201.0,3950.0,male,2009
330 | Chinstrap,Dream,45.7,17.3,193.0,3600.0,female,2009
331 | Chinstrap,Dream,50.7,19.7,203.0,4050.0,male,2009
332 | Chinstrap,Dream,42.5,17.3,187.0,3350.0,female,2009
333 | Chinstrap,Dream,52.2,18.8,197.0,3450.0,male,2009
334 | Chinstrap,Dream,45.2,16.6,191.0,3250.0,female,2009
335 | Chinstrap,Dream,49.3,19.9,203.0,4050.0,male,2009
336 | Chinstrap,Dream,50.2,18.8,202.0,3800.0,male,2009
337 | Chinstrap,Dream,45.6,19.4,194.0,3525.0,female,2009
338 | Chinstrap,Dream,51.9,19.5,206.0,3950.0,male,2009
339 | Chinstrap,Dream,46.8,16.5,189.0,3650.0,female,2009
340 | Chinstrap,Dream,45.7,17.0,195.0,3650.0,female,2009
341 | Chinstrap,Dream,55.8,19.8,207.0,4000.0,male,2009
342 | Chinstrap,Dream,43.5,18.1,202.0,3400.0,female,2009
343 | Chinstrap,Dream,49.6,18.2,193.0,3775.0,male,2009
344 | Chinstrap,Dream,50.8,19.0,210.0,4100.0,male,2009
345 | Chinstrap,Dream,50.2,18.7,198.0,3775.0,female,2009
346 |
--------------------------------------------------------------------------------
/Chapter02/penguin_app/penguins.py:
--------------------------------------------------------------------------------
1 | import streamlit as st
2 | import pandas as pd
3 | import matplotlib.pyplot as plt
4 | import seaborn as sns
5 |
6 | st.title("Palmer's Penguins")
7 | st.markdown('Use this Streamlit app to make your own scatterplot about penguins!')
8 |
9 | selected_x_var = st.selectbox('What do want the x variable to be?',
10 | ['bill_length_mm', 'bill_depth_mm', 'flipper_length_mm', 'body_mass_g'])
11 | selected_y_var = st.selectbox('What about the y?',
12 | ['bill_depth_mm', 'bill_length_mm', 'flipper_length_mm', 'body_mass_g'])
13 |
14 | penguin_file = st.file_uploader('Select Your Local Penguins CSV')
15 | if penguin_file is not None:
16 | penguins_df = pd.read_csv(penguin_file)
17 | else:
18 | st.stop()
19 |
20 | sns.set_style('darkgrid')
21 | markers = {"Adelie": "X", "Gentoo": "s", "Chinstrap":'o'}
22 | fig, ax = plt.subplots()
23 | ax = sns.scatterplot(data = penguins_df, x = selected_x_var,
24 | y = selected_y_var, hue = 'species', markers = markers,
25 | style = 'species')
26 | plt.xlabel(selected_x_var)
27 | plt.ylabel(selected_y_var)
28 | plt.title("Scatterplot of Palmer's Penguins")
29 | st.pyplot(fig)
--------------------------------------------------------------------------------
/Chapter02/penguin_app/requirements.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Getting-started-with-Streamlit-for-Data-Science/50677d3f08c78f796b05cb1caf76246df3ff08ff/Chapter02/penguin_app/requirements.txt
--------------------------------------------------------------------------------
/Chapter03/trees_app/.streamlit/config.toml:
--------------------------------------------------------------------------------
1 | # Below are all the sections and options you can have in ~/.streamlit/config.toml.
2 |
3 | [global]
4 |
5 | # By default, Streamlit checks if the Python watchdog module is available and, if not, prints a warning asking for you to install it. The watchdog module is not required, but highly recommended. It improves Streamlit's ability to detect changes to files in your filesystem.
6 | # If you'd like to turn off this warning, set this to True.
7 | # Default: false
8 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
9 | disableWatchdogWarning = false
10 |
11 | # If True, will show a warning when you run a Streamlit-enabled script via "python my_script.py".
12 | # Default: true
13 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
14 | showWarningOnDirectExecution = true
15 |
16 |
17 | [logger]
18 |
19 | # Level of logging: 'error', 'warning', 'info', or 'debug'.
20 | # Default: 'info'
21 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
22 | level = "info"
23 |
24 | # String format for logging messages. If logger.datetimeFormat is set, logger messages will default to `%(asctime)s.%(msecs)03d %(message)s`. See [Python's documentation](https://docs.python.org/2.6/library/logging.html#formatter-objects) for available attributes.
25 | # Default: None
26 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
27 | messageFormat = "%(asctime)s %(message)s"
28 |
29 |
30 | [client]
31 |
32 | # Whether to enable st.cache.
33 | # Default: true
34 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
35 | caching = true
36 |
37 | # If false, makes your Streamlit script not draw to a Streamlit app.
38 | # Default: true
39 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
40 | displayEnabled = true
41 |
42 | # Controls whether uncaught app exceptions are displayed in the browser. By default, this is set to True and Streamlit displays app exceptions and associated tracebacks in the browser.
43 | # If set to False, an exception will result in a generic message being shown in the browser, and exceptions and tracebacks will be printed to the console only.
44 | # Default: true
45 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
46 | showErrorDetails = true
47 |
48 |
49 | [runner]
50 |
51 | # Allows you to type a variable or string by itself in a single line of Python code to write it to the app.
52 | # Default: true
53 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
54 | magicEnabled = true
55 |
56 | # Install a Python tracer to allow you to stop or pause your script at any point and introspect it. As a side-effect, this slows down your script's execution.
57 | # Default: false
58 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
59 | installTracer = false
60 |
61 | # Sets the MPLBACKEND environment variable to Agg inside Streamlit to prevent Python crashing.
62 | # Default: true
63 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
64 | fixMatplotlib = true
65 |
66 | # Run the Python Garbage Collector after each script execution. This can help avoid excess memory use in Streamlit apps, but could introduce delay in rerunning the app script for high-memory-use applications.
67 | # Default: true
68 | postScriptGC = true
69 |
70 |
71 | [server]
72 |
73 | # List of folders that should not be watched for changes. This impacts both "Run on Save" and @st.cache.
74 | # Relative paths will be taken as relative to the current working directory.
75 | # Example: ['/home/user1/env', 'relative/path/to/folder']
76 | # Default: []
77 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
78 | folderWatchBlacklist = []
79 |
80 | # Change the type of file watcher used by Streamlit, or turn it off completely.
81 | # Allowed values: * "auto" : Streamlit will attempt to use the watchdog module, and falls back to polling if watchdog is not available. * "watchdog" : Force Streamlit to use the watchdog module. * "poll" : Force Streamlit to always use polling. * "none" : Streamlit will not watch files.
82 | # Default: "auto"
83 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
84 | fileWatcherType = "auto"
85 |
86 | # Symmetric key used to produce signed cookies. If deploying on multiple replicas, this should be set to the same value across all replicas to ensure they all share the same secret.
87 | # Default: randomly generated secret key.
88 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
89 | cookieSecret = "2c414c16ac4fd30c17ae02fb65126628e9b4718a4332c994239eab21b182b1b9"
90 |
91 | # If false, will attempt to open a browser window on start.
92 | # Default: false unless (1) we are on a Linux box where DISPLAY is unset, or (2) server.liveSave is set.
93 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
94 | headless = false
95 |
96 | # Automatically rerun script when the file is modified on disk.
97 | # Default: false
98 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
99 | runOnSave = false
100 |
101 | # The address where the server will listen for client and browser connections. Use this if you want to bind the server to a specific address. If set, the server will only be accessible from this address, and not from any aliases (like localhost).
102 | # Default: (unset)
103 | #address =
104 |
105 | # The port where the server will listen for browser connections.
106 | # Default: 8501
107 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
108 | port = 8501
109 |
110 | # The base path for the URL where Streamlit should be served from.
111 | # Default: ""
112 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
113 | baseUrlPath = ""
114 |
115 | # Enables support for Cross-Origin Request Sharing (CORS) protection, for added security.
116 | # Due to conflicts between CORS and XSRF, if `server.enableXsrfProtection` is on and `server.enableCORS` is off at the same time, we will prioritize `server.enableXsrfProtection`.
117 | # Default: true
118 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
119 | enableCORS = true
120 |
121 | # Enables support for Cross-Site Request Forgery (XSRF) protection, for added security.
122 | # Due to conflicts between CORS and XSRF, if `server.enableXsrfProtection` is on and `server.enableCORS` is off at the same time, we will prioritize `server.enableXsrfProtection`.
123 | # Default: true
124 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
125 | enableXsrfProtection = true
126 |
127 | # Max size, in megabytes, for files uploaded with the file_uploader.
128 | # Default: 200
129 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
130 | maxUploadSize = 200
131 |
132 | # Enables support for websocket compression.
133 | # Default: true
134 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
135 | enableWebsocketCompression = true
136 |
137 |
138 | [browser]
139 |
140 | # Internet address where users should point their browsers in order to connect to the app. Can be IP address or DNS name and path.
141 | # This is used to: - Set the correct URL for CORS and XSRF protection purposes. - Show the URL on the terminal - Open the browser - Tell the browser where to connect to the server when in liveSave mode.
142 | # Default: 'localhost'
143 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
144 | serverAddress = "localhost"
145 |
146 | # Whether to send usage statistics to Streamlit.
147 | # Default: true
148 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
149 | gatherUsageStats = true
150 |
151 | # Port where users should point their browsers in order to connect to the app.
152 | # This is used to: - Set the correct URL for CORS and XSRF protection purposes. - Show the URL on the terminal - Open the browser - Tell the browser where to connect to the server when in liveSave mode.
153 | # Default: whatever value is set in server.port.
154 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
155 | serverPort = 8501
156 |
157 |
158 | [mapbox]
159 |
160 | # Configure Streamlit to use a custom Mapbox token for elements like st.pydeck_chart and st.map. To get a token for yourself, create an account at https://mapbox.com. It's free (for moderate usage levels)!
161 | # Default: ""
162 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
163 | token = "pk.eyJ1IjoidHlsZXJqcmljaGFyZHMiLCJhIjoiY2p1YWRvYmlvMDFuZDN5bjV4NmJ3OWpieCJ9.jZzjCeslaeVUrhEFaQCX7Q"
164 |
165 |
166 | [deprecation]
167 |
168 | # Set to false to disable the deprecation warning for the file uploader encoding.
169 | # Default: "True"
170 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
171 | showfileUploaderEncoding = "True"
172 |
173 | # Set to false to disable the deprecation warning for using the global pyplot instance.
174 | # Default: "True"
175 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
176 | showPyplotGlobalUse = "True"
177 |
178 |
179 | [s3]
180 |
181 | # Name of the AWS S3 bucket to save apps.
182 | # Default: (unset)
183 | #bucket =
184 |
185 | # URL root for external view of Streamlit apps.
186 | # Default: (unset)
187 | #url =
188 |
189 | # Access key to write to the S3 bucket.
190 | # Leave unset if you want to use an AWS profile.
191 | # Default: (unset)
192 | #accessKeyId =
193 |
194 | # Secret access key to write to the S3 bucket.
195 | # Leave unset if you want to use an AWS profile.
196 | # Default: (unset)
197 | #secretAccessKey =
198 |
199 | # The "subdirectory" within the S3 bucket where to save apps.
200 | # S3 calls paths "keys" which is why the keyPrefix is like a subdirectory. Use "" to mean the root directory.
201 | # Default: ""
202 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
203 | keyPrefix = ""
204 |
205 | # AWS region where the bucket is located, e.g. "us-west-2".
206 | # Default: (unset)
207 | #region =
208 |
209 | # AWS credentials profile to use.
210 | # Leave unset to use your default profile.
211 | # Default: (unset)
212 | #profile =
213 |
214 |
215 | [theme]
216 |
217 | # The preset Streamlit theme that your custom theme inherits from. One of "light" or "dark".
218 | #base =
219 |
220 | # Primary accent color for interactive elements.
221 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
222 | primaryColor = "#de8ba1"
223 |
224 | # Background color for the main content area.
225 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
226 | backgroundColor = "#f4f1ea"
227 |
228 | # Background color used for the sidebar and most interactive widgets.
229 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
230 | secondaryBackgroundColor = "#9fe4cc"
231 |
232 | # Color used for almost all text.
233 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
234 | textColor = "#262730"
235 |
236 | # Font family for all text in the app, except code blocks. One of "sans serif", "serif", or "monospace".
237 | # The value below was set in /Users/tylerjrichards/.streamlit/config.toml
238 | font = "sans serif"
239 |
240 |
--------------------------------------------------------------------------------
/Chapter03/trees_app/trees.py:
--------------------------------------------------------------------------------
1 | import streamlit as st
2 | import pandas as pd
3 | import pydeck as pdk
4 |
5 | st.title('SF Trees')
6 | st.write('This app analyses trees in San Francisco using'
7 | ' a dataset kindly provided by SF DPW')
8 |
9 | trees_df = pd.read_csv('trees.csv')
10 | trees_df.dropna(how='any', inplace=True)
11 |
12 | sf_initial_view = pdk.ViewState(
13 | latitude=37.77,
14 | longitude=-122.4,
15 | zoom=11
16 | )
17 |
18 | sp_layer = pdk.Layer(
19 | 'ScatterplotLayer',
20 | data = trees_df,
21 | get_position = ['longitude', 'latitude'],
22 | get_radius=30)
23 |
24 | st.pydeck_chart(pdk.Deck(
25 | map_style='mapbox://styles/mapbox/light-v9',
26 | initial_view_state=sf_initial_view,
27 | layers = [sp_layer]
28 | ))
--------------------------------------------------------------------------------
/Chapter04/penguin_ml/feature_importance.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Getting-started-with-Streamlit-for-Data-Science/50677d3f08c78f796b05cb1caf76246df3ff08ff/Chapter04/penguin_ml/feature_importance.png
--------------------------------------------------------------------------------
/Chapter04/penguin_ml/output_penguin.pickle:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Getting-started-with-Streamlit-for-Data-Science/50677d3f08c78f796b05cb1caf76246df3ff08ff/Chapter04/penguin_ml/output_penguin.pickle
--------------------------------------------------------------------------------
/Chapter04/penguin_ml/penguins.csv:
--------------------------------------------------------------------------------
1 | species,island,bill_length_mm,bill_depth_mm,flipper_length_mm,body_mass_g,sex,year
2 | Adelie,Torgersen,39.1,18.7,181.0,3750.0,male,2007
3 | Adelie,Torgersen,39.5,17.4,186.0,3800.0,female,2007
4 | Adelie,Torgersen,40.3,18.0,195.0,3250.0,female,2007
5 | Adelie,Torgersen,,,,,,2007
6 | Adelie,Torgersen,36.7,19.3,193.0,3450.0,female,2007
7 | Adelie,Torgersen,39.3,20.6,190.0,3650.0,male,2007
8 | Adelie,Torgersen,38.9,17.8,181.0,3625.0,female,2007
9 | Adelie,Torgersen,39.2,19.6,195.0,4675.0,male,2007
10 | Adelie,Torgersen,34.1,18.1,193.0,3475.0,,2007
11 | Adelie,Torgersen,42.0,20.2,190.0,4250.0,,2007
12 | Adelie,Torgersen,37.8,17.1,186.0,3300.0,,2007
13 | Adelie,Torgersen,37.8,17.3,180.0,3700.0,,2007
14 | Adelie,Torgersen,41.1,17.6,182.0,3200.0,female,2007
15 | Adelie,Torgersen,38.6,21.2,191.0,3800.0,male,2007
16 | Adelie,Torgersen,34.6,21.1,198.0,4400.0,male,2007
17 | Adelie,Torgersen,36.6,17.8,185.0,3700.0,female,2007
18 | Adelie,Torgersen,38.7,19.0,195.0,3450.0,female,2007
19 | Adelie,Torgersen,42.5,20.7,197.0,4500.0,male,2007
20 | Adelie,Torgersen,34.4,18.4,184.0,3325.0,female,2007
21 | Adelie,Torgersen,46.0,21.5,194.0,4200.0,male,2007
22 | Adelie,Biscoe,37.8,18.3,174.0,3400.0,female,2007
23 | Adelie,Biscoe,37.7,18.7,180.0,3600.0,male,2007
24 | Adelie,Biscoe,35.9,19.2,189.0,3800.0,female,2007
25 | Adelie,Biscoe,38.2,18.1,185.0,3950.0,male,2007
26 | Adelie,Biscoe,38.8,17.2,180.0,3800.0,male,2007
27 | Adelie,Biscoe,35.3,18.9,187.0,3800.0,female,2007
28 | Adelie,Biscoe,40.6,18.6,183.0,3550.0,male,2007
29 | Adelie,Biscoe,40.5,17.9,187.0,3200.0,female,2007
30 | Adelie,Biscoe,37.9,18.6,172.0,3150.0,female,2007
31 | Adelie,Biscoe,40.5,18.9,180.0,3950.0,male,2007
32 | Adelie,Dream,39.5,16.7,178.0,3250.0,female,2007
33 | Adelie,Dream,37.2,18.1,178.0,3900.0,male,2007
34 | Adelie,Dream,39.5,17.8,188.0,3300.0,female,2007
35 | Adelie,Dream,40.9,18.9,184.0,3900.0,male,2007
36 | Adelie,Dream,36.4,17.0,195.0,3325.0,female,2007
37 | Adelie,Dream,39.2,21.1,196.0,4150.0,male,2007
38 | Adelie,Dream,38.8,20.0,190.0,3950.0,male,2007
39 | Adelie,Dream,42.2,18.5,180.0,3550.0,female,2007
40 | Adelie,Dream,37.6,19.3,181.0,3300.0,female,2007
41 | Adelie,Dream,39.8,19.1,184.0,4650.0,male,2007
42 | Adelie,Dream,36.5,18.0,182.0,3150.0,female,2007
43 | Adelie,Dream,40.8,18.4,195.0,3900.0,male,2007
44 | Adelie,Dream,36.0,18.5,186.0,3100.0,female,2007
45 | Adelie,Dream,44.1,19.7,196.0,4400.0,male,2007
46 | Adelie,Dream,37.0,16.9,185.0,3000.0,female,2007
47 | Adelie,Dream,39.6,18.8,190.0,4600.0,male,2007
48 | Adelie,Dream,41.1,19.0,182.0,3425.0,male,2007
49 | Adelie,Dream,37.5,18.9,179.0,2975.0,,2007
50 | Adelie,Dream,36.0,17.9,190.0,3450.0,female,2007
51 | Adelie,Dream,42.3,21.2,191.0,4150.0,male,2007
52 | Adelie,Biscoe,39.6,17.7,186.0,3500.0,female,2008
53 | Adelie,Biscoe,40.1,18.9,188.0,4300.0,male,2008
54 | Adelie,Biscoe,35.0,17.9,190.0,3450.0,female,2008
55 | Adelie,Biscoe,42.0,19.5,200.0,4050.0,male,2008
56 | Adelie,Biscoe,34.5,18.1,187.0,2900.0,female,2008
57 | Adelie,Biscoe,41.4,18.6,191.0,3700.0,male,2008
58 | Adelie,Biscoe,39.0,17.5,186.0,3550.0,female,2008
59 | Adelie,Biscoe,40.6,18.8,193.0,3800.0,male,2008
60 | Adelie,Biscoe,36.5,16.6,181.0,2850.0,female,2008
61 | Adelie,Biscoe,37.6,19.1,194.0,3750.0,male,2008
62 | Adelie,Biscoe,35.7,16.9,185.0,3150.0,female,2008
63 | Adelie,Biscoe,41.3,21.1,195.0,4400.0,male,2008
64 | Adelie,Biscoe,37.6,17.0,185.0,3600.0,female,2008
65 | Adelie,Biscoe,41.1,18.2,192.0,4050.0,male,2008
66 | Adelie,Biscoe,36.4,17.1,184.0,2850.0,female,2008
67 | Adelie,Biscoe,41.6,18.0,192.0,3950.0,male,2008
68 | Adelie,Biscoe,35.5,16.2,195.0,3350.0,female,2008
69 | Adelie,Biscoe,41.1,19.1,188.0,4100.0,male,2008
70 | Adelie,Torgersen,35.9,16.6,190.0,3050.0,female,2008
71 | Adelie,Torgersen,41.8,19.4,198.0,4450.0,male,2008
72 | Adelie,Torgersen,33.5,19.0,190.0,3600.0,female,2008
73 | Adelie,Torgersen,39.7,18.4,190.0,3900.0,male,2008
74 | Adelie,Torgersen,39.6,17.2,196.0,3550.0,female,2008
75 | Adelie,Torgersen,45.8,18.9,197.0,4150.0,male,2008
76 | Adelie,Torgersen,35.5,17.5,190.0,3700.0,female,2008
77 | Adelie,Torgersen,42.8,18.5,195.0,4250.0,male,2008
78 | Adelie,Torgersen,40.9,16.8,191.0,3700.0,female,2008
79 | Adelie,Torgersen,37.2,19.4,184.0,3900.0,male,2008
80 | Adelie,Torgersen,36.2,16.1,187.0,3550.0,female,2008
81 | Adelie,Torgersen,42.1,19.1,195.0,4000.0,male,2008
82 | Adelie,Torgersen,34.6,17.2,189.0,3200.0,female,2008
83 | Adelie,Torgersen,42.9,17.6,196.0,4700.0,male,2008
84 | Adelie,Torgersen,36.7,18.8,187.0,3800.0,female,2008
85 | Adelie,Torgersen,35.1,19.4,193.0,4200.0,male,2008
86 | Adelie,Dream,37.3,17.8,191.0,3350.0,female,2008
87 | Adelie,Dream,41.3,20.3,194.0,3550.0,male,2008
88 | Adelie,Dream,36.3,19.5,190.0,3800.0,male,2008
89 | Adelie,Dream,36.9,18.6,189.0,3500.0,female,2008
90 | Adelie,Dream,38.3,19.2,189.0,3950.0,male,2008
91 | Adelie,Dream,38.9,18.8,190.0,3600.0,female,2008
92 | Adelie,Dream,35.7,18.0,202.0,3550.0,female,2008
93 | Adelie,Dream,41.1,18.1,205.0,4300.0,male,2008
94 | Adelie,Dream,34.0,17.1,185.0,3400.0,female,2008
95 | Adelie,Dream,39.6,18.1,186.0,4450.0,male,2008
96 | Adelie,Dream,36.2,17.3,187.0,3300.0,female,2008
97 | Adelie,Dream,40.8,18.9,208.0,4300.0,male,2008
98 | Adelie,Dream,38.1,18.6,190.0,3700.0,female,2008
99 | Adelie,Dream,40.3,18.5,196.0,4350.0,male,2008
100 | Adelie,Dream,33.1,16.1,178.0,2900.0,female,2008
101 | Adelie,Dream,43.2,18.5,192.0,4100.0,male,2008
102 | Adelie,Biscoe,35.0,17.9,192.0,3725.0,female,2009
103 | Adelie,Biscoe,41.0,20.0,203.0,4725.0,male,2009
104 | Adelie,Biscoe,37.7,16.0,183.0,3075.0,female,2009
105 | Adelie,Biscoe,37.8,20.0,190.0,4250.0,male,2009
106 | Adelie,Biscoe,37.9,18.6,193.0,2925.0,female,2009
107 | Adelie,Biscoe,39.7,18.9,184.0,3550.0,male,2009
108 | Adelie,Biscoe,38.6,17.2,199.0,3750.0,female,2009
109 | Adelie,Biscoe,38.2,20.0,190.0,3900.0,male,2009
110 | Adelie,Biscoe,38.1,17.0,181.0,3175.0,female,2009
111 | Adelie,Biscoe,43.2,19.0,197.0,4775.0,male,2009
112 | Adelie,Biscoe,38.1,16.5,198.0,3825.0,female,2009
113 | Adelie,Biscoe,45.6,20.3,191.0,4600.0,male,2009
114 | Adelie,Biscoe,39.7,17.7,193.0,3200.0,female,2009
115 | Adelie,Biscoe,42.2,19.5,197.0,4275.0,male,2009
116 | Adelie,Biscoe,39.6,20.7,191.0,3900.0,female,2009
117 | Adelie,Biscoe,42.7,18.3,196.0,4075.0,male,2009
118 | Adelie,Torgersen,38.6,17.0,188.0,2900.0,female,2009
119 | Adelie,Torgersen,37.3,20.5,199.0,3775.0,male,2009
120 | Adelie,Torgersen,35.7,17.0,189.0,3350.0,female,2009
121 | Adelie,Torgersen,41.1,18.6,189.0,3325.0,male,2009
122 | Adelie,Torgersen,36.2,17.2,187.0,3150.0,female,2009
123 | Adelie,Torgersen,37.7,19.8,198.0,3500.0,male,2009
124 | Adelie,Torgersen,40.2,17.0,176.0,3450.0,female,2009
125 | Adelie,Torgersen,41.4,18.5,202.0,3875.0,male,2009
126 | Adelie,Torgersen,35.2,15.9,186.0,3050.0,female,2009
127 | Adelie,Torgersen,40.6,19.0,199.0,4000.0,male,2009
128 | Adelie,Torgersen,38.8,17.6,191.0,3275.0,female,2009
129 | Adelie,Torgersen,41.5,18.3,195.0,4300.0,male,2009
130 | Adelie,Torgersen,39.0,17.1,191.0,3050.0,female,2009
131 | Adelie,Torgersen,44.1,18.0,210.0,4000.0,male,2009
132 | Adelie,Torgersen,38.5,17.9,190.0,3325.0,female,2009
133 | Adelie,Torgersen,43.1,19.2,197.0,3500.0,male,2009
134 | Adelie,Dream,36.8,18.5,193.0,3500.0,female,2009
135 | Adelie,Dream,37.5,18.5,199.0,4475.0,male,2009
136 | Adelie,Dream,38.1,17.6,187.0,3425.0,female,2009
137 | Adelie,Dream,41.1,17.5,190.0,3900.0,male,2009
138 | Adelie,Dream,35.6,17.5,191.0,3175.0,female,2009
139 | Adelie,Dream,40.2,20.1,200.0,3975.0,male,2009
140 | Adelie,Dream,37.0,16.5,185.0,3400.0,female,2009
141 | Adelie,Dream,39.7,17.9,193.0,4250.0,male,2009
142 | Adelie,Dream,40.2,17.1,193.0,3400.0,female,2009
143 | Adelie,Dream,40.6,17.2,187.0,3475.0,male,2009
144 | Adelie,Dream,32.1,15.5,188.0,3050.0,female,2009
145 | Adelie,Dream,40.7,17.0,190.0,3725.0,male,2009
146 | Adelie,Dream,37.3,16.8,192.0,3000.0,female,2009
147 | Adelie,Dream,39.0,18.7,185.0,3650.0,male,2009
148 | Adelie,Dream,39.2,18.6,190.0,4250.0,male,2009
149 | Adelie,Dream,36.6,18.4,184.0,3475.0,female,2009
150 | Adelie,Dream,36.0,17.8,195.0,3450.0,female,2009
151 | Adelie,Dream,37.8,18.1,193.0,3750.0,male,2009
152 | Adelie,Dream,36.0,17.1,187.0,3700.0,female,2009
153 | Adelie,Dream,41.5,18.5,201.0,4000.0,male,2009
154 | Gentoo,Biscoe,46.1,13.2,211.0,4500.0,female,2007
155 | Gentoo,Biscoe,50.0,16.3,230.0,5700.0,male,2007
156 | Gentoo,Biscoe,48.7,14.1,210.0,4450.0,female,2007
157 | Gentoo,Biscoe,50.0,15.2,218.0,5700.0,male,2007
158 | Gentoo,Biscoe,47.6,14.5,215.0,5400.0,male,2007
159 | Gentoo,Biscoe,46.5,13.5,210.0,4550.0,female,2007
160 | Gentoo,Biscoe,45.4,14.6,211.0,4800.0,female,2007
161 | Gentoo,Biscoe,46.7,15.3,219.0,5200.0,male,2007
162 | Gentoo,Biscoe,43.3,13.4,209.0,4400.0,female,2007
163 | Gentoo,Biscoe,46.8,15.4,215.0,5150.0,male,2007
164 | Gentoo,Biscoe,40.9,13.7,214.0,4650.0,female,2007
165 | Gentoo,Biscoe,49.0,16.1,216.0,5550.0,male,2007
166 | Gentoo,Biscoe,45.5,13.7,214.0,4650.0,female,2007
167 | Gentoo,Biscoe,48.4,14.6,213.0,5850.0,male,2007
168 | Gentoo,Biscoe,45.8,14.6,210.0,4200.0,female,2007
169 | Gentoo,Biscoe,49.3,15.7,217.0,5850.0,male,2007
170 | Gentoo,Biscoe,42.0,13.5,210.0,4150.0,female,2007
171 | Gentoo,Biscoe,49.2,15.2,221.0,6300.0,male,2007
172 | Gentoo,Biscoe,46.2,14.5,209.0,4800.0,female,2007
173 | Gentoo,Biscoe,48.7,15.1,222.0,5350.0,male,2007
174 | Gentoo,Biscoe,50.2,14.3,218.0,5700.0,male,2007
175 | Gentoo,Biscoe,45.1,14.5,215.0,5000.0,female,2007
176 | Gentoo,Biscoe,46.5,14.5,213.0,4400.0,female,2007
177 | Gentoo,Biscoe,46.3,15.8,215.0,5050.0,male,2007
178 | Gentoo,Biscoe,42.9,13.1,215.0,5000.0,female,2007
179 | Gentoo,Biscoe,46.1,15.1,215.0,5100.0,male,2007
180 | Gentoo,Biscoe,44.5,14.3,216.0,4100.0,,2007
181 | Gentoo,Biscoe,47.8,15.0,215.0,5650.0,male,2007
182 | Gentoo,Biscoe,48.2,14.3,210.0,4600.0,female,2007
183 | Gentoo,Biscoe,50.0,15.3,220.0,5550.0,male,2007
184 | Gentoo,Biscoe,47.3,15.3,222.0,5250.0,male,2007
185 | Gentoo,Biscoe,42.8,14.2,209.0,4700.0,female,2007
186 | Gentoo,Biscoe,45.1,14.5,207.0,5050.0,female,2007
187 | Gentoo,Biscoe,59.6,17.0,230.0,6050.0,male,2007
188 | Gentoo,Biscoe,49.1,14.8,220.0,5150.0,female,2008
189 | Gentoo,Biscoe,48.4,16.3,220.0,5400.0,male,2008
190 | Gentoo,Biscoe,42.6,13.7,213.0,4950.0,female,2008
191 | Gentoo,Biscoe,44.4,17.3,219.0,5250.0,male,2008
192 | Gentoo,Biscoe,44.0,13.6,208.0,4350.0,female,2008
193 | Gentoo,Biscoe,48.7,15.7,208.0,5350.0,male,2008
194 | Gentoo,Biscoe,42.7,13.7,208.0,3950.0,female,2008
195 | Gentoo,Biscoe,49.6,16.0,225.0,5700.0,male,2008
196 | Gentoo,Biscoe,45.3,13.7,210.0,4300.0,female,2008
197 | Gentoo,Biscoe,49.6,15.0,216.0,4750.0,male,2008
198 | Gentoo,Biscoe,50.5,15.9,222.0,5550.0,male,2008
199 | Gentoo,Biscoe,43.6,13.9,217.0,4900.0,female,2008
200 | Gentoo,Biscoe,45.5,13.9,210.0,4200.0,female,2008
201 | Gentoo,Biscoe,50.5,15.9,225.0,5400.0,male,2008
202 | Gentoo,Biscoe,44.9,13.3,213.0,5100.0,female,2008
203 | Gentoo,Biscoe,45.2,15.8,215.0,5300.0,male,2008
204 | Gentoo,Biscoe,46.6,14.2,210.0,4850.0,female,2008
205 | Gentoo,Biscoe,48.5,14.1,220.0,5300.0,male,2008
206 | Gentoo,Biscoe,45.1,14.4,210.0,4400.0,female,2008
207 | Gentoo,Biscoe,50.1,15.0,225.0,5000.0,male,2008
208 | Gentoo,Biscoe,46.5,14.4,217.0,4900.0,female,2008
209 | Gentoo,Biscoe,45.0,15.4,220.0,5050.0,male,2008
210 | Gentoo,Biscoe,43.8,13.9,208.0,4300.0,female,2008
211 | Gentoo,Biscoe,45.5,15.0,220.0,5000.0,male,2008
212 | Gentoo,Biscoe,43.2,14.5,208.0,4450.0,female,2008
213 | Gentoo,Biscoe,50.4,15.3,224.0,5550.0,male,2008
214 | Gentoo,Biscoe,45.3,13.8,208.0,4200.0,female,2008
215 | Gentoo,Biscoe,46.2,14.9,221.0,5300.0,male,2008
216 | Gentoo,Biscoe,45.7,13.9,214.0,4400.0,female,2008
217 | Gentoo,Biscoe,54.3,15.7,231.0,5650.0,male,2008
218 | Gentoo,Biscoe,45.8,14.2,219.0,4700.0,female,2008
219 | Gentoo,Biscoe,49.8,16.8,230.0,5700.0,male,2008
220 | Gentoo,Biscoe,46.2,14.4,214.0,4650.0,,2008
221 | Gentoo,Biscoe,49.5,16.2,229.0,5800.0,male,2008
222 | Gentoo,Biscoe,43.5,14.2,220.0,4700.0,female,2008
223 | Gentoo,Biscoe,50.7,15.0,223.0,5550.0,male,2008
224 | Gentoo,Biscoe,47.7,15.0,216.0,4750.0,female,2008
225 | Gentoo,Biscoe,46.4,15.6,221.0,5000.0,male,2008
226 | Gentoo,Biscoe,48.2,15.6,221.0,5100.0,male,2008
227 | Gentoo,Biscoe,46.5,14.8,217.0,5200.0,female,2008
228 | Gentoo,Biscoe,46.4,15.0,216.0,4700.0,female,2008
229 | Gentoo,Biscoe,48.6,16.0,230.0,5800.0,male,2008
230 | Gentoo,Biscoe,47.5,14.2,209.0,4600.0,female,2008
231 | Gentoo,Biscoe,51.1,16.3,220.0,6000.0,male,2008
232 | Gentoo,Biscoe,45.2,13.8,215.0,4750.0,female,2008
233 | Gentoo,Biscoe,45.2,16.4,223.0,5950.0,male,2008
234 | Gentoo,Biscoe,49.1,14.5,212.0,4625.0,female,2009
235 | Gentoo,Biscoe,52.5,15.6,221.0,5450.0,male,2009
236 | Gentoo,Biscoe,47.4,14.6,212.0,4725.0,female,2009
237 | Gentoo,Biscoe,50.0,15.9,224.0,5350.0,male,2009
238 | Gentoo,Biscoe,44.9,13.8,212.0,4750.0,female,2009
239 | Gentoo,Biscoe,50.8,17.3,228.0,5600.0,male,2009
240 | Gentoo,Biscoe,43.4,14.4,218.0,4600.0,female,2009
241 | Gentoo,Biscoe,51.3,14.2,218.0,5300.0,male,2009
242 | Gentoo,Biscoe,47.5,14.0,212.0,4875.0,female,2009
243 | Gentoo,Biscoe,52.1,17.0,230.0,5550.0,male,2009
244 | Gentoo,Biscoe,47.5,15.0,218.0,4950.0,female,2009
245 | Gentoo,Biscoe,52.2,17.1,228.0,5400.0,male,2009
246 | Gentoo,Biscoe,45.5,14.5,212.0,4750.0,female,2009
247 | Gentoo,Biscoe,49.5,16.1,224.0,5650.0,male,2009
248 | Gentoo,Biscoe,44.5,14.7,214.0,4850.0,female,2009
249 | Gentoo,Biscoe,50.8,15.7,226.0,5200.0,male,2009
250 | Gentoo,Biscoe,49.4,15.8,216.0,4925.0,male,2009
251 | Gentoo,Biscoe,46.9,14.6,222.0,4875.0,female,2009
252 | Gentoo,Biscoe,48.4,14.4,203.0,4625.0,female,2009
253 | Gentoo,Biscoe,51.1,16.5,225.0,5250.0,male,2009
254 | Gentoo,Biscoe,48.5,15.0,219.0,4850.0,female,2009
255 | Gentoo,Biscoe,55.9,17.0,228.0,5600.0,male,2009
256 | Gentoo,Biscoe,47.2,15.5,215.0,4975.0,female,2009
257 | Gentoo,Biscoe,49.1,15.0,228.0,5500.0,male,2009
258 | Gentoo,Biscoe,47.3,13.8,216.0,4725.0,,2009
259 | Gentoo,Biscoe,46.8,16.1,215.0,5500.0,male,2009
260 | Gentoo,Biscoe,41.7,14.7,210.0,4700.0,female,2009
261 | Gentoo,Biscoe,53.4,15.8,219.0,5500.0,male,2009
262 | Gentoo,Biscoe,43.3,14.0,208.0,4575.0,female,2009
263 | Gentoo,Biscoe,48.1,15.1,209.0,5500.0,male,2009
264 | Gentoo,Biscoe,50.5,15.2,216.0,5000.0,female,2009
265 | Gentoo,Biscoe,49.8,15.9,229.0,5950.0,male,2009
266 | Gentoo,Biscoe,43.5,15.2,213.0,4650.0,female,2009
267 | Gentoo,Biscoe,51.5,16.3,230.0,5500.0,male,2009
268 | Gentoo,Biscoe,46.2,14.1,217.0,4375.0,female,2009
269 | Gentoo,Biscoe,55.1,16.0,230.0,5850.0,male,2009
270 | Gentoo,Biscoe,44.5,15.7,217.0,4875.0,,2009
271 | Gentoo,Biscoe,48.8,16.2,222.0,6000.0,male,2009
272 | Gentoo,Biscoe,47.2,13.7,214.0,4925.0,female,2009
273 | Gentoo,Biscoe,,,,,,2009
274 | Gentoo,Biscoe,46.8,14.3,215.0,4850.0,female,2009
275 | Gentoo,Biscoe,50.4,15.7,222.0,5750.0,male,2009
276 | Gentoo,Biscoe,45.2,14.8,212.0,5200.0,female,2009
277 | Gentoo,Biscoe,49.9,16.1,213.0,5400.0,male,2009
278 | Chinstrap,Dream,46.5,17.9,192.0,3500.0,female,2007
279 | Chinstrap,Dream,50.0,19.5,196.0,3900.0,male,2007
280 | Chinstrap,Dream,51.3,19.2,193.0,3650.0,male,2007
281 | Chinstrap,Dream,45.4,18.7,188.0,3525.0,female,2007
282 | Chinstrap,Dream,52.7,19.8,197.0,3725.0,male,2007
283 | Chinstrap,Dream,45.2,17.8,198.0,3950.0,female,2007
284 | Chinstrap,Dream,46.1,18.2,178.0,3250.0,female,2007
285 | Chinstrap,Dream,51.3,18.2,197.0,3750.0,male,2007
286 | Chinstrap,Dream,46.0,18.9,195.0,4150.0,female,2007
287 | Chinstrap,Dream,51.3,19.9,198.0,3700.0,male,2007
288 | Chinstrap,Dream,46.6,17.8,193.0,3800.0,female,2007
289 | Chinstrap,Dream,51.7,20.3,194.0,3775.0,male,2007
290 | Chinstrap,Dream,47.0,17.3,185.0,3700.0,female,2007
291 | Chinstrap,Dream,52.0,18.1,201.0,4050.0,male,2007
292 | Chinstrap,Dream,45.9,17.1,190.0,3575.0,female,2007
293 | Chinstrap,Dream,50.5,19.6,201.0,4050.0,male,2007
294 | Chinstrap,Dream,50.3,20.0,197.0,3300.0,male,2007
295 | Chinstrap,Dream,58.0,17.8,181.0,3700.0,female,2007
296 | Chinstrap,Dream,46.4,18.6,190.0,3450.0,female,2007
297 | Chinstrap,Dream,49.2,18.2,195.0,4400.0,male,2007
298 | Chinstrap,Dream,42.4,17.3,181.0,3600.0,female,2007
299 | Chinstrap,Dream,48.5,17.5,191.0,3400.0,male,2007
300 | Chinstrap,Dream,43.2,16.6,187.0,2900.0,female,2007
301 | Chinstrap,Dream,50.6,19.4,193.0,3800.0,male,2007
302 | Chinstrap,Dream,46.7,17.9,195.0,3300.0,female,2007
303 | Chinstrap,Dream,52.0,19.0,197.0,4150.0,male,2007
304 | Chinstrap,Dream,50.5,18.4,200.0,3400.0,female,2008
305 | Chinstrap,Dream,49.5,19.0,200.0,3800.0,male,2008
306 | Chinstrap,Dream,46.4,17.8,191.0,3700.0,female,2008
307 | Chinstrap,Dream,52.8,20.0,205.0,4550.0,male,2008
308 | Chinstrap,Dream,40.9,16.6,187.0,3200.0,female,2008
309 | Chinstrap,Dream,54.2,20.8,201.0,4300.0,male,2008
310 | Chinstrap,Dream,42.5,16.7,187.0,3350.0,female,2008
311 | Chinstrap,Dream,51.0,18.8,203.0,4100.0,male,2008
312 | Chinstrap,Dream,49.7,18.6,195.0,3600.0,male,2008
313 | Chinstrap,Dream,47.5,16.8,199.0,3900.0,female,2008
314 | Chinstrap,Dream,47.6,18.3,195.0,3850.0,female,2008
315 | Chinstrap,Dream,52.0,20.7,210.0,4800.0,male,2008
316 | Chinstrap,Dream,46.9,16.6,192.0,2700.0,female,2008
317 | Chinstrap,Dream,53.5,19.9,205.0,4500.0,male,2008
318 | Chinstrap,Dream,49.0,19.5,210.0,3950.0,male,2008
319 | Chinstrap,Dream,46.2,17.5,187.0,3650.0,female,2008
320 | Chinstrap,Dream,50.9,19.1,196.0,3550.0,male,2008
321 | Chinstrap,Dream,45.5,17.0,196.0,3500.0,female,2008
322 | Chinstrap,Dream,50.9,17.9,196.0,3675.0,female,2009
323 | Chinstrap,Dream,50.8,18.5,201.0,4450.0,male,2009
324 | Chinstrap,Dream,50.1,17.9,190.0,3400.0,female,2009
325 | Chinstrap,Dream,49.0,19.6,212.0,4300.0,male,2009
326 | Chinstrap,Dream,51.5,18.7,187.0,3250.0,male,2009
327 | Chinstrap,Dream,49.8,17.3,198.0,3675.0,female,2009
328 | Chinstrap,Dream,48.1,16.4,199.0,3325.0,female,2009
329 | Chinstrap,Dream,51.4,19.0,201.0,3950.0,male,2009
330 | Chinstrap,Dream,45.7,17.3,193.0,3600.0,female,2009
331 | Chinstrap,Dream,50.7,19.7,203.0,4050.0,male,2009
332 | Chinstrap,Dream,42.5,17.3,187.0,3350.0,female,2009
333 | Chinstrap,Dream,52.2,18.8,197.0,3450.0,male,2009
334 | Chinstrap,Dream,45.2,16.6,191.0,3250.0,female,2009
335 | Chinstrap,Dream,49.3,19.9,203.0,4050.0,male,2009
336 | Chinstrap,Dream,50.2,18.8,202.0,3800.0,male,2009
337 | Chinstrap,Dream,45.6,19.4,194.0,3525.0,female,2009
338 | Chinstrap,Dream,51.9,19.5,206.0,3950.0,male,2009
339 | Chinstrap,Dream,46.8,16.5,189.0,3650.0,female,2009
340 | Chinstrap,Dream,45.7,17.0,195.0,3650.0,female,2009
341 | Chinstrap,Dream,55.8,19.8,207.0,4000.0,male,2009
342 | Chinstrap,Dream,43.5,18.1,202.0,3400.0,female,2009
343 | Chinstrap,Dream,49.6,18.2,193.0,3775.0,male,2009
344 | Chinstrap,Dream,50.8,19.0,210.0,4100.0,male,2009
345 | Chinstrap,Dream,50.2,18.7,198.0,3775.0,female,2009
346 |
--------------------------------------------------------------------------------
/Chapter04/penguin_ml/penguins_ml.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 |
3 | penguin_df = pd.read_csv('penguins.csv')
4 | penguin_df.dropna(inplace=True)
5 | output = penguin_df['species']
6 | features = penguin_df[['island', 'bill_length_mm', 'bill_depth_mm', 'flipper_length_mm', 'body_mass_g', 'sex']]
7 | features = pd.get_dummies(features)
8 | output, uniques = pd.factorize(output)
9 | print('Here is what our unique output variables represent')
10 | print(uniques)
11 | print('Here are our feature variables')
12 | print(features.head())
--------------------------------------------------------------------------------
/Chapter04/penguin_ml/penguins_streamlit.py:
--------------------------------------------------------------------------------
1 | import streamlit as st
2 | import seaborn as sns
3 | import matplotlib.pyplot as plt
4 | import pandas as pd
5 | import pickle
6 | from sklearn.metrics import accuracy_score
7 | from sklearn.ensemble import RandomForestClassifier
8 | from sklearn.model_selection import train_test_split
9 |
10 | st.title('Penguin Classifier')
11 |
12 | st.write("This app uses 6 inputs to predict the species of penguin using "
13 |
14 | "a model built on the Palmer's Penguin's dataset. Use the form below"
15 |
16 | " to get started!")
17 |
18 |
19 |
20 | password_guess = st.text_input('What is the Password?')
21 |
22 | if password_guess != 'streamlit_is_great':
23 | st.stop()
24 |
25 |
26 |
27 | penguin_file = st.file_uploader('Upload your own penguin data')
28 |
29 | if penguin_file is None:
30 |
31 | rf_pickle = open('random_forest_penguin.pickle', 'rb')
32 |
33 | map_pickle = open('output_penguin.pickle', 'rb')
34 |
35 | rfc = pickle.load(rf_pickle)
36 |
37 | unique_penguin_mapping = pickle.load(map_pickle)
38 |
39 | rf_pickle.close()
40 |
41 | map_pickle.close()
42 |
43 | else:
44 |
45 | penguin_df = pd.read_csv(penguin_file)
46 |
47 | penguin_df = penguin_df.dropna()
48 |
49 | output = penguin_df['species']
50 |
51 | features = penguin_df[['island', 'bill_length_mm', 'bill_depth_mm',
52 |
53 | 'flipper_length_mm', 'body_mass_g', 'sex']]
54 |
55 | features = pd.get_dummies(features)
56 |
57 | output, unique_penguin_mapping = pd.factorize(output)
58 |
59 |
60 |
61 | x_train, x_test, y_train, y_test = train_test_split(
62 |
63 | features, output, test_size=.8)
64 |
65 | rfc = RandomForestClassifier(random_state=15)
66 |
67 | rfc.fit(x_train, y_train)
68 |
69 | y_pred = rfc.predict(x_test)
70 |
71 | score = round(accuracy_score(y_pred, y_test), 2)
72 |
73 | st.write('We trained a Random Forest model on these data,'
74 | ' it has a score of {}! Use the '
75 | 'inputs below to try out the model.'.format(score))
76 |
77 | with st.form('user_inputs'):
78 | island = st.selectbox('Penguin Island', options=[
79 | 'Biscoe', 'Dream', 'Torgerson'])
80 | sex = st.selectbox('Sex', options=[
81 | 'Female', 'Male'])
82 | bill_length = st.number_input(
83 | 'Bill Length (mm)', min_value=0)
84 | bill_depth = st.number_input(
85 | 'Bill Depth (mm)', min_value=0)
86 | flipper_length = st.number_input(
87 | 'Flipper Length (mm)', min_value=0)
88 | body_mass = st.number_input(
89 | 'Body Mass (g)', min_value=0)
90 | st.form_submit_button()
91 |
92 |
93 |
94 | island_biscoe, island_dream, island_torgerson = 0, 0, 0
95 | if island == 'Biscoe':
96 | island_biscoe = 1
97 | elif island == 'Dream':
98 | island_dream = 1
99 | elif island == 'Torgerson':
100 | island_torgerson = 1
101 |
102 | sex_female, sex_male = 0, 0
103 |
104 | if sex == 'Female':
105 | sex_female = 1
106 |
107 | elif sex == 'Male':
108 | sex_male = 1
109 |
110 |
111 | new_prediction = rfc.predict([[bill_length, bill_depth, flipper_length,
112 | body_mass, island_biscoe, island_dream,
113 | island_torgerson, sex_female, sex_male]])
114 | prediction_species = unique_penguin_mapping[new_prediction][0]
115 | st.write('We predict your penguin is of the {} species'.format(prediction_species))
116 |
--------------------------------------------------------------------------------
/Chapter04/penguin_ml/random_forest_penguin.pickle:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Getting-started-with-Streamlit-for-Data-Science/50677d3f08c78f796b05cb1caf76246df3ff08ff/Chapter04/penguin_ml/random_forest_penguin.pickle
--------------------------------------------------------------------------------
/Chapter04/penguin_ml/requirements.txt:
--------------------------------------------------------------------------------
1 | pandas==1.0.5
2 | matplotlib==3.2.2
3 | seaborn==0.11.0
4 | streamlit==0.81.1
5 | scikit_learn==0.24.1
6 |
--------------------------------------------------------------------------------
/Chapter05/penguin_ml/feature_importance.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Getting-started-with-Streamlit-for-Data-Science/50677d3f08c78f796b05cb1caf76246df3ff08ff/Chapter05/penguin_ml/feature_importance.png
--------------------------------------------------------------------------------
/Chapter05/penguin_ml/output_penguin.pickle:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Getting-started-with-Streamlit-for-Data-Science/50677d3f08c78f796b05cb1caf76246df3ff08ff/Chapter05/penguin_ml/output_penguin.pickle
--------------------------------------------------------------------------------
/Chapter05/penguin_ml/penguins.csv:
--------------------------------------------------------------------------------
1 | species,island,bill_length_mm,bill_depth_mm,flipper_length_mm,body_mass_g,sex,year
2 | Adelie,Torgersen,39.1,18.7,181.0,3750.0,male,2007
3 | Adelie,Torgersen,39.5,17.4,186.0,3800.0,female,2007
4 | Adelie,Torgersen,40.3,18.0,195.0,3250.0,female,2007
5 | Adelie,Torgersen,,,,,,2007
6 | Adelie,Torgersen,36.7,19.3,193.0,3450.0,female,2007
7 | Adelie,Torgersen,39.3,20.6,190.0,3650.0,male,2007
8 | Adelie,Torgersen,38.9,17.8,181.0,3625.0,female,2007
9 | Adelie,Torgersen,39.2,19.6,195.0,4675.0,male,2007
10 | Adelie,Torgersen,34.1,18.1,193.0,3475.0,,2007
11 | Adelie,Torgersen,42.0,20.2,190.0,4250.0,,2007
12 | Adelie,Torgersen,37.8,17.1,186.0,3300.0,,2007
13 | Adelie,Torgersen,37.8,17.3,180.0,3700.0,,2007
14 | Adelie,Torgersen,41.1,17.6,182.0,3200.0,female,2007
15 | Adelie,Torgersen,38.6,21.2,191.0,3800.0,male,2007
16 | Adelie,Torgersen,34.6,21.1,198.0,4400.0,male,2007
17 | Adelie,Torgersen,36.6,17.8,185.0,3700.0,female,2007
18 | Adelie,Torgersen,38.7,19.0,195.0,3450.0,female,2007
19 | Adelie,Torgersen,42.5,20.7,197.0,4500.0,male,2007
20 | Adelie,Torgersen,34.4,18.4,184.0,3325.0,female,2007
21 | Adelie,Torgersen,46.0,21.5,194.0,4200.0,male,2007
22 | Adelie,Biscoe,37.8,18.3,174.0,3400.0,female,2007
23 | Adelie,Biscoe,37.7,18.7,180.0,3600.0,male,2007
24 | Adelie,Biscoe,35.9,19.2,189.0,3800.0,female,2007
25 | Adelie,Biscoe,38.2,18.1,185.0,3950.0,male,2007
26 | Adelie,Biscoe,38.8,17.2,180.0,3800.0,male,2007
27 | Adelie,Biscoe,35.3,18.9,187.0,3800.0,female,2007
28 | Adelie,Biscoe,40.6,18.6,183.0,3550.0,male,2007
29 | Adelie,Biscoe,40.5,17.9,187.0,3200.0,female,2007
30 | Adelie,Biscoe,37.9,18.6,172.0,3150.0,female,2007
31 | Adelie,Biscoe,40.5,18.9,180.0,3950.0,male,2007
32 | Adelie,Dream,39.5,16.7,178.0,3250.0,female,2007
33 | Adelie,Dream,37.2,18.1,178.0,3900.0,male,2007
34 | Adelie,Dream,39.5,17.8,188.0,3300.0,female,2007
35 | Adelie,Dream,40.9,18.9,184.0,3900.0,male,2007
36 | Adelie,Dream,36.4,17.0,195.0,3325.0,female,2007
37 | Adelie,Dream,39.2,21.1,196.0,4150.0,male,2007
38 | Adelie,Dream,38.8,20.0,190.0,3950.0,male,2007
39 | Adelie,Dream,42.2,18.5,180.0,3550.0,female,2007
40 | Adelie,Dream,37.6,19.3,181.0,3300.0,female,2007
41 | Adelie,Dream,39.8,19.1,184.0,4650.0,male,2007
42 | Adelie,Dream,36.5,18.0,182.0,3150.0,female,2007
43 | Adelie,Dream,40.8,18.4,195.0,3900.0,male,2007
44 | Adelie,Dream,36.0,18.5,186.0,3100.0,female,2007
45 | Adelie,Dream,44.1,19.7,196.0,4400.0,male,2007
46 | Adelie,Dream,37.0,16.9,185.0,3000.0,female,2007
47 | Adelie,Dream,39.6,18.8,190.0,4600.0,male,2007
48 | Adelie,Dream,41.1,19.0,182.0,3425.0,male,2007
49 | Adelie,Dream,37.5,18.9,179.0,2975.0,,2007
50 | Adelie,Dream,36.0,17.9,190.0,3450.0,female,2007
51 | Adelie,Dream,42.3,21.2,191.0,4150.0,male,2007
52 | Adelie,Biscoe,39.6,17.7,186.0,3500.0,female,2008
53 | Adelie,Biscoe,40.1,18.9,188.0,4300.0,male,2008
54 | Adelie,Biscoe,35.0,17.9,190.0,3450.0,female,2008
55 | Adelie,Biscoe,42.0,19.5,200.0,4050.0,male,2008
56 | Adelie,Biscoe,34.5,18.1,187.0,2900.0,female,2008
57 | Adelie,Biscoe,41.4,18.6,191.0,3700.0,male,2008
58 | Adelie,Biscoe,39.0,17.5,186.0,3550.0,female,2008
59 | Adelie,Biscoe,40.6,18.8,193.0,3800.0,male,2008
60 | Adelie,Biscoe,36.5,16.6,181.0,2850.0,female,2008
61 | Adelie,Biscoe,37.6,19.1,194.0,3750.0,male,2008
62 | Adelie,Biscoe,35.7,16.9,185.0,3150.0,female,2008
63 | Adelie,Biscoe,41.3,21.1,195.0,4400.0,male,2008
64 | Adelie,Biscoe,37.6,17.0,185.0,3600.0,female,2008
65 | Adelie,Biscoe,41.1,18.2,192.0,4050.0,male,2008
66 | Adelie,Biscoe,36.4,17.1,184.0,2850.0,female,2008
67 | Adelie,Biscoe,41.6,18.0,192.0,3950.0,male,2008
68 | Adelie,Biscoe,35.5,16.2,195.0,3350.0,female,2008
69 | Adelie,Biscoe,41.1,19.1,188.0,4100.0,male,2008
70 | Adelie,Torgersen,35.9,16.6,190.0,3050.0,female,2008
71 | Adelie,Torgersen,41.8,19.4,198.0,4450.0,male,2008
72 | Adelie,Torgersen,33.5,19.0,190.0,3600.0,female,2008
73 | Adelie,Torgersen,39.7,18.4,190.0,3900.0,male,2008
74 | Adelie,Torgersen,39.6,17.2,196.0,3550.0,female,2008
75 | Adelie,Torgersen,45.8,18.9,197.0,4150.0,male,2008
76 | Adelie,Torgersen,35.5,17.5,190.0,3700.0,female,2008
77 | Adelie,Torgersen,42.8,18.5,195.0,4250.0,male,2008
78 | Adelie,Torgersen,40.9,16.8,191.0,3700.0,female,2008
79 | Adelie,Torgersen,37.2,19.4,184.0,3900.0,male,2008
80 | Adelie,Torgersen,36.2,16.1,187.0,3550.0,female,2008
81 | Adelie,Torgersen,42.1,19.1,195.0,4000.0,male,2008
82 | Adelie,Torgersen,34.6,17.2,189.0,3200.0,female,2008
83 | Adelie,Torgersen,42.9,17.6,196.0,4700.0,male,2008
84 | Adelie,Torgersen,36.7,18.8,187.0,3800.0,female,2008
85 | Adelie,Torgersen,35.1,19.4,193.0,4200.0,male,2008
86 | Adelie,Dream,37.3,17.8,191.0,3350.0,female,2008
87 | Adelie,Dream,41.3,20.3,194.0,3550.0,male,2008
88 | Adelie,Dream,36.3,19.5,190.0,3800.0,male,2008
89 | Adelie,Dream,36.9,18.6,189.0,3500.0,female,2008
90 | Adelie,Dream,38.3,19.2,189.0,3950.0,male,2008
91 | Adelie,Dream,38.9,18.8,190.0,3600.0,female,2008
92 | Adelie,Dream,35.7,18.0,202.0,3550.0,female,2008
93 | Adelie,Dream,41.1,18.1,205.0,4300.0,male,2008
94 | Adelie,Dream,34.0,17.1,185.0,3400.0,female,2008
95 | Adelie,Dream,39.6,18.1,186.0,4450.0,male,2008
96 | Adelie,Dream,36.2,17.3,187.0,3300.0,female,2008
97 | Adelie,Dream,40.8,18.9,208.0,4300.0,male,2008
98 | Adelie,Dream,38.1,18.6,190.0,3700.0,female,2008
99 | Adelie,Dream,40.3,18.5,196.0,4350.0,male,2008
100 | Adelie,Dream,33.1,16.1,178.0,2900.0,female,2008
101 | Adelie,Dream,43.2,18.5,192.0,4100.0,male,2008
102 | Adelie,Biscoe,35.0,17.9,192.0,3725.0,female,2009
103 | Adelie,Biscoe,41.0,20.0,203.0,4725.0,male,2009
104 | Adelie,Biscoe,37.7,16.0,183.0,3075.0,female,2009
105 | Adelie,Biscoe,37.8,20.0,190.0,4250.0,male,2009
106 | Adelie,Biscoe,37.9,18.6,193.0,2925.0,female,2009
107 | Adelie,Biscoe,39.7,18.9,184.0,3550.0,male,2009
108 | Adelie,Biscoe,38.6,17.2,199.0,3750.0,female,2009
109 | Adelie,Biscoe,38.2,20.0,190.0,3900.0,male,2009
110 | Adelie,Biscoe,38.1,17.0,181.0,3175.0,female,2009
111 | Adelie,Biscoe,43.2,19.0,197.0,4775.0,male,2009
112 | Adelie,Biscoe,38.1,16.5,198.0,3825.0,female,2009
113 | Adelie,Biscoe,45.6,20.3,191.0,4600.0,male,2009
114 | Adelie,Biscoe,39.7,17.7,193.0,3200.0,female,2009
115 | Adelie,Biscoe,42.2,19.5,197.0,4275.0,male,2009
116 | Adelie,Biscoe,39.6,20.7,191.0,3900.0,female,2009
117 | Adelie,Biscoe,42.7,18.3,196.0,4075.0,male,2009
118 | Adelie,Torgersen,38.6,17.0,188.0,2900.0,female,2009
119 | Adelie,Torgersen,37.3,20.5,199.0,3775.0,male,2009
120 | Adelie,Torgersen,35.7,17.0,189.0,3350.0,female,2009
121 | Adelie,Torgersen,41.1,18.6,189.0,3325.0,male,2009
122 | Adelie,Torgersen,36.2,17.2,187.0,3150.0,female,2009
123 | Adelie,Torgersen,37.7,19.8,198.0,3500.0,male,2009
124 | Adelie,Torgersen,40.2,17.0,176.0,3450.0,female,2009
125 | Adelie,Torgersen,41.4,18.5,202.0,3875.0,male,2009
126 | Adelie,Torgersen,35.2,15.9,186.0,3050.0,female,2009
127 | Adelie,Torgersen,40.6,19.0,199.0,4000.0,male,2009
128 | Adelie,Torgersen,38.8,17.6,191.0,3275.0,female,2009
129 | Adelie,Torgersen,41.5,18.3,195.0,4300.0,male,2009
130 | Adelie,Torgersen,39.0,17.1,191.0,3050.0,female,2009
131 | Adelie,Torgersen,44.1,18.0,210.0,4000.0,male,2009
132 | Adelie,Torgersen,38.5,17.9,190.0,3325.0,female,2009
133 | Adelie,Torgersen,43.1,19.2,197.0,3500.0,male,2009
134 | Adelie,Dream,36.8,18.5,193.0,3500.0,female,2009
135 | Adelie,Dream,37.5,18.5,199.0,4475.0,male,2009
136 | Adelie,Dream,38.1,17.6,187.0,3425.0,female,2009
137 | Adelie,Dream,41.1,17.5,190.0,3900.0,male,2009
138 | Adelie,Dream,35.6,17.5,191.0,3175.0,female,2009
139 | Adelie,Dream,40.2,20.1,200.0,3975.0,male,2009
140 | Adelie,Dream,37.0,16.5,185.0,3400.0,female,2009
141 | Adelie,Dream,39.7,17.9,193.0,4250.0,male,2009
142 | Adelie,Dream,40.2,17.1,193.0,3400.0,female,2009
143 | Adelie,Dream,40.6,17.2,187.0,3475.0,male,2009
144 | Adelie,Dream,32.1,15.5,188.0,3050.0,female,2009
145 | Adelie,Dream,40.7,17.0,190.0,3725.0,male,2009
146 | Adelie,Dream,37.3,16.8,192.0,3000.0,female,2009
147 | Adelie,Dream,39.0,18.7,185.0,3650.0,male,2009
148 | Adelie,Dream,39.2,18.6,190.0,4250.0,male,2009
149 | Adelie,Dream,36.6,18.4,184.0,3475.0,female,2009
150 | Adelie,Dream,36.0,17.8,195.0,3450.0,female,2009
151 | Adelie,Dream,37.8,18.1,193.0,3750.0,male,2009
152 | Adelie,Dream,36.0,17.1,187.0,3700.0,female,2009
153 | Adelie,Dream,41.5,18.5,201.0,4000.0,male,2009
154 | Gentoo,Biscoe,46.1,13.2,211.0,4500.0,female,2007
155 | Gentoo,Biscoe,50.0,16.3,230.0,5700.0,male,2007
156 | Gentoo,Biscoe,48.7,14.1,210.0,4450.0,female,2007
157 | Gentoo,Biscoe,50.0,15.2,218.0,5700.0,male,2007
158 | Gentoo,Biscoe,47.6,14.5,215.0,5400.0,male,2007
159 | Gentoo,Biscoe,46.5,13.5,210.0,4550.0,female,2007
160 | Gentoo,Biscoe,45.4,14.6,211.0,4800.0,female,2007
161 | Gentoo,Biscoe,46.7,15.3,219.0,5200.0,male,2007
162 | Gentoo,Biscoe,43.3,13.4,209.0,4400.0,female,2007
163 | Gentoo,Biscoe,46.8,15.4,215.0,5150.0,male,2007
164 | Gentoo,Biscoe,40.9,13.7,214.0,4650.0,female,2007
165 | Gentoo,Biscoe,49.0,16.1,216.0,5550.0,male,2007
166 | Gentoo,Biscoe,45.5,13.7,214.0,4650.0,female,2007
167 | Gentoo,Biscoe,48.4,14.6,213.0,5850.0,male,2007
168 | Gentoo,Biscoe,45.8,14.6,210.0,4200.0,female,2007
169 | Gentoo,Biscoe,49.3,15.7,217.0,5850.0,male,2007
170 | Gentoo,Biscoe,42.0,13.5,210.0,4150.0,female,2007
171 | Gentoo,Biscoe,49.2,15.2,221.0,6300.0,male,2007
172 | Gentoo,Biscoe,46.2,14.5,209.0,4800.0,female,2007
173 | Gentoo,Biscoe,48.7,15.1,222.0,5350.0,male,2007
174 | Gentoo,Biscoe,50.2,14.3,218.0,5700.0,male,2007
175 | Gentoo,Biscoe,45.1,14.5,215.0,5000.0,female,2007
176 | Gentoo,Biscoe,46.5,14.5,213.0,4400.0,female,2007
177 | Gentoo,Biscoe,46.3,15.8,215.0,5050.0,male,2007
178 | Gentoo,Biscoe,42.9,13.1,215.0,5000.0,female,2007
179 | Gentoo,Biscoe,46.1,15.1,215.0,5100.0,male,2007
180 | Gentoo,Biscoe,44.5,14.3,216.0,4100.0,,2007
181 | Gentoo,Biscoe,47.8,15.0,215.0,5650.0,male,2007
182 | Gentoo,Biscoe,48.2,14.3,210.0,4600.0,female,2007
183 | Gentoo,Biscoe,50.0,15.3,220.0,5550.0,male,2007
184 | Gentoo,Biscoe,47.3,15.3,222.0,5250.0,male,2007
185 | Gentoo,Biscoe,42.8,14.2,209.0,4700.0,female,2007
186 | Gentoo,Biscoe,45.1,14.5,207.0,5050.0,female,2007
187 | Gentoo,Biscoe,59.6,17.0,230.0,6050.0,male,2007
188 | Gentoo,Biscoe,49.1,14.8,220.0,5150.0,female,2008
189 | Gentoo,Biscoe,48.4,16.3,220.0,5400.0,male,2008
190 | Gentoo,Biscoe,42.6,13.7,213.0,4950.0,female,2008
191 | Gentoo,Biscoe,44.4,17.3,219.0,5250.0,male,2008
192 | Gentoo,Biscoe,44.0,13.6,208.0,4350.0,female,2008
193 | Gentoo,Biscoe,48.7,15.7,208.0,5350.0,male,2008
194 | Gentoo,Biscoe,42.7,13.7,208.0,3950.0,female,2008
195 | Gentoo,Biscoe,49.6,16.0,225.0,5700.0,male,2008
196 | Gentoo,Biscoe,45.3,13.7,210.0,4300.0,female,2008
197 | Gentoo,Biscoe,49.6,15.0,216.0,4750.0,male,2008
198 | Gentoo,Biscoe,50.5,15.9,222.0,5550.0,male,2008
199 | Gentoo,Biscoe,43.6,13.9,217.0,4900.0,female,2008
200 | Gentoo,Biscoe,45.5,13.9,210.0,4200.0,female,2008
201 | Gentoo,Biscoe,50.5,15.9,225.0,5400.0,male,2008
202 | Gentoo,Biscoe,44.9,13.3,213.0,5100.0,female,2008
203 | Gentoo,Biscoe,45.2,15.8,215.0,5300.0,male,2008
204 | Gentoo,Biscoe,46.6,14.2,210.0,4850.0,female,2008
205 | Gentoo,Biscoe,48.5,14.1,220.0,5300.0,male,2008
206 | Gentoo,Biscoe,45.1,14.4,210.0,4400.0,female,2008
207 | Gentoo,Biscoe,50.1,15.0,225.0,5000.0,male,2008
208 | Gentoo,Biscoe,46.5,14.4,217.0,4900.0,female,2008
209 | Gentoo,Biscoe,45.0,15.4,220.0,5050.0,male,2008
210 | Gentoo,Biscoe,43.8,13.9,208.0,4300.0,female,2008
211 | Gentoo,Biscoe,45.5,15.0,220.0,5000.0,male,2008
212 | Gentoo,Biscoe,43.2,14.5,208.0,4450.0,female,2008
213 | Gentoo,Biscoe,50.4,15.3,224.0,5550.0,male,2008
214 | Gentoo,Biscoe,45.3,13.8,208.0,4200.0,female,2008
215 | Gentoo,Biscoe,46.2,14.9,221.0,5300.0,male,2008
216 | Gentoo,Biscoe,45.7,13.9,214.0,4400.0,female,2008
217 | Gentoo,Biscoe,54.3,15.7,231.0,5650.0,male,2008
218 | Gentoo,Biscoe,45.8,14.2,219.0,4700.0,female,2008
219 | Gentoo,Biscoe,49.8,16.8,230.0,5700.0,male,2008
220 | Gentoo,Biscoe,46.2,14.4,214.0,4650.0,,2008
221 | Gentoo,Biscoe,49.5,16.2,229.0,5800.0,male,2008
222 | Gentoo,Biscoe,43.5,14.2,220.0,4700.0,female,2008
223 | Gentoo,Biscoe,50.7,15.0,223.0,5550.0,male,2008
224 | Gentoo,Biscoe,47.7,15.0,216.0,4750.0,female,2008
225 | Gentoo,Biscoe,46.4,15.6,221.0,5000.0,male,2008
226 | Gentoo,Biscoe,48.2,15.6,221.0,5100.0,male,2008
227 | Gentoo,Biscoe,46.5,14.8,217.0,5200.0,female,2008
228 | Gentoo,Biscoe,46.4,15.0,216.0,4700.0,female,2008
229 | Gentoo,Biscoe,48.6,16.0,230.0,5800.0,male,2008
230 | Gentoo,Biscoe,47.5,14.2,209.0,4600.0,female,2008
231 | Gentoo,Biscoe,51.1,16.3,220.0,6000.0,male,2008
232 | Gentoo,Biscoe,45.2,13.8,215.0,4750.0,female,2008
233 | Gentoo,Biscoe,45.2,16.4,223.0,5950.0,male,2008
234 | Gentoo,Biscoe,49.1,14.5,212.0,4625.0,female,2009
235 | Gentoo,Biscoe,52.5,15.6,221.0,5450.0,male,2009
236 | Gentoo,Biscoe,47.4,14.6,212.0,4725.0,female,2009
237 | Gentoo,Biscoe,50.0,15.9,224.0,5350.0,male,2009
238 | Gentoo,Biscoe,44.9,13.8,212.0,4750.0,female,2009
239 | Gentoo,Biscoe,50.8,17.3,228.0,5600.0,male,2009
240 | Gentoo,Biscoe,43.4,14.4,218.0,4600.0,female,2009
241 | Gentoo,Biscoe,51.3,14.2,218.0,5300.0,male,2009
242 | Gentoo,Biscoe,47.5,14.0,212.0,4875.0,female,2009
243 | Gentoo,Biscoe,52.1,17.0,230.0,5550.0,male,2009
244 | Gentoo,Biscoe,47.5,15.0,218.0,4950.0,female,2009
245 | Gentoo,Biscoe,52.2,17.1,228.0,5400.0,male,2009
246 | Gentoo,Biscoe,45.5,14.5,212.0,4750.0,female,2009
247 | Gentoo,Biscoe,49.5,16.1,224.0,5650.0,male,2009
248 | Gentoo,Biscoe,44.5,14.7,214.0,4850.0,female,2009
249 | Gentoo,Biscoe,50.8,15.7,226.0,5200.0,male,2009
250 | Gentoo,Biscoe,49.4,15.8,216.0,4925.0,male,2009
251 | Gentoo,Biscoe,46.9,14.6,222.0,4875.0,female,2009
252 | Gentoo,Biscoe,48.4,14.4,203.0,4625.0,female,2009
253 | Gentoo,Biscoe,51.1,16.5,225.0,5250.0,male,2009
254 | Gentoo,Biscoe,48.5,15.0,219.0,4850.0,female,2009
255 | Gentoo,Biscoe,55.9,17.0,228.0,5600.0,male,2009
256 | Gentoo,Biscoe,47.2,15.5,215.0,4975.0,female,2009
257 | Gentoo,Biscoe,49.1,15.0,228.0,5500.0,male,2009
258 | Gentoo,Biscoe,47.3,13.8,216.0,4725.0,,2009
259 | Gentoo,Biscoe,46.8,16.1,215.0,5500.0,male,2009
260 | Gentoo,Biscoe,41.7,14.7,210.0,4700.0,female,2009
261 | Gentoo,Biscoe,53.4,15.8,219.0,5500.0,male,2009
262 | Gentoo,Biscoe,43.3,14.0,208.0,4575.0,female,2009
263 | Gentoo,Biscoe,48.1,15.1,209.0,5500.0,male,2009
264 | Gentoo,Biscoe,50.5,15.2,216.0,5000.0,female,2009
265 | Gentoo,Biscoe,49.8,15.9,229.0,5950.0,male,2009
266 | Gentoo,Biscoe,43.5,15.2,213.0,4650.0,female,2009
267 | Gentoo,Biscoe,51.5,16.3,230.0,5500.0,male,2009
268 | Gentoo,Biscoe,46.2,14.1,217.0,4375.0,female,2009
269 | Gentoo,Biscoe,55.1,16.0,230.0,5850.0,male,2009
270 | Gentoo,Biscoe,44.5,15.7,217.0,4875.0,,2009
271 | Gentoo,Biscoe,48.8,16.2,222.0,6000.0,male,2009
272 | Gentoo,Biscoe,47.2,13.7,214.0,4925.0,female,2009
273 | Gentoo,Biscoe,,,,,,2009
274 | Gentoo,Biscoe,46.8,14.3,215.0,4850.0,female,2009
275 | Gentoo,Biscoe,50.4,15.7,222.0,5750.0,male,2009
276 | Gentoo,Biscoe,45.2,14.8,212.0,5200.0,female,2009
277 | Gentoo,Biscoe,49.9,16.1,213.0,5400.0,male,2009
278 | Chinstrap,Dream,46.5,17.9,192.0,3500.0,female,2007
279 | Chinstrap,Dream,50.0,19.5,196.0,3900.0,male,2007
280 | Chinstrap,Dream,51.3,19.2,193.0,3650.0,male,2007
281 | Chinstrap,Dream,45.4,18.7,188.0,3525.0,female,2007
282 | Chinstrap,Dream,52.7,19.8,197.0,3725.0,male,2007
283 | Chinstrap,Dream,45.2,17.8,198.0,3950.0,female,2007
284 | Chinstrap,Dream,46.1,18.2,178.0,3250.0,female,2007
285 | Chinstrap,Dream,51.3,18.2,197.0,3750.0,male,2007
286 | Chinstrap,Dream,46.0,18.9,195.0,4150.0,female,2007
287 | Chinstrap,Dream,51.3,19.9,198.0,3700.0,male,2007
288 | Chinstrap,Dream,46.6,17.8,193.0,3800.0,female,2007
289 | Chinstrap,Dream,51.7,20.3,194.0,3775.0,male,2007
290 | Chinstrap,Dream,47.0,17.3,185.0,3700.0,female,2007
291 | Chinstrap,Dream,52.0,18.1,201.0,4050.0,male,2007
292 | Chinstrap,Dream,45.9,17.1,190.0,3575.0,female,2007
293 | Chinstrap,Dream,50.5,19.6,201.0,4050.0,male,2007
294 | Chinstrap,Dream,50.3,20.0,197.0,3300.0,male,2007
295 | Chinstrap,Dream,58.0,17.8,181.0,3700.0,female,2007
296 | Chinstrap,Dream,46.4,18.6,190.0,3450.0,female,2007
297 | Chinstrap,Dream,49.2,18.2,195.0,4400.0,male,2007
298 | Chinstrap,Dream,42.4,17.3,181.0,3600.0,female,2007
299 | Chinstrap,Dream,48.5,17.5,191.0,3400.0,male,2007
300 | Chinstrap,Dream,43.2,16.6,187.0,2900.0,female,2007
301 | Chinstrap,Dream,50.6,19.4,193.0,3800.0,male,2007
302 | Chinstrap,Dream,46.7,17.9,195.0,3300.0,female,2007
303 | Chinstrap,Dream,52.0,19.0,197.0,4150.0,male,2007
304 | Chinstrap,Dream,50.5,18.4,200.0,3400.0,female,2008
305 | Chinstrap,Dream,49.5,19.0,200.0,3800.0,male,2008
306 | Chinstrap,Dream,46.4,17.8,191.0,3700.0,female,2008
307 | Chinstrap,Dream,52.8,20.0,205.0,4550.0,male,2008
308 | Chinstrap,Dream,40.9,16.6,187.0,3200.0,female,2008
309 | Chinstrap,Dream,54.2,20.8,201.0,4300.0,male,2008
310 | Chinstrap,Dream,42.5,16.7,187.0,3350.0,female,2008
311 | Chinstrap,Dream,51.0,18.8,203.0,4100.0,male,2008
312 | Chinstrap,Dream,49.7,18.6,195.0,3600.0,male,2008
313 | Chinstrap,Dream,47.5,16.8,199.0,3900.0,female,2008
314 | Chinstrap,Dream,47.6,18.3,195.0,3850.0,female,2008
315 | Chinstrap,Dream,52.0,20.7,210.0,4800.0,male,2008
316 | Chinstrap,Dream,46.9,16.6,192.0,2700.0,female,2008
317 | Chinstrap,Dream,53.5,19.9,205.0,4500.0,male,2008
318 | Chinstrap,Dream,49.0,19.5,210.0,3950.0,male,2008
319 | Chinstrap,Dream,46.2,17.5,187.0,3650.0,female,2008
320 | Chinstrap,Dream,50.9,19.1,196.0,3550.0,male,2008
321 | Chinstrap,Dream,45.5,17.0,196.0,3500.0,female,2008
322 | Chinstrap,Dream,50.9,17.9,196.0,3675.0,female,2009
323 | Chinstrap,Dream,50.8,18.5,201.0,4450.0,male,2009
324 | Chinstrap,Dream,50.1,17.9,190.0,3400.0,female,2009
325 | Chinstrap,Dream,49.0,19.6,212.0,4300.0,male,2009
326 | Chinstrap,Dream,51.5,18.7,187.0,3250.0,male,2009
327 | Chinstrap,Dream,49.8,17.3,198.0,3675.0,female,2009
328 | Chinstrap,Dream,48.1,16.4,199.0,3325.0,female,2009
329 | Chinstrap,Dream,51.4,19.0,201.0,3950.0,male,2009
330 | Chinstrap,Dream,45.7,17.3,193.0,3600.0,female,2009
331 | Chinstrap,Dream,50.7,19.7,203.0,4050.0,male,2009
332 | Chinstrap,Dream,42.5,17.3,187.0,3350.0,female,2009
333 | Chinstrap,Dream,52.2,18.8,197.0,3450.0,male,2009
334 | Chinstrap,Dream,45.2,16.6,191.0,3250.0,female,2009
335 | Chinstrap,Dream,49.3,19.9,203.0,4050.0,male,2009
336 | Chinstrap,Dream,50.2,18.8,202.0,3800.0,male,2009
337 | Chinstrap,Dream,45.6,19.4,194.0,3525.0,female,2009
338 | Chinstrap,Dream,51.9,19.5,206.0,3950.0,male,2009
339 | Chinstrap,Dream,46.8,16.5,189.0,3650.0,female,2009
340 | Chinstrap,Dream,45.7,17.0,195.0,3650.0,female,2009
341 | Chinstrap,Dream,55.8,19.8,207.0,4000.0,male,2009
342 | Chinstrap,Dream,43.5,18.1,202.0,3400.0,female,2009
343 | Chinstrap,Dream,49.6,18.2,193.0,3775.0,male,2009
344 | Chinstrap,Dream,50.8,19.0,210.0,4100.0,male,2009
345 | Chinstrap,Dream,50.2,18.7,198.0,3775.0,female,2009
346 |
--------------------------------------------------------------------------------
/Chapter05/penguin_ml/penguins_ml.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 |
3 | penguin_df = pd.read_csv('penguins.csv')
4 | penguin_df.dropna(inplace=True)
5 | output = penguin_df['species']
6 | features = penguin_df[['island', 'bill_length_mm', 'bill_depth_mm', 'flipper_length_mm', 'body_mass_g', 'sex']]
7 | features = pd.get_dummies(features)
8 | output, uniques = pd.factorize(output)
9 | print('Here is what our unique output variables represent')
10 | print(uniques)
11 | print('Here are our feature variables')
12 | print(features.head())
--------------------------------------------------------------------------------
/Chapter05/penguin_ml/penguins_streamlit.py:
--------------------------------------------------------------------------------
1 | import streamlit as st
2 | import seaborn as sns
3 | import matplotlib.pyplot as plt
4 | import pandas as pd
5 | import pickle
6 | from sklearn.metrics import accuracy_score
7 | from sklearn.ensemble import RandomForestClassifier
8 | from sklearn.model_selection import train_test_split
9 |
10 | st.title('Penguin Classifier')
11 |
12 | st.write("This app uses 6 inputs to predict the species of penguin using "
13 |
14 | "a model built on the Palmer's Penguin's dataset. Use the form below"
15 |
16 | " to get started!")
17 |
18 |
19 |
20 | password_guess = st.text_input('What is the Password?')
21 |
22 | if password_guess != 'streamlit_is_great':
23 | st.stop()
24 |
25 |
26 |
27 | penguin_file = st.file_uploader('Upload your own penguin data')
28 |
29 | if penguin_file is None:
30 |
31 | rf_pickle = open('random_forest_penguin.pickle', 'rb')
32 |
33 | map_pickle = open('output_penguin.pickle', 'rb')
34 |
35 | rfc = pickle.load(rf_pickle)
36 |
37 | unique_penguin_mapping = pickle.load(map_pickle)
38 |
39 | rf_pickle.close()
40 |
41 | map_pickle.close()
42 |
43 | else:
44 |
45 | penguin_df = pd.read_csv(penguin_file)
46 |
47 | penguin_df = penguin_df.dropna()
48 |
49 | output = penguin_df['species']
50 |
51 | features = penguin_df[['island', 'bill_length_mm', 'bill_depth_mm',
52 |
53 | 'flipper_length_mm', 'body_mass_g', 'sex']]
54 |
55 | features = pd.get_dummies(features)
56 |
57 | output, unique_penguin_mapping = pd.factorize(output)
58 |
59 |
60 |
61 | x_train, x_test, y_train, y_test = train_test_split(
62 |
63 | features, output, test_size=.8)
64 |
65 | rfc = RandomForestClassifier(random_state=15)
66 |
67 | rfc.fit(x_train, y_train)
68 |
69 | y_pred = rfc.predict(x_test)
70 |
71 | score = round(accuracy_score(y_pred, y_test), 2)
72 |
73 | st.write('We trained a Random Forest model on these data,'
74 | ' it has a score of {}! Use the '
75 | 'inputs below to try out the model.'.format(score))
76 |
77 | with st.form('user_inputs'):
78 | island = st.selectbox('Penguin Island', options=[
79 | 'Biscoe', 'Dream', 'Torgerson'])
80 | sex = st.selectbox('Sex', options=[
81 | 'Female', 'Male'])
82 | bill_length = st.number_input(
83 | 'Bill Length (mm)', min_value=0)
84 | bill_depth = st.number_input(
85 | 'Bill Depth (mm)', min_value=0)
86 | flipper_length = st.number_input(
87 | 'Flipper Length (mm)', min_value=0)
88 | body_mass = st.number_input(
89 | 'Body Mass (g)', min_value=0)
90 | st.form_submit_button()
91 |
92 |
93 |
94 | island_biscoe, island_dream, island_torgerson = 0, 0, 0
95 | if island == 'Biscoe':
96 | island_biscoe = 1
97 | elif island == 'Dream':
98 | island_dream = 1
99 | elif island == 'Torgerson':
100 | island_torgerson = 1
101 |
102 | sex_female, sex_male = 0, 0
103 |
104 | if sex == 'Female':
105 | sex_female = 1
106 |
107 | elif sex == 'Male':
108 | sex_male = 1
109 |
110 |
111 | new_prediction = rfc.predict([[bill_length, bill_depth, flipper_length,
112 | body_mass, island_biscoe, island_dream,
113 | island_torgerson, sex_female, sex_male]])
114 | prediction_species = unique_penguin_mapping[new_prediction][0]
115 | st.write('We predict your penguin is of the {} species'.format(prediction_species))
116 |
--------------------------------------------------------------------------------
/Chapter05/penguin_ml/random_forest_penguin.pickle:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Getting-started-with-Streamlit-for-Data-Science/50677d3f08c78f796b05cb1caf76246df3ff08ff/Chapter05/penguin_ml/random_forest_penguin.pickle
--------------------------------------------------------------------------------
/Chapter05/penguin_ml/requirements.txt:
--------------------------------------------------------------------------------
1 | pandas==1.0.5
2 | matplotlib==3.2.2
3 | seaborn==0.11.0
4 | streamlit==0.81.1
5 | scikit_learn==0.24.1
6 |
--------------------------------------------------------------------------------
/Chapter06/pretty_trees/pretty_trees.py:
--------------------------------------------------------------------------------
1 | import streamlit as st
2 |
3 | import pandas as pd
4 |
5 | import seaborn as sns
6 |
7 | import datetime as dt
8 |
9 | import matplotlib.pyplot as plt
10 |
11 |
12 |
13 | st.title('SF Trees')
14 |
15 | st.write('This app analyses trees in San Francisco using'
16 |
17 | ' a dataset kindly provided by SF DPW. The '
18 |
19 | 'histogram below is filtered by tree owner.')
20 |
21 |
22 |
23 | #load trees dataset, add age column in days
24 |
25 | trees_df = pd.read_csv('trees.csv')
26 |
27 | trees_df['age'] = (pd.to_datetime('today') -
28 |
29 | pd.to_datetime(trees_df['date'])).dt.days
30 |
31 | #add tree owner filter to sidebar, then filter, get color
32 |
33 | owners = st.sidebar.multiselect('Tree Owner Filter', trees_df['caretaker'].unique())
34 |
35 | graph_color = st.sidebar.color_picker('Graph Colors')
36 |
37 | if owners:
38 | trees_df = trees_df[trees_df['caretaker'].isin(owners)]
39 |
40 |
41 |
42 | #group by dbh for leftmost graph
43 |
44 | df_dbh_grouped = pd.DataFrame(trees_df.groupby(['dbh']).count()['tree_id'])
45 |
46 | df_dbh_grouped.columns = ['tree_count']
47 |
48 | col1, col2 = st.beta_columns(2)
49 |
50 | with col1:
51 |
52 | st.write('Trees by Width')
53 |
54 | fig_1, ax_1 = plt.subplots()
55 |
56 | ax_1 = sns.histplot(trees_df['dbh'],
57 |
58 | color=graph_color)
59 |
60 | plt.xlabel('Tree Width')
61 |
62 | st.pyplot(fig_1)
63 |
64 | with col2:
65 |
66 | st.write('Trees by Age')
67 |
68 | fig_2, ax_2 = plt.subplots()
69 |
70 | ax_2 = sns.histplot(trees_df['age'],
71 |
72 | color=graph_color)
73 |
74 | plt.xlabel('Age (Days)')
75 |
76 | st.pyplot(fig_2)
77 |
78 |
79 |
80 | st.write('Trees by Location')
81 |
82 | trees_df = trees_df.dropna(subset=['longitude', 'latitude'])
83 |
84 | trees_df = trees_df.sample(n = 1000, replace=True)
85 |
86 | st.map(trees_df)
--------------------------------------------------------------------------------
/Chapter07/components_example/gist_example.py:
--------------------------------------------------------------------------------
1 | import streamlit as st
2 | from streamlit_embedcode import github_gist
3 |
4 | st.title("Github Gist Example")
5 | st.write("Code from Palmer's Penguin Streamlit app.")
6 | github_gist('https://gist.github.com/tylerjrichards/9dcf6df0c17ccb7b91baafbe3cdf7654')
--------------------------------------------------------------------------------
/Chapter07/components_example/penguin_animated.py:
--------------------------------------------------------------------------------
1 | import streamlit as st
2 | from streamlit_lottie import st_lottie
3 | import requests
4 | import pandas as pd
5 | import matplotlib.pyplot as plt
6 | import seaborn as sns
7 | from pandas_profiling import ProfileReport
8 | from streamlit_pandas_profiling import st_profile_report
9 |
10 | def load_lottieurl(url: str):
11 | r = requests.get(url)
12 | if r.status_code != 200:
13 | return None
14 | return r.json()
15 |
16 | lottie_penguin = load_lottieurl('https://assets9.lottiefiles.com/private_files/lf30_lntyk83o.json')
17 | st_lottie(lottie_penguin, speed=1.5, width = 800, height = 400)
18 |
19 | st.title("Palmer's Penguins")
20 | st.markdown('Use this Streamlit app to make your own scatterplot about penguins!')
21 |
22 | selected_x_var = st.selectbox('What do want the x variable to be?',
23 | ['bill_length_mm', 'bill_depth_mm', 'flipper_length_mm', 'body_mass_g'])
24 | selected_y_var = st.selectbox('What about the y?',
25 | ['bill_depth_mm', 'bill_length_mm', 'flipper_length_mm', 'body_mass_g'])
26 |
27 | penguin_file = st.file_uploader('Select Your Local Penguins CSV')
28 | if penguin_file is not None:
29 | penguins_df = pd.read_csv(penguin_file)
30 | else:
31 | penguins_df = pd.read_csv('penguins.csv')
32 |
33 | sns.set_style('darkgrid')
34 | markers = {"Adelie": "X", "Gentoo": "s", "Chinstrap":'o'}
35 | fig, ax = plt.subplots()
36 | ax = sns.scatterplot(data = penguins_df, x = selected_x_var,
37 | y = selected_y_var, hue = 'species', markers = markers,
38 | style = 'species')
39 | plt.xlabel(selected_x_var)
40 | plt.ylabel(selected_y_var)
41 | plt.title("Scatterplot of Palmer's Penguins")
42 | st.pyplot(fig)
43 |
44 | st.title('Pandas Profiling of Penguin Dataset')
45 | penguin_profile = ProfileReport(penguins_df, explorative=True)
46 | st_profile_report(penguin_profile)
--------------------------------------------------------------------------------
/Chapter07/components_example/penguins.csv:
--------------------------------------------------------------------------------
1 | species,island,bill_length_mm,bill_depth_mm,flipper_length_mm,body_mass_g,sex,year
2 | Adelie,Torgersen,39.1,18.7,181.0,3750.0,male,2007
3 | Adelie,Torgersen,39.5,17.4,186.0,3800.0,female,2007
4 | Adelie,Torgersen,40.3,18.0,195.0,3250.0,female,2007
5 | Adelie,Torgersen,,,,,,2007
6 | Adelie,Torgersen,36.7,19.3,193.0,3450.0,female,2007
7 | Adelie,Torgersen,39.3,20.6,190.0,3650.0,male,2007
8 | Adelie,Torgersen,38.9,17.8,181.0,3625.0,female,2007
9 | Adelie,Torgersen,39.2,19.6,195.0,4675.0,male,2007
10 | Adelie,Torgersen,34.1,18.1,193.0,3475.0,,2007
11 | Adelie,Torgersen,42.0,20.2,190.0,4250.0,,2007
12 | Adelie,Torgersen,37.8,17.1,186.0,3300.0,,2007
13 | Adelie,Torgersen,37.8,17.3,180.0,3700.0,,2007
14 | Adelie,Torgersen,41.1,17.6,182.0,3200.0,female,2007
15 | Adelie,Torgersen,38.6,21.2,191.0,3800.0,male,2007
16 | Adelie,Torgersen,34.6,21.1,198.0,4400.0,male,2007
17 | Adelie,Torgersen,36.6,17.8,185.0,3700.0,female,2007
18 | Adelie,Torgersen,38.7,19.0,195.0,3450.0,female,2007
19 | Adelie,Torgersen,42.5,20.7,197.0,4500.0,male,2007
20 | Adelie,Torgersen,34.4,18.4,184.0,3325.0,female,2007
21 | Adelie,Torgersen,46.0,21.5,194.0,4200.0,male,2007
22 | Adelie,Biscoe,37.8,18.3,174.0,3400.0,female,2007
23 | Adelie,Biscoe,37.7,18.7,180.0,3600.0,male,2007
24 | Adelie,Biscoe,35.9,19.2,189.0,3800.0,female,2007
25 | Adelie,Biscoe,38.2,18.1,185.0,3950.0,male,2007
26 | Adelie,Biscoe,38.8,17.2,180.0,3800.0,male,2007
27 | Adelie,Biscoe,35.3,18.9,187.0,3800.0,female,2007
28 | Adelie,Biscoe,40.6,18.6,183.0,3550.0,male,2007
29 | Adelie,Biscoe,40.5,17.9,187.0,3200.0,female,2007
30 | Adelie,Biscoe,37.9,18.6,172.0,3150.0,female,2007
31 | Adelie,Biscoe,40.5,18.9,180.0,3950.0,male,2007
32 | Adelie,Dream,39.5,16.7,178.0,3250.0,female,2007
33 | Adelie,Dream,37.2,18.1,178.0,3900.0,male,2007
34 | Adelie,Dream,39.5,17.8,188.0,3300.0,female,2007
35 | Adelie,Dream,40.9,18.9,184.0,3900.0,male,2007
36 | Adelie,Dream,36.4,17.0,195.0,3325.0,female,2007
37 | Adelie,Dream,39.2,21.1,196.0,4150.0,male,2007
38 | Adelie,Dream,38.8,20.0,190.0,3950.0,male,2007
39 | Adelie,Dream,42.2,18.5,180.0,3550.0,female,2007
40 | Adelie,Dream,37.6,19.3,181.0,3300.0,female,2007
41 | Adelie,Dream,39.8,19.1,184.0,4650.0,male,2007
42 | Adelie,Dream,36.5,18.0,182.0,3150.0,female,2007
43 | Adelie,Dream,40.8,18.4,195.0,3900.0,male,2007
44 | Adelie,Dream,36.0,18.5,186.0,3100.0,female,2007
45 | Adelie,Dream,44.1,19.7,196.0,4400.0,male,2007
46 | Adelie,Dream,37.0,16.9,185.0,3000.0,female,2007
47 | Adelie,Dream,39.6,18.8,190.0,4600.0,male,2007
48 | Adelie,Dream,41.1,19.0,182.0,3425.0,male,2007
49 | Adelie,Dream,37.5,18.9,179.0,2975.0,,2007
50 | Adelie,Dream,36.0,17.9,190.0,3450.0,female,2007
51 | Adelie,Dream,42.3,21.2,191.0,4150.0,male,2007
52 | Adelie,Biscoe,39.6,17.7,186.0,3500.0,female,2008
53 | Adelie,Biscoe,40.1,18.9,188.0,4300.0,male,2008
54 | Adelie,Biscoe,35.0,17.9,190.0,3450.0,female,2008
55 | Adelie,Biscoe,42.0,19.5,200.0,4050.0,male,2008
56 | Adelie,Biscoe,34.5,18.1,187.0,2900.0,female,2008
57 | Adelie,Biscoe,41.4,18.6,191.0,3700.0,male,2008
58 | Adelie,Biscoe,39.0,17.5,186.0,3550.0,female,2008
59 | Adelie,Biscoe,40.6,18.8,193.0,3800.0,male,2008
60 | Adelie,Biscoe,36.5,16.6,181.0,2850.0,female,2008
61 | Adelie,Biscoe,37.6,19.1,194.0,3750.0,male,2008
62 | Adelie,Biscoe,35.7,16.9,185.0,3150.0,female,2008
63 | Adelie,Biscoe,41.3,21.1,195.0,4400.0,male,2008
64 | Adelie,Biscoe,37.6,17.0,185.0,3600.0,female,2008
65 | Adelie,Biscoe,41.1,18.2,192.0,4050.0,male,2008
66 | Adelie,Biscoe,36.4,17.1,184.0,2850.0,female,2008
67 | Adelie,Biscoe,41.6,18.0,192.0,3950.0,male,2008
68 | Adelie,Biscoe,35.5,16.2,195.0,3350.0,female,2008
69 | Adelie,Biscoe,41.1,19.1,188.0,4100.0,male,2008
70 | Adelie,Torgersen,35.9,16.6,190.0,3050.0,female,2008
71 | Adelie,Torgersen,41.8,19.4,198.0,4450.0,male,2008
72 | Adelie,Torgersen,33.5,19.0,190.0,3600.0,female,2008
73 | Adelie,Torgersen,39.7,18.4,190.0,3900.0,male,2008
74 | Adelie,Torgersen,39.6,17.2,196.0,3550.0,female,2008
75 | Adelie,Torgersen,45.8,18.9,197.0,4150.0,male,2008
76 | Adelie,Torgersen,35.5,17.5,190.0,3700.0,female,2008
77 | Adelie,Torgersen,42.8,18.5,195.0,4250.0,male,2008
78 | Adelie,Torgersen,40.9,16.8,191.0,3700.0,female,2008
79 | Adelie,Torgersen,37.2,19.4,184.0,3900.0,male,2008
80 | Adelie,Torgersen,36.2,16.1,187.0,3550.0,female,2008
81 | Adelie,Torgersen,42.1,19.1,195.0,4000.0,male,2008
82 | Adelie,Torgersen,34.6,17.2,189.0,3200.0,female,2008
83 | Adelie,Torgersen,42.9,17.6,196.0,4700.0,male,2008
84 | Adelie,Torgersen,36.7,18.8,187.0,3800.0,female,2008
85 | Adelie,Torgersen,35.1,19.4,193.0,4200.0,male,2008
86 | Adelie,Dream,37.3,17.8,191.0,3350.0,female,2008
87 | Adelie,Dream,41.3,20.3,194.0,3550.0,male,2008
88 | Adelie,Dream,36.3,19.5,190.0,3800.0,male,2008
89 | Adelie,Dream,36.9,18.6,189.0,3500.0,female,2008
90 | Adelie,Dream,38.3,19.2,189.0,3950.0,male,2008
91 | Adelie,Dream,38.9,18.8,190.0,3600.0,female,2008
92 | Adelie,Dream,35.7,18.0,202.0,3550.0,female,2008
93 | Adelie,Dream,41.1,18.1,205.0,4300.0,male,2008
94 | Adelie,Dream,34.0,17.1,185.0,3400.0,female,2008
95 | Adelie,Dream,39.6,18.1,186.0,4450.0,male,2008
96 | Adelie,Dream,36.2,17.3,187.0,3300.0,female,2008
97 | Adelie,Dream,40.8,18.9,208.0,4300.0,male,2008
98 | Adelie,Dream,38.1,18.6,190.0,3700.0,female,2008
99 | Adelie,Dream,40.3,18.5,196.0,4350.0,male,2008
100 | Adelie,Dream,33.1,16.1,178.0,2900.0,female,2008
101 | Adelie,Dream,43.2,18.5,192.0,4100.0,male,2008
102 | Adelie,Biscoe,35.0,17.9,192.0,3725.0,female,2009
103 | Adelie,Biscoe,41.0,20.0,203.0,4725.0,male,2009
104 | Adelie,Biscoe,37.7,16.0,183.0,3075.0,female,2009
105 | Adelie,Biscoe,37.8,20.0,190.0,4250.0,male,2009
106 | Adelie,Biscoe,37.9,18.6,193.0,2925.0,female,2009
107 | Adelie,Biscoe,39.7,18.9,184.0,3550.0,male,2009
108 | Adelie,Biscoe,38.6,17.2,199.0,3750.0,female,2009
109 | Adelie,Biscoe,38.2,20.0,190.0,3900.0,male,2009
110 | Adelie,Biscoe,38.1,17.0,181.0,3175.0,female,2009
111 | Adelie,Biscoe,43.2,19.0,197.0,4775.0,male,2009
112 | Adelie,Biscoe,38.1,16.5,198.0,3825.0,female,2009
113 | Adelie,Biscoe,45.6,20.3,191.0,4600.0,male,2009
114 | Adelie,Biscoe,39.7,17.7,193.0,3200.0,female,2009
115 | Adelie,Biscoe,42.2,19.5,197.0,4275.0,male,2009
116 | Adelie,Biscoe,39.6,20.7,191.0,3900.0,female,2009
117 | Adelie,Biscoe,42.7,18.3,196.0,4075.0,male,2009
118 | Adelie,Torgersen,38.6,17.0,188.0,2900.0,female,2009
119 | Adelie,Torgersen,37.3,20.5,199.0,3775.0,male,2009
120 | Adelie,Torgersen,35.7,17.0,189.0,3350.0,female,2009
121 | Adelie,Torgersen,41.1,18.6,189.0,3325.0,male,2009
122 | Adelie,Torgersen,36.2,17.2,187.0,3150.0,female,2009
123 | Adelie,Torgersen,37.7,19.8,198.0,3500.0,male,2009
124 | Adelie,Torgersen,40.2,17.0,176.0,3450.0,female,2009
125 | Adelie,Torgersen,41.4,18.5,202.0,3875.0,male,2009
126 | Adelie,Torgersen,35.2,15.9,186.0,3050.0,female,2009
127 | Adelie,Torgersen,40.6,19.0,199.0,4000.0,male,2009
128 | Adelie,Torgersen,38.8,17.6,191.0,3275.0,female,2009
129 | Adelie,Torgersen,41.5,18.3,195.0,4300.0,male,2009
130 | Adelie,Torgersen,39.0,17.1,191.0,3050.0,female,2009
131 | Adelie,Torgersen,44.1,18.0,210.0,4000.0,male,2009
132 | Adelie,Torgersen,38.5,17.9,190.0,3325.0,female,2009
133 | Adelie,Torgersen,43.1,19.2,197.0,3500.0,male,2009
134 | Adelie,Dream,36.8,18.5,193.0,3500.0,female,2009
135 | Adelie,Dream,37.5,18.5,199.0,4475.0,male,2009
136 | Adelie,Dream,38.1,17.6,187.0,3425.0,female,2009
137 | Adelie,Dream,41.1,17.5,190.0,3900.0,male,2009
138 | Adelie,Dream,35.6,17.5,191.0,3175.0,female,2009
139 | Adelie,Dream,40.2,20.1,200.0,3975.0,male,2009
140 | Adelie,Dream,37.0,16.5,185.0,3400.0,female,2009
141 | Adelie,Dream,39.7,17.9,193.0,4250.0,male,2009
142 | Adelie,Dream,40.2,17.1,193.0,3400.0,female,2009
143 | Adelie,Dream,40.6,17.2,187.0,3475.0,male,2009
144 | Adelie,Dream,32.1,15.5,188.0,3050.0,female,2009
145 | Adelie,Dream,40.7,17.0,190.0,3725.0,male,2009
146 | Adelie,Dream,37.3,16.8,192.0,3000.0,female,2009
147 | Adelie,Dream,39.0,18.7,185.0,3650.0,male,2009
148 | Adelie,Dream,39.2,18.6,190.0,4250.0,male,2009
149 | Adelie,Dream,36.6,18.4,184.0,3475.0,female,2009
150 | Adelie,Dream,36.0,17.8,195.0,3450.0,female,2009
151 | Adelie,Dream,37.8,18.1,193.0,3750.0,male,2009
152 | Adelie,Dream,36.0,17.1,187.0,3700.0,female,2009
153 | Adelie,Dream,41.5,18.5,201.0,4000.0,male,2009
154 | Gentoo,Biscoe,46.1,13.2,211.0,4500.0,female,2007
155 | Gentoo,Biscoe,50.0,16.3,230.0,5700.0,male,2007
156 | Gentoo,Biscoe,48.7,14.1,210.0,4450.0,female,2007
157 | Gentoo,Biscoe,50.0,15.2,218.0,5700.0,male,2007
158 | Gentoo,Biscoe,47.6,14.5,215.0,5400.0,male,2007
159 | Gentoo,Biscoe,46.5,13.5,210.0,4550.0,female,2007
160 | Gentoo,Biscoe,45.4,14.6,211.0,4800.0,female,2007
161 | Gentoo,Biscoe,46.7,15.3,219.0,5200.0,male,2007
162 | Gentoo,Biscoe,43.3,13.4,209.0,4400.0,female,2007
163 | Gentoo,Biscoe,46.8,15.4,215.0,5150.0,male,2007
164 | Gentoo,Biscoe,40.9,13.7,214.0,4650.0,female,2007
165 | Gentoo,Biscoe,49.0,16.1,216.0,5550.0,male,2007
166 | Gentoo,Biscoe,45.5,13.7,214.0,4650.0,female,2007
167 | Gentoo,Biscoe,48.4,14.6,213.0,5850.0,male,2007
168 | Gentoo,Biscoe,45.8,14.6,210.0,4200.0,female,2007
169 | Gentoo,Biscoe,49.3,15.7,217.0,5850.0,male,2007
170 | Gentoo,Biscoe,42.0,13.5,210.0,4150.0,female,2007
171 | Gentoo,Biscoe,49.2,15.2,221.0,6300.0,male,2007
172 | Gentoo,Biscoe,46.2,14.5,209.0,4800.0,female,2007
173 | Gentoo,Biscoe,48.7,15.1,222.0,5350.0,male,2007
174 | Gentoo,Biscoe,50.2,14.3,218.0,5700.0,male,2007
175 | Gentoo,Biscoe,45.1,14.5,215.0,5000.0,female,2007
176 | Gentoo,Biscoe,46.5,14.5,213.0,4400.0,female,2007
177 | Gentoo,Biscoe,46.3,15.8,215.0,5050.0,male,2007
178 | Gentoo,Biscoe,42.9,13.1,215.0,5000.0,female,2007
179 | Gentoo,Biscoe,46.1,15.1,215.0,5100.0,male,2007
180 | Gentoo,Biscoe,44.5,14.3,216.0,4100.0,,2007
181 | Gentoo,Biscoe,47.8,15.0,215.0,5650.0,male,2007
182 | Gentoo,Biscoe,48.2,14.3,210.0,4600.0,female,2007
183 | Gentoo,Biscoe,50.0,15.3,220.0,5550.0,male,2007
184 | Gentoo,Biscoe,47.3,15.3,222.0,5250.0,male,2007
185 | Gentoo,Biscoe,42.8,14.2,209.0,4700.0,female,2007
186 | Gentoo,Biscoe,45.1,14.5,207.0,5050.0,female,2007
187 | Gentoo,Biscoe,59.6,17.0,230.0,6050.0,male,2007
188 | Gentoo,Biscoe,49.1,14.8,220.0,5150.0,female,2008
189 | Gentoo,Biscoe,48.4,16.3,220.0,5400.0,male,2008
190 | Gentoo,Biscoe,42.6,13.7,213.0,4950.0,female,2008
191 | Gentoo,Biscoe,44.4,17.3,219.0,5250.0,male,2008
192 | Gentoo,Biscoe,44.0,13.6,208.0,4350.0,female,2008
193 | Gentoo,Biscoe,48.7,15.7,208.0,5350.0,male,2008
194 | Gentoo,Biscoe,42.7,13.7,208.0,3950.0,female,2008
195 | Gentoo,Biscoe,49.6,16.0,225.0,5700.0,male,2008
196 | Gentoo,Biscoe,45.3,13.7,210.0,4300.0,female,2008
197 | Gentoo,Biscoe,49.6,15.0,216.0,4750.0,male,2008
198 | Gentoo,Biscoe,50.5,15.9,222.0,5550.0,male,2008
199 | Gentoo,Biscoe,43.6,13.9,217.0,4900.0,female,2008
200 | Gentoo,Biscoe,45.5,13.9,210.0,4200.0,female,2008
201 | Gentoo,Biscoe,50.5,15.9,225.0,5400.0,male,2008
202 | Gentoo,Biscoe,44.9,13.3,213.0,5100.0,female,2008
203 | Gentoo,Biscoe,45.2,15.8,215.0,5300.0,male,2008
204 | Gentoo,Biscoe,46.6,14.2,210.0,4850.0,female,2008
205 | Gentoo,Biscoe,48.5,14.1,220.0,5300.0,male,2008
206 | Gentoo,Biscoe,45.1,14.4,210.0,4400.0,female,2008
207 | Gentoo,Biscoe,50.1,15.0,225.0,5000.0,male,2008
208 | Gentoo,Biscoe,46.5,14.4,217.0,4900.0,female,2008
209 | Gentoo,Biscoe,45.0,15.4,220.0,5050.0,male,2008
210 | Gentoo,Biscoe,43.8,13.9,208.0,4300.0,female,2008
211 | Gentoo,Biscoe,45.5,15.0,220.0,5000.0,male,2008
212 | Gentoo,Biscoe,43.2,14.5,208.0,4450.0,female,2008
213 | Gentoo,Biscoe,50.4,15.3,224.0,5550.0,male,2008
214 | Gentoo,Biscoe,45.3,13.8,208.0,4200.0,female,2008
215 | Gentoo,Biscoe,46.2,14.9,221.0,5300.0,male,2008
216 | Gentoo,Biscoe,45.7,13.9,214.0,4400.0,female,2008
217 | Gentoo,Biscoe,54.3,15.7,231.0,5650.0,male,2008
218 | Gentoo,Biscoe,45.8,14.2,219.0,4700.0,female,2008
219 | Gentoo,Biscoe,49.8,16.8,230.0,5700.0,male,2008
220 | Gentoo,Biscoe,46.2,14.4,214.0,4650.0,,2008
221 | Gentoo,Biscoe,49.5,16.2,229.0,5800.0,male,2008
222 | Gentoo,Biscoe,43.5,14.2,220.0,4700.0,female,2008
223 | Gentoo,Biscoe,50.7,15.0,223.0,5550.0,male,2008
224 | Gentoo,Biscoe,47.7,15.0,216.0,4750.0,female,2008
225 | Gentoo,Biscoe,46.4,15.6,221.0,5000.0,male,2008
226 | Gentoo,Biscoe,48.2,15.6,221.0,5100.0,male,2008
227 | Gentoo,Biscoe,46.5,14.8,217.0,5200.0,female,2008
228 | Gentoo,Biscoe,46.4,15.0,216.0,4700.0,female,2008
229 | Gentoo,Biscoe,48.6,16.0,230.0,5800.0,male,2008
230 | Gentoo,Biscoe,47.5,14.2,209.0,4600.0,female,2008
231 | Gentoo,Biscoe,51.1,16.3,220.0,6000.0,male,2008
232 | Gentoo,Biscoe,45.2,13.8,215.0,4750.0,female,2008
233 | Gentoo,Biscoe,45.2,16.4,223.0,5950.0,male,2008
234 | Gentoo,Biscoe,49.1,14.5,212.0,4625.0,female,2009
235 | Gentoo,Biscoe,52.5,15.6,221.0,5450.0,male,2009
236 | Gentoo,Biscoe,47.4,14.6,212.0,4725.0,female,2009
237 | Gentoo,Biscoe,50.0,15.9,224.0,5350.0,male,2009
238 | Gentoo,Biscoe,44.9,13.8,212.0,4750.0,female,2009
239 | Gentoo,Biscoe,50.8,17.3,228.0,5600.0,male,2009
240 | Gentoo,Biscoe,43.4,14.4,218.0,4600.0,female,2009
241 | Gentoo,Biscoe,51.3,14.2,218.0,5300.0,male,2009
242 | Gentoo,Biscoe,47.5,14.0,212.0,4875.0,female,2009
243 | Gentoo,Biscoe,52.1,17.0,230.0,5550.0,male,2009
244 | Gentoo,Biscoe,47.5,15.0,218.0,4950.0,female,2009
245 | Gentoo,Biscoe,52.2,17.1,228.0,5400.0,male,2009
246 | Gentoo,Biscoe,45.5,14.5,212.0,4750.0,female,2009
247 | Gentoo,Biscoe,49.5,16.1,224.0,5650.0,male,2009
248 | Gentoo,Biscoe,44.5,14.7,214.0,4850.0,female,2009
249 | Gentoo,Biscoe,50.8,15.7,226.0,5200.0,male,2009
250 | Gentoo,Biscoe,49.4,15.8,216.0,4925.0,male,2009
251 | Gentoo,Biscoe,46.9,14.6,222.0,4875.0,female,2009
252 | Gentoo,Biscoe,48.4,14.4,203.0,4625.0,female,2009
253 | Gentoo,Biscoe,51.1,16.5,225.0,5250.0,male,2009
254 | Gentoo,Biscoe,48.5,15.0,219.0,4850.0,female,2009
255 | Gentoo,Biscoe,55.9,17.0,228.0,5600.0,male,2009
256 | Gentoo,Biscoe,47.2,15.5,215.0,4975.0,female,2009
257 | Gentoo,Biscoe,49.1,15.0,228.0,5500.0,male,2009
258 | Gentoo,Biscoe,47.3,13.8,216.0,4725.0,,2009
259 | Gentoo,Biscoe,46.8,16.1,215.0,5500.0,male,2009
260 | Gentoo,Biscoe,41.7,14.7,210.0,4700.0,female,2009
261 | Gentoo,Biscoe,53.4,15.8,219.0,5500.0,male,2009
262 | Gentoo,Biscoe,43.3,14.0,208.0,4575.0,female,2009
263 | Gentoo,Biscoe,48.1,15.1,209.0,5500.0,male,2009
264 | Gentoo,Biscoe,50.5,15.2,216.0,5000.0,female,2009
265 | Gentoo,Biscoe,49.8,15.9,229.0,5950.0,male,2009
266 | Gentoo,Biscoe,43.5,15.2,213.0,4650.0,female,2009
267 | Gentoo,Biscoe,51.5,16.3,230.0,5500.0,male,2009
268 | Gentoo,Biscoe,46.2,14.1,217.0,4375.0,female,2009
269 | Gentoo,Biscoe,55.1,16.0,230.0,5850.0,male,2009
270 | Gentoo,Biscoe,44.5,15.7,217.0,4875.0,,2009
271 | Gentoo,Biscoe,48.8,16.2,222.0,6000.0,male,2009
272 | Gentoo,Biscoe,47.2,13.7,214.0,4925.0,female,2009
273 | Gentoo,Biscoe,,,,,,2009
274 | Gentoo,Biscoe,46.8,14.3,215.0,4850.0,female,2009
275 | Gentoo,Biscoe,50.4,15.7,222.0,5750.0,male,2009
276 | Gentoo,Biscoe,45.2,14.8,212.0,5200.0,female,2009
277 | Gentoo,Biscoe,49.9,16.1,213.0,5400.0,male,2009
278 | Chinstrap,Dream,46.5,17.9,192.0,3500.0,female,2007
279 | Chinstrap,Dream,50.0,19.5,196.0,3900.0,male,2007
280 | Chinstrap,Dream,51.3,19.2,193.0,3650.0,male,2007
281 | Chinstrap,Dream,45.4,18.7,188.0,3525.0,female,2007
282 | Chinstrap,Dream,52.7,19.8,197.0,3725.0,male,2007
283 | Chinstrap,Dream,45.2,17.8,198.0,3950.0,female,2007
284 | Chinstrap,Dream,46.1,18.2,178.0,3250.0,female,2007
285 | Chinstrap,Dream,51.3,18.2,197.0,3750.0,male,2007
286 | Chinstrap,Dream,46.0,18.9,195.0,4150.0,female,2007
287 | Chinstrap,Dream,51.3,19.9,198.0,3700.0,male,2007
288 | Chinstrap,Dream,46.6,17.8,193.0,3800.0,female,2007
289 | Chinstrap,Dream,51.7,20.3,194.0,3775.0,male,2007
290 | Chinstrap,Dream,47.0,17.3,185.0,3700.0,female,2007
291 | Chinstrap,Dream,52.0,18.1,201.0,4050.0,male,2007
292 | Chinstrap,Dream,45.9,17.1,190.0,3575.0,female,2007
293 | Chinstrap,Dream,50.5,19.6,201.0,4050.0,male,2007
294 | Chinstrap,Dream,50.3,20.0,197.0,3300.0,male,2007
295 | Chinstrap,Dream,58.0,17.8,181.0,3700.0,female,2007
296 | Chinstrap,Dream,46.4,18.6,190.0,3450.0,female,2007
297 | Chinstrap,Dream,49.2,18.2,195.0,4400.0,male,2007
298 | Chinstrap,Dream,42.4,17.3,181.0,3600.0,female,2007
299 | Chinstrap,Dream,48.5,17.5,191.0,3400.0,male,2007
300 | Chinstrap,Dream,43.2,16.6,187.0,2900.0,female,2007
301 | Chinstrap,Dream,50.6,19.4,193.0,3800.0,male,2007
302 | Chinstrap,Dream,46.7,17.9,195.0,3300.0,female,2007
303 | Chinstrap,Dream,52.0,19.0,197.0,4150.0,male,2007
304 | Chinstrap,Dream,50.5,18.4,200.0,3400.0,female,2008
305 | Chinstrap,Dream,49.5,19.0,200.0,3800.0,male,2008
306 | Chinstrap,Dream,46.4,17.8,191.0,3700.0,female,2008
307 | Chinstrap,Dream,52.8,20.0,205.0,4550.0,male,2008
308 | Chinstrap,Dream,40.9,16.6,187.0,3200.0,female,2008
309 | Chinstrap,Dream,54.2,20.8,201.0,4300.0,male,2008
310 | Chinstrap,Dream,42.5,16.7,187.0,3350.0,female,2008
311 | Chinstrap,Dream,51.0,18.8,203.0,4100.0,male,2008
312 | Chinstrap,Dream,49.7,18.6,195.0,3600.0,male,2008
313 | Chinstrap,Dream,47.5,16.8,199.0,3900.0,female,2008
314 | Chinstrap,Dream,47.6,18.3,195.0,3850.0,female,2008
315 | Chinstrap,Dream,52.0,20.7,210.0,4800.0,male,2008
316 | Chinstrap,Dream,46.9,16.6,192.0,2700.0,female,2008
317 | Chinstrap,Dream,53.5,19.9,205.0,4500.0,male,2008
318 | Chinstrap,Dream,49.0,19.5,210.0,3950.0,male,2008
319 | Chinstrap,Dream,46.2,17.5,187.0,3650.0,female,2008
320 | Chinstrap,Dream,50.9,19.1,196.0,3550.0,male,2008
321 | Chinstrap,Dream,45.5,17.0,196.0,3500.0,female,2008
322 | Chinstrap,Dream,50.9,17.9,196.0,3675.0,female,2009
323 | Chinstrap,Dream,50.8,18.5,201.0,4450.0,male,2009
324 | Chinstrap,Dream,50.1,17.9,190.0,3400.0,female,2009
325 | Chinstrap,Dream,49.0,19.6,212.0,4300.0,male,2009
326 | Chinstrap,Dream,51.5,18.7,187.0,3250.0,male,2009
327 | Chinstrap,Dream,49.8,17.3,198.0,3675.0,female,2009
328 | Chinstrap,Dream,48.1,16.4,199.0,3325.0,female,2009
329 | Chinstrap,Dream,51.4,19.0,201.0,3950.0,male,2009
330 | Chinstrap,Dream,45.7,17.3,193.0,3600.0,female,2009
331 | Chinstrap,Dream,50.7,19.7,203.0,4050.0,male,2009
332 | Chinstrap,Dream,42.5,17.3,187.0,3350.0,female,2009
333 | Chinstrap,Dream,52.2,18.8,197.0,3450.0,male,2009
334 | Chinstrap,Dream,45.2,16.6,191.0,3250.0,female,2009
335 | Chinstrap,Dream,49.3,19.9,203.0,4050.0,male,2009
336 | Chinstrap,Dream,50.2,18.8,202.0,3800.0,male,2009
337 | Chinstrap,Dream,45.6,19.4,194.0,3525.0,female,2009
338 | Chinstrap,Dream,51.9,19.5,206.0,3950.0,male,2009
339 | Chinstrap,Dream,46.8,16.5,189.0,3650.0,female,2009
340 | Chinstrap,Dream,45.7,17.0,195.0,3650.0,female,2009
341 | Chinstrap,Dream,55.8,19.8,207.0,4000.0,male,2009
342 | Chinstrap,Dream,43.5,18.1,202.0,3400.0,female,2009
343 | Chinstrap,Dream,49.6,18.2,193.0,3775.0,male,2009
344 | Chinstrap,Dream,50.8,19.0,210.0,4100.0,male,2009
345 | Chinstrap,Dream,50.2,18.7,198.0,3775.0,female,2009
346 |
--------------------------------------------------------------------------------
/Chapter07/components_example/tree_animated.py:
--------------------------------------------------------------------------------
1 |
2 | import streamlit as st
3 | import pandas as pd
4 | import seaborn as sns
5 | import datetime as dt
6 | import matplotlib.pyplot as plt
7 | from streamlit_lottie import st_lottie
8 | import requests
9 |
10 | def load_lottieurl(url: str):
11 | r = requests.get(url)
12 | if r.status_code != 200:
13 | return None
14 | return r.json()
15 |
16 | lottie_tree = load_lottieurl('https://assets7.lottiefiles.com/temp/lf20_yww8EW.json')
17 | st_lottie(lottie_tree, speed=1, height=100, key="initial")
18 |
19 | st.title('SF Trees')
20 | st.write('This app analyses trees in San Francisco using'
21 | ' a dataset kindly provided by SF DPW. The '
22 | 'histogram below is filtered by tree owner.')
23 |
24 | #load trees dataset, add age column in days
25 | trees_df = pd.read_csv('trees.csv')
26 | trees_df['age'] = (pd.to_datetime('today') -
27 | pd.to_datetime(trees_df['date'])).dt.days
28 | #add tree owner filter to sidebar, then filter, get color
29 | owners = st.sidebar.multiselect(
30 | 'Tree Owner Filter', trees_df['caretaker'].unique())
31 | graph_color = st.sidebar.color_picker('Graph Colors')
32 | if owners:
33 | trees_df = trees_df[trees_df['caretaker'].isin(owners)]
34 |
35 | #group by dbh for leftmost graph
36 | df_dbh_grouped = pd.DataFrame(trees_df.groupby(['dbh']).count()['tree_id'])
37 | df_dbh_grouped.columns = ['tree_count']
38 |
39 | #define multiple columns, add two graphs
40 | col1, col2 = st.beta_columns(2)
41 | with col1:
42 | st.write('Trees by Width')
43 | fig_1, ax_1 = plt.subplots()
44 | ax_1 = sns.histplot(trees_df['dbh'],
45 | color=graph_color)
46 | plt.xlabel('Tree Width')
47 | st.pyplot(fig_1)
48 | with col2:
49 | st.write('Trees by Age')
50 | fig_2, ax_2 = plt.subplots()
51 | ax_2 = sns.histplot(trees_df['age'],
52 | color=graph_color)
53 | plt.xlabel('Age (Days)')
54 | st.pyplot(fig_2)
55 |
56 | st.write('Trees by Location')
57 | trees_df = trees_df.dropna(subset=['longitude', 'latitude'])
58 | trees_df = trees_df.sample(n = 1000, replace=True)
59 | st.map(trees_df)
--------------------------------------------------------------------------------
/Chapter08/penguin_ml/feature_importance.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Getting-started-with-Streamlit-for-Data-Science/50677d3f08c78f796b05cb1caf76246df3ff08ff/Chapter08/penguin_ml/feature_importance.png
--------------------------------------------------------------------------------
/Chapter08/penguin_ml/output_penguin.pickle:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Getting-started-with-Streamlit-for-Data-Science/50677d3f08c78f796b05cb1caf76246df3ff08ff/Chapter08/penguin_ml/output_penguin.pickle
--------------------------------------------------------------------------------
/Chapter08/penguin_ml/penguins.csv:
--------------------------------------------------------------------------------
1 | species,island,bill_length_mm,bill_depth_mm,flipper_length_mm,body_mass_g,sex,year
2 | Adelie,Torgersen,39.1,18.7,181.0,3750.0,male,2007
3 | Adelie,Torgersen,39.5,17.4,186.0,3800.0,female,2007
4 | Adelie,Torgersen,40.3,18.0,195.0,3250.0,female,2007
5 | Adelie,Torgersen,,,,,,2007
6 | Adelie,Torgersen,36.7,19.3,193.0,3450.0,female,2007
7 | Adelie,Torgersen,39.3,20.6,190.0,3650.0,male,2007
8 | Adelie,Torgersen,38.9,17.8,181.0,3625.0,female,2007
9 | Adelie,Torgersen,39.2,19.6,195.0,4675.0,male,2007
10 | Adelie,Torgersen,34.1,18.1,193.0,3475.0,,2007
11 | Adelie,Torgersen,42.0,20.2,190.0,4250.0,,2007
12 | Adelie,Torgersen,37.8,17.1,186.0,3300.0,,2007
13 | Adelie,Torgersen,37.8,17.3,180.0,3700.0,,2007
14 | Adelie,Torgersen,41.1,17.6,182.0,3200.0,female,2007
15 | Adelie,Torgersen,38.6,21.2,191.0,3800.0,male,2007
16 | Adelie,Torgersen,34.6,21.1,198.0,4400.0,male,2007
17 | Adelie,Torgersen,36.6,17.8,185.0,3700.0,female,2007
18 | Adelie,Torgersen,38.7,19.0,195.0,3450.0,female,2007
19 | Adelie,Torgersen,42.5,20.7,197.0,4500.0,male,2007
20 | Adelie,Torgersen,34.4,18.4,184.0,3325.0,female,2007
21 | Adelie,Torgersen,46.0,21.5,194.0,4200.0,male,2007
22 | Adelie,Biscoe,37.8,18.3,174.0,3400.0,female,2007
23 | Adelie,Biscoe,37.7,18.7,180.0,3600.0,male,2007
24 | Adelie,Biscoe,35.9,19.2,189.0,3800.0,female,2007
25 | Adelie,Biscoe,38.2,18.1,185.0,3950.0,male,2007
26 | Adelie,Biscoe,38.8,17.2,180.0,3800.0,male,2007
27 | Adelie,Biscoe,35.3,18.9,187.0,3800.0,female,2007
28 | Adelie,Biscoe,40.6,18.6,183.0,3550.0,male,2007
29 | Adelie,Biscoe,40.5,17.9,187.0,3200.0,female,2007
30 | Adelie,Biscoe,37.9,18.6,172.0,3150.0,female,2007
31 | Adelie,Biscoe,40.5,18.9,180.0,3950.0,male,2007
32 | Adelie,Dream,39.5,16.7,178.0,3250.0,female,2007
33 | Adelie,Dream,37.2,18.1,178.0,3900.0,male,2007
34 | Adelie,Dream,39.5,17.8,188.0,3300.0,female,2007
35 | Adelie,Dream,40.9,18.9,184.0,3900.0,male,2007
36 | Adelie,Dream,36.4,17.0,195.0,3325.0,female,2007
37 | Adelie,Dream,39.2,21.1,196.0,4150.0,male,2007
38 | Adelie,Dream,38.8,20.0,190.0,3950.0,male,2007
39 | Adelie,Dream,42.2,18.5,180.0,3550.0,female,2007
40 | Adelie,Dream,37.6,19.3,181.0,3300.0,female,2007
41 | Adelie,Dream,39.8,19.1,184.0,4650.0,male,2007
42 | Adelie,Dream,36.5,18.0,182.0,3150.0,female,2007
43 | Adelie,Dream,40.8,18.4,195.0,3900.0,male,2007
44 | Adelie,Dream,36.0,18.5,186.0,3100.0,female,2007
45 | Adelie,Dream,44.1,19.7,196.0,4400.0,male,2007
46 | Adelie,Dream,37.0,16.9,185.0,3000.0,female,2007
47 | Adelie,Dream,39.6,18.8,190.0,4600.0,male,2007
48 | Adelie,Dream,41.1,19.0,182.0,3425.0,male,2007
49 | Adelie,Dream,37.5,18.9,179.0,2975.0,,2007
50 | Adelie,Dream,36.0,17.9,190.0,3450.0,female,2007
51 | Adelie,Dream,42.3,21.2,191.0,4150.0,male,2007
52 | Adelie,Biscoe,39.6,17.7,186.0,3500.0,female,2008
53 | Adelie,Biscoe,40.1,18.9,188.0,4300.0,male,2008
54 | Adelie,Biscoe,35.0,17.9,190.0,3450.0,female,2008
55 | Adelie,Biscoe,42.0,19.5,200.0,4050.0,male,2008
56 | Adelie,Biscoe,34.5,18.1,187.0,2900.0,female,2008
57 | Adelie,Biscoe,41.4,18.6,191.0,3700.0,male,2008
58 | Adelie,Biscoe,39.0,17.5,186.0,3550.0,female,2008
59 | Adelie,Biscoe,40.6,18.8,193.0,3800.0,male,2008
60 | Adelie,Biscoe,36.5,16.6,181.0,2850.0,female,2008
61 | Adelie,Biscoe,37.6,19.1,194.0,3750.0,male,2008
62 | Adelie,Biscoe,35.7,16.9,185.0,3150.0,female,2008
63 | Adelie,Biscoe,41.3,21.1,195.0,4400.0,male,2008
64 | Adelie,Biscoe,37.6,17.0,185.0,3600.0,female,2008
65 | Adelie,Biscoe,41.1,18.2,192.0,4050.0,male,2008
66 | Adelie,Biscoe,36.4,17.1,184.0,2850.0,female,2008
67 | Adelie,Biscoe,41.6,18.0,192.0,3950.0,male,2008
68 | Adelie,Biscoe,35.5,16.2,195.0,3350.0,female,2008
69 | Adelie,Biscoe,41.1,19.1,188.0,4100.0,male,2008
70 | Adelie,Torgersen,35.9,16.6,190.0,3050.0,female,2008
71 | Adelie,Torgersen,41.8,19.4,198.0,4450.0,male,2008
72 | Adelie,Torgersen,33.5,19.0,190.0,3600.0,female,2008
73 | Adelie,Torgersen,39.7,18.4,190.0,3900.0,male,2008
74 | Adelie,Torgersen,39.6,17.2,196.0,3550.0,female,2008
75 | Adelie,Torgersen,45.8,18.9,197.0,4150.0,male,2008
76 | Adelie,Torgersen,35.5,17.5,190.0,3700.0,female,2008
77 | Adelie,Torgersen,42.8,18.5,195.0,4250.0,male,2008
78 | Adelie,Torgersen,40.9,16.8,191.0,3700.0,female,2008
79 | Adelie,Torgersen,37.2,19.4,184.0,3900.0,male,2008
80 | Adelie,Torgersen,36.2,16.1,187.0,3550.0,female,2008
81 | Adelie,Torgersen,42.1,19.1,195.0,4000.0,male,2008
82 | Adelie,Torgersen,34.6,17.2,189.0,3200.0,female,2008
83 | Adelie,Torgersen,42.9,17.6,196.0,4700.0,male,2008
84 | Adelie,Torgersen,36.7,18.8,187.0,3800.0,female,2008
85 | Adelie,Torgersen,35.1,19.4,193.0,4200.0,male,2008
86 | Adelie,Dream,37.3,17.8,191.0,3350.0,female,2008
87 | Adelie,Dream,41.3,20.3,194.0,3550.0,male,2008
88 | Adelie,Dream,36.3,19.5,190.0,3800.0,male,2008
89 | Adelie,Dream,36.9,18.6,189.0,3500.0,female,2008
90 | Adelie,Dream,38.3,19.2,189.0,3950.0,male,2008
91 | Adelie,Dream,38.9,18.8,190.0,3600.0,female,2008
92 | Adelie,Dream,35.7,18.0,202.0,3550.0,female,2008
93 | Adelie,Dream,41.1,18.1,205.0,4300.0,male,2008
94 | Adelie,Dream,34.0,17.1,185.0,3400.0,female,2008
95 | Adelie,Dream,39.6,18.1,186.0,4450.0,male,2008
96 | Adelie,Dream,36.2,17.3,187.0,3300.0,female,2008
97 | Adelie,Dream,40.8,18.9,208.0,4300.0,male,2008
98 | Adelie,Dream,38.1,18.6,190.0,3700.0,female,2008
99 | Adelie,Dream,40.3,18.5,196.0,4350.0,male,2008
100 | Adelie,Dream,33.1,16.1,178.0,2900.0,female,2008
101 | Adelie,Dream,43.2,18.5,192.0,4100.0,male,2008
102 | Adelie,Biscoe,35.0,17.9,192.0,3725.0,female,2009
103 | Adelie,Biscoe,41.0,20.0,203.0,4725.0,male,2009
104 | Adelie,Biscoe,37.7,16.0,183.0,3075.0,female,2009
105 | Adelie,Biscoe,37.8,20.0,190.0,4250.0,male,2009
106 | Adelie,Biscoe,37.9,18.6,193.0,2925.0,female,2009
107 | Adelie,Biscoe,39.7,18.9,184.0,3550.0,male,2009
108 | Adelie,Biscoe,38.6,17.2,199.0,3750.0,female,2009
109 | Adelie,Biscoe,38.2,20.0,190.0,3900.0,male,2009
110 | Adelie,Biscoe,38.1,17.0,181.0,3175.0,female,2009
111 | Adelie,Biscoe,43.2,19.0,197.0,4775.0,male,2009
112 | Adelie,Biscoe,38.1,16.5,198.0,3825.0,female,2009
113 | Adelie,Biscoe,45.6,20.3,191.0,4600.0,male,2009
114 | Adelie,Biscoe,39.7,17.7,193.0,3200.0,female,2009
115 | Adelie,Biscoe,42.2,19.5,197.0,4275.0,male,2009
116 | Adelie,Biscoe,39.6,20.7,191.0,3900.0,female,2009
117 | Adelie,Biscoe,42.7,18.3,196.0,4075.0,male,2009
118 | Adelie,Torgersen,38.6,17.0,188.0,2900.0,female,2009
119 | Adelie,Torgersen,37.3,20.5,199.0,3775.0,male,2009
120 | Adelie,Torgersen,35.7,17.0,189.0,3350.0,female,2009
121 | Adelie,Torgersen,41.1,18.6,189.0,3325.0,male,2009
122 | Adelie,Torgersen,36.2,17.2,187.0,3150.0,female,2009
123 | Adelie,Torgersen,37.7,19.8,198.0,3500.0,male,2009
124 | Adelie,Torgersen,40.2,17.0,176.0,3450.0,female,2009
125 | Adelie,Torgersen,41.4,18.5,202.0,3875.0,male,2009
126 | Adelie,Torgersen,35.2,15.9,186.0,3050.0,female,2009
127 | Adelie,Torgersen,40.6,19.0,199.0,4000.0,male,2009
128 | Adelie,Torgersen,38.8,17.6,191.0,3275.0,female,2009
129 | Adelie,Torgersen,41.5,18.3,195.0,4300.0,male,2009
130 | Adelie,Torgersen,39.0,17.1,191.0,3050.0,female,2009
131 | Adelie,Torgersen,44.1,18.0,210.0,4000.0,male,2009
132 | Adelie,Torgersen,38.5,17.9,190.0,3325.0,female,2009
133 | Adelie,Torgersen,43.1,19.2,197.0,3500.0,male,2009
134 | Adelie,Dream,36.8,18.5,193.0,3500.0,female,2009
135 | Adelie,Dream,37.5,18.5,199.0,4475.0,male,2009
136 | Adelie,Dream,38.1,17.6,187.0,3425.0,female,2009
137 | Adelie,Dream,41.1,17.5,190.0,3900.0,male,2009
138 | Adelie,Dream,35.6,17.5,191.0,3175.0,female,2009
139 | Adelie,Dream,40.2,20.1,200.0,3975.0,male,2009
140 | Adelie,Dream,37.0,16.5,185.0,3400.0,female,2009
141 | Adelie,Dream,39.7,17.9,193.0,4250.0,male,2009
142 | Adelie,Dream,40.2,17.1,193.0,3400.0,female,2009
143 | Adelie,Dream,40.6,17.2,187.0,3475.0,male,2009
144 | Adelie,Dream,32.1,15.5,188.0,3050.0,female,2009
145 | Adelie,Dream,40.7,17.0,190.0,3725.0,male,2009
146 | Adelie,Dream,37.3,16.8,192.0,3000.0,female,2009
147 | Adelie,Dream,39.0,18.7,185.0,3650.0,male,2009
148 | Adelie,Dream,39.2,18.6,190.0,4250.0,male,2009
149 | Adelie,Dream,36.6,18.4,184.0,3475.0,female,2009
150 | Adelie,Dream,36.0,17.8,195.0,3450.0,female,2009
151 | Adelie,Dream,37.8,18.1,193.0,3750.0,male,2009
152 | Adelie,Dream,36.0,17.1,187.0,3700.0,female,2009
153 | Adelie,Dream,41.5,18.5,201.0,4000.0,male,2009
154 | Gentoo,Biscoe,46.1,13.2,211.0,4500.0,female,2007
155 | Gentoo,Biscoe,50.0,16.3,230.0,5700.0,male,2007
156 | Gentoo,Biscoe,48.7,14.1,210.0,4450.0,female,2007
157 | Gentoo,Biscoe,50.0,15.2,218.0,5700.0,male,2007
158 | Gentoo,Biscoe,47.6,14.5,215.0,5400.0,male,2007
159 | Gentoo,Biscoe,46.5,13.5,210.0,4550.0,female,2007
160 | Gentoo,Biscoe,45.4,14.6,211.0,4800.0,female,2007
161 | Gentoo,Biscoe,46.7,15.3,219.0,5200.0,male,2007
162 | Gentoo,Biscoe,43.3,13.4,209.0,4400.0,female,2007
163 | Gentoo,Biscoe,46.8,15.4,215.0,5150.0,male,2007
164 | Gentoo,Biscoe,40.9,13.7,214.0,4650.0,female,2007
165 | Gentoo,Biscoe,49.0,16.1,216.0,5550.0,male,2007
166 | Gentoo,Biscoe,45.5,13.7,214.0,4650.0,female,2007
167 | Gentoo,Biscoe,48.4,14.6,213.0,5850.0,male,2007
168 | Gentoo,Biscoe,45.8,14.6,210.0,4200.0,female,2007
169 | Gentoo,Biscoe,49.3,15.7,217.0,5850.0,male,2007
170 | Gentoo,Biscoe,42.0,13.5,210.0,4150.0,female,2007
171 | Gentoo,Biscoe,49.2,15.2,221.0,6300.0,male,2007
172 | Gentoo,Biscoe,46.2,14.5,209.0,4800.0,female,2007
173 | Gentoo,Biscoe,48.7,15.1,222.0,5350.0,male,2007
174 | Gentoo,Biscoe,50.2,14.3,218.0,5700.0,male,2007
175 | Gentoo,Biscoe,45.1,14.5,215.0,5000.0,female,2007
176 | Gentoo,Biscoe,46.5,14.5,213.0,4400.0,female,2007
177 | Gentoo,Biscoe,46.3,15.8,215.0,5050.0,male,2007
178 | Gentoo,Biscoe,42.9,13.1,215.0,5000.0,female,2007
179 | Gentoo,Biscoe,46.1,15.1,215.0,5100.0,male,2007
180 | Gentoo,Biscoe,44.5,14.3,216.0,4100.0,,2007
181 | Gentoo,Biscoe,47.8,15.0,215.0,5650.0,male,2007
182 | Gentoo,Biscoe,48.2,14.3,210.0,4600.0,female,2007
183 | Gentoo,Biscoe,50.0,15.3,220.0,5550.0,male,2007
184 | Gentoo,Biscoe,47.3,15.3,222.0,5250.0,male,2007
185 | Gentoo,Biscoe,42.8,14.2,209.0,4700.0,female,2007
186 | Gentoo,Biscoe,45.1,14.5,207.0,5050.0,female,2007
187 | Gentoo,Biscoe,59.6,17.0,230.0,6050.0,male,2007
188 | Gentoo,Biscoe,49.1,14.8,220.0,5150.0,female,2008
189 | Gentoo,Biscoe,48.4,16.3,220.0,5400.0,male,2008
190 | Gentoo,Biscoe,42.6,13.7,213.0,4950.0,female,2008
191 | Gentoo,Biscoe,44.4,17.3,219.0,5250.0,male,2008
192 | Gentoo,Biscoe,44.0,13.6,208.0,4350.0,female,2008
193 | Gentoo,Biscoe,48.7,15.7,208.0,5350.0,male,2008
194 | Gentoo,Biscoe,42.7,13.7,208.0,3950.0,female,2008
195 | Gentoo,Biscoe,49.6,16.0,225.0,5700.0,male,2008
196 | Gentoo,Biscoe,45.3,13.7,210.0,4300.0,female,2008
197 | Gentoo,Biscoe,49.6,15.0,216.0,4750.0,male,2008
198 | Gentoo,Biscoe,50.5,15.9,222.0,5550.0,male,2008
199 | Gentoo,Biscoe,43.6,13.9,217.0,4900.0,female,2008
200 | Gentoo,Biscoe,45.5,13.9,210.0,4200.0,female,2008
201 | Gentoo,Biscoe,50.5,15.9,225.0,5400.0,male,2008
202 | Gentoo,Biscoe,44.9,13.3,213.0,5100.0,female,2008
203 | Gentoo,Biscoe,45.2,15.8,215.0,5300.0,male,2008
204 | Gentoo,Biscoe,46.6,14.2,210.0,4850.0,female,2008
205 | Gentoo,Biscoe,48.5,14.1,220.0,5300.0,male,2008
206 | Gentoo,Biscoe,45.1,14.4,210.0,4400.0,female,2008
207 | Gentoo,Biscoe,50.1,15.0,225.0,5000.0,male,2008
208 | Gentoo,Biscoe,46.5,14.4,217.0,4900.0,female,2008
209 | Gentoo,Biscoe,45.0,15.4,220.0,5050.0,male,2008
210 | Gentoo,Biscoe,43.8,13.9,208.0,4300.0,female,2008
211 | Gentoo,Biscoe,45.5,15.0,220.0,5000.0,male,2008
212 | Gentoo,Biscoe,43.2,14.5,208.0,4450.0,female,2008
213 | Gentoo,Biscoe,50.4,15.3,224.0,5550.0,male,2008
214 | Gentoo,Biscoe,45.3,13.8,208.0,4200.0,female,2008
215 | Gentoo,Biscoe,46.2,14.9,221.0,5300.0,male,2008
216 | Gentoo,Biscoe,45.7,13.9,214.0,4400.0,female,2008
217 | Gentoo,Biscoe,54.3,15.7,231.0,5650.0,male,2008
218 | Gentoo,Biscoe,45.8,14.2,219.0,4700.0,female,2008
219 | Gentoo,Biscoe,49.8,16.8,230.0,5700.0,male,2008
220 | Gentoo,Biscoe,46.2,14.4,214.0,4650.0,,2008
221 | Gentoo,Biscoe,49.5,16.2,229.0,5800.0,male,2008
222 | Gentoo,Biscoe,43.5,14.2,220.0,4700.0,female,2008
223 | Gentoo,Biscoe,50.7,15.0,223.0,5550.0,male,2008
224 | Gentoo,Biscoe,47.7,15.0,216.0,4750.0,female,2008
225 | Gentoo,Biscoe,46.4,15.6,221.0,5000.0,male,2008
226 | Gentoo,Biscoe,48.2,15.6,221.0,5100.0,male,2008
227 | Gentoo,Biscoe,46.5,14.8,217.0,5200.0,female,2008
228 | Gentoo,Biscoe,46.4,15.0,216.0,4700.0,female,2008
229 | Gentoo,Biscoe,48.6,16.0,230.0,5800.0,male,2008
230 | Gentoo,Biscoe,47.5,14.2,209.0,4600.0,female,2008
231 | Gentoo,Biscoe,51.1,16.3,220.0,6000.0,male,2008
232 | Gentoo,Biscoe,45.2,13.8,215.0,4750.0,female,2008
233 | Gentoo,Biscoe,45.2,16.4,223.0,5950.0,male,2008
234 | Gentoo,Biscoe,49.1,14.5,212.0,4625.0,female,2009
235 | Gentoo,Biscoe,52.5,15.6,221.0,5450.0,male,2009
236 | Gentoo,Biscoe,47.4,14.6,212.0,4725.0,female,2009
237 | Gentoo,Biscoe,50.0,15.9,224.0,5350.0,male,2009
238 | Gentoo,Biscoe,44.9,13.8,212.0,4750.0,female,2009
239 | Gentoo,Biscoe,50.8,17.3,228.0,5600.0,male,2009
240 | Gentoo,Biscoe,43.4,14.4,218.0,4600.0,female,2009
241 | Gentoo,Biscoe,51.3,14.2,218.0,5300.0,male,2009
242 | Gentoo,Biscoe,47.5,14.0,212.0,4875.0,female,2009
243 | Gentoo,Biscoe,52.1,17.0,230.0,5550.0,male,2009
244 | Gentoo,Biscoe,47.5,15.0,218.0,4950.0,female,2009
245 | Gentoo,Biscoe,52.2,17.1,228.0,5400.0,male,2009
246 | Gentoo,Biscoe,45.5,14.5,212.0,4750.0,female,2009
247 | Gentoo,Biscoe,49.5,16.1,224.0,5650.0,male,2009
248 | Gentoo,Biscoe,44.5,14.7,214.0,4850.0,female,2009
249 | Gentoo,Biscoe,50.8,15.7,226.0,5200.0,male,2009
250 | Gentoo,Biscoe,49.4,15.8,216.0,4925.0,male,2009
251 | Gentoo,Biscoe,46.9,14.6,222.0,4875.0,female,2009
252 | Gentoo,Biscoe,48.4,14.4,203.0,4625.0,female,2009
253 | Gentoo,Biscoe,51.1,16.5,225.0,5250.0,male,2009
254 | Gentoo,Biscoe,48.5,15.0,219.0,4850.0,female,2009
255 | Gentoo,Biscoe,55.9,17.0,228.0,5600.0,male,2009
256 | Gentoo,Biscoe,47.2,15.5,215.0,4975.0,female,2009
257 | Gentoo,Biscoe,49.1,15.0,228.0,5500.0,male,2009
258 | Gentoo,Biscoe,47.3,13.8,216.0,4725.0,,2009
259 | Gentoo,Biscoe,46.8,16.1,215.0,5500.0,male,2009
260 | Gentoo,Biscoe,41.7,14.7,210.0,4700.0,female,2009
261 | Gentoo,Biscoe,53.4,15.8,219.0,5500.0,male,2009
262 | Gentoo,Biscoe,43.3,14.0,208.0,4575.0,female,2009
263 | Gentoo,Biscoe,48.1,15.1,209.0,5500.0,male,2009
264 | Gentoo,Biscoe,50.5,15.2,216.0,5000.0,female,2009
265 | Gentoo,Biscoe,49.8,15.9,229.0,5950.0,male,2009
266 | Gentoo,Biscoe,43.5,15.2,213.0,4650.0,female,2009
267 | Gentoo,Biscoe,51.5,16.3,230.0,5500.0,male,2009
268 | Gentoo,Biscoe,46.2,14.1,217.0,4375.0,female,2009
269 | Gentoo,Biscoe,55.1,16.0,230.0,5850.0,male,2009
270 | Gentoo,Biscoe,44.5,15.7,217.0,4875.0,,2009
271 | Gentoo,Biscoe,48.8,16.2,222.0,6000.0,male,2009
272 | Gentoo,Biscoe,47.2,13.7,214.0,4925.0,female,2009
273 | Gentoo,Biscoe,,,,,,2009
274 | Gentoo,Biscoe,46.8,14.3,215.0,4850.0,female,2009
275 | Gentoo,Biscoe,50.4,15.7,222.0,5750.0,male,2009
276 | Gentoo,Biscoe,45.2,14.8,212.0,5200.0,female,2009
277 | Gentoo,Biscoe,49.9,16.1,213.0,5400.0,male,2009
278 | Chinstrap,Dream,46.5,17.9,192.0,3500.0,female,2007
279 | Chinstrap,Dream,50.0,19.5,196.0,3900.0,male,2007
280 | Chinstrap,Dream,51.3,19.2,193.0,3650.0,male,2007
281 | Chinstrap,Dream,45.4,18.7,188.0,3525.0,female,2007
282 | Chinstrap,Dream,52.7,19.8,197.0,3725.0,male,2007
283 | Chinstrap,Dream,45.2,17.8,198.0,3950.0,female,2007
284 | Chinstrap,Dream,46.1,18.2,178.0,3250.0,female,2007
285 | Chinstrap,Dream,51.3,18.2,197.0,3750.0,male,2007
286 | Chinstrap,Dream,46.0,18.9,195.0,4150.0,female,2007
287 | Chinstrap,Dream,51.3,19.9,198.0,3700.0,male,2007
288 | Chinstrap,Dream,46.6,17.8,193.0,3800.0,female,2007
289 | Chinstrap,Dream,51.7,20.3,194.0,3775.0,male,2007
290 | Chinstrap,Dream,47.0,17.3,185.0,3700.0,female,2007
291 | Chinstrap,Dream,52.0,18.1,201.0,4050.0,male,2007
292 | Chinstrap,Dream,45.9,17.1,190.0,3575.0,female,2007
293 | Chinstrap,Dream,50.5,19.6,201.0,4050.0,male,2007
294 | Chinstrap,Dream,50.3,20.0,197.0,3300.0,male,2007
295 | Chinstrap,Dream,58.0,17.8,181.0,3700.0,female,2007
296 | Chinstrap,Dream,46.4,18.6,190.0,3450.0,female,2007
297 | Chinstrap,Dream,49.2,18.2,195.0,4400.0,male,2007
298 | Chinstrap,Dream,42.4,17.3,181.0,3600.0,female,2007
299 | Chinstrap,Dream,48.5,17.5,191.0,3400.0,male,2007
300 | Chinstrap,Dream,43.2,16.6,187.0,2900.0,female,2007
301 | Chinstrap,Dream,50.6,19.4,193.0,3800.0,male,2007
302 | Chinstrap,Dream,46.7,17.9,195.0,3300.0,female,2007
303 | Chinstrap,Dream,52.0,19.0,197.0,4150.0,male,2007
304 | Chinstrap,Dream,50.5,18.4,200.0,3400.0,female,2008
305 | Chinstrap,Dream,49.5,19.0,200.0,3800.0,male,2008
306 | Chinstrap,Dream,46.4,17.8,191.0,3700.0,female,2008
307 | Chinstrap,Dream,52.8,20.0,205.0,4550.0,male,2008
308 | Chinstrap,Dream,40.9,16.6,187.0,3200.0,female,2008
309 | Chinstrap,Dream,54.2,20.8,201.0,4300.0,male,2008
310 | Chinstrap,Dream,42.5,16.7,187.0,3350.0,female,2008
311 | Chinstrap,Dream,51.0,18.8,203.0,4100.0,male,2008
312 | Chinstrap,Dream,49.7,18.6,195.0,3600.0,male,2008
313 | Chinstrap,Dream,47.5,16.8,199.0,3900.0,female,2008
314 | Chinstrap,Dream,47.6,18.3,195.0,3850.0,female,2008
315 | Chinstrap,Dream,52.0,20.7,210.0,4800.0,male,2008
316 | Chinstrap,Dream,46.9,16.6,192.0,2700.0,female,2008
317 | Chinstrap,Dream,53.5,19.9,205.0,4500.0,male,2008
318 | Chinstrap,Dream,49.0,19.5,210.0,3950.0,male,2008
319 | Chinstrap,Dream,46.2,17.5,187.0,3650.0,female,2008
320 | Chinstrap,Dream,50.9,19.1,196.0,3550.0,male,2008
321 | Chinstrap,Dream,45.5,17.0,196.0,3500.0,female,2008
322 | Chinstrap,Dream,50.9,17.9,196.0,3675.0,female,2009
323 | Chinstrap,Dream,50.8,18.5,201.0,4450.0,male,2009
324 | Chinstrap,Dream,50.1,17.9,190.0,3400.0,female,2009
325 | Chinstrap,Dream,49.0,19.6,212.0,4300.0,male,2009
326 | Chinstrap,Dream,51.5,18.7,187.0,3250.0,male,2009
327 | Chinstrap,Dream,49.8,17.3,198.0,3675.0,female,2009
328 | Chinstrap,Dream,48.1,16.4,199.0,3325.0,female,2009
329 | Chinstrap,Dream,51.4,19.0,201.0,3950.0,male,2009
330 | Chinstrap,Dream,45.7,17.3,193.0,3600.0,female,2009
331 | Chinstrap,Dream,50.7,19.7,203.0,4050.0,male,2009
332 | Chinstrap,Dream,42.5,17.3,187.0,3350.0,female,2009
333 | Chinstrap,Dream,52.2,18.8,197.0,3450.0,male,2009
334 | Chinstrap,Dream,45.2,16.6,191.0,3250.0,female,2009
335 | Chinstrap,Dream,49.3,19.9,203.0,4050.0,male,2009
336 | Chinstrap,Dream,50.2,18.8,202.0,3800.0,male,2009
337 | Chinstrap,Dream,45.6,19.4,194.0,3525.0,female,2009
338 | Chinstrap,Dream,51.9,19.5,206.0,3950.0,male,2009
339 | Chinstrap,Dream,46.8,16.5,189.0,3650.0,female,2009
340 | Chinstrap,Dream,45.7,17.0,195.0,3650.0,female,2009
341 | Chinstrap,Dream,55.8,19.8,207.0,4000.0,male,2009
342 | Chinstrap,Dream,43.5,18.1,202.0,3400.0,female,2009
343 | Chinstrap,Dream,49.6,18.2,193.0,3775.0,male,2009
344 | Chinstrap,Dream,50.8,19.0,210.0,4100.0,male,2009
345 | Chinstrap,Dream,50.2,18.7,198.0,3775.0,female,2009
346 |
--------------------------------------------------------------------------------
/Chapter08/penguin_ml/penguins_ml.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 |
3 | penguin_df = pd.read_csv('penguins.csv')
4 | penguin_df.dropna(inplace=True)
5 | output = penguin_df['species']
6 | features = penguin_df[['island', 'bill_length_mm', 'bill_depth_mm', 'flipper_length_mm', 'body_mass_g', 'sex']]
7 | features = pd.get_dummies(features)
8 | output, uniques = pd.factorize(output)
9 | print('Here is what our unique output variables represent')
10 | print(uniques)
11 | print('Here are our feature variables')
12 | print(features.head())
--------------------------------------------------------------------------------
/Chapter08/penguin_ml/penguins_streamlit.py:
--------------------------------------------------------------------------------
1 | import streamlit as st
2 | import seaborn as sns
3 | import matplotlib.pyplot as plt
4 | import pandas as pd
5 | import pickle
6 | from sklearn.metrics import accuracy_score
7 | from sklearn.ensemble import RandomForestClassifier
8 | from sklearn.model_selection import train_test_split
9 |
10 | st.title('Penguin Classifier')
11 |
12 | st.write("This app uses 6 inputs to predict the species of penguin using "
13 |
14 | "a model built on the Palmer's Penguin's dataset. Use the form below"
15 |
16 | " to get started!")
17 |
18 |
19 |
20 | password_guess = st.text_input('What is the Password?')
21 |
22 | if password_guess != 'streamlit_is_great':
23 | st.stop()
24 |
25 |
26 |
27 | penguin_file = st.file_uploader('Upload your own penguin data')
28 |
29 | if penguin_file is None:
30 |
31 | rf_pickle = open('random_forest_penguin.pickle', 'rb')
32 |
33 | map_pickle = open('output_penguin.pickle', 'rb')
34 |
35 | rfc = pickle.load(rf_pickle)
36 |
37 | unique_penguin_mapping = pickle.load(map_pickle)
38 |
39 | rf_pickle.close()
40 |
41 | map_pickle.close()
42 |
43 | else:
44 |
45 | penguin_df = pd.read_csv(penguin_file)
46 |
47 | penguin_df = penguin_df.dropna()
48 |
49 | output = penguin_df['species']
50 |
51 | features = penguin_df[['island', 'bill_length_mm', 'bill_depth_mm',
52 |
53 | 'flipper_length_mm', 'body_mass_g', 'sex']]
54 |
55 | features = pd.get_dummies(features)
56 |
57 | output, unique_penguin_mapping = pd.factorize(output)
58 |
59 |
60 |
61 | x_train, x_test, y_train, y_test = train_test_split(
62 |
63 | features, output, test_size=.8)
64 |
65 | rfc = RandomForestClassifier(random_state=15)
66 |
67 | rfc.fit(x_train, y_train)
68 |
69 | y_pred = rfc.predict(x_test)
70 |
71 | score = round(accuracy_score(y_pred, y_test), 2)
72 |
73 | st.write('We trained a Random Forest model on these data,'
74 | ' it has a score of {}! Use the '
75 | 'inputs below to try out the model.'.format(score))
76 |
77 | with st.form('user_inputs'):
78 | island = st.selectbox('Penguin Island', options=[
79 | 'Biscoe', 'Dream', 'Torgerson'])
80 | sex = st.selectbox('Sex', options=[
81 | 'Female', 'Male'])
82 | bill_length = st.number_input(
83 | 'Bill Length (mm)', min_value=0)
84 | bill_depth = st.number_input(
85 | 'Bill Depth (mm)', min_value=0)
86 | flipper_length = st.number_input(
87 | 'Flipper Length (mm)', min_value=0)
88 | body_mass = st.number_input(
89 | 'Body Mass (g)', min_value=0)
90 | st.form_submit_button()
91 |
92 |
93 |
94 | island_biscoe, island_dream, island_torgerson = 0, 0, 0
95 | if island == 'Biscoe':
96 | island_biscoe = 1
97 | elif island == 'Dream':
98 | island_dream = 1
99 | elif island == 'Torgerson':
100 | island_torgerson = 1
101 |
102 | sex_female, sex_male = 0, 0
103 |
104 | if sex == 'Female':
105 | sex_female = 1
106 |
107 | elif sex == 'Male':
108 | sex_male = 1
109 |
110 |
111 | new_prediction = rfc.predict([[bill_length, bill_depth, flipper_length,
112 | body_mass, island_biscoe, island_dream,
113 | island_torgerson, sex_female, sex_male]])
114 | prediction_species = unique_penguin_mapping[new_prediction][0]
115 | st.write('We predict your penguin is of the {} species'.format(prediction_species))
116 |
--------------------------------------------------------------------------------
/Chapter08/penguin_ml/random_forest_penguin.pickle:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Getting-started-with-Streamlit-for-Data-Science/50677d3f08c78f796b05cb1caf76246df3ff08ff/Chapter08/penguin_ml/random_forest_penguin.pickle
--------------------------------------------------------------------------------
/Chapter08/penguin_ml/requirements.txt:
--------------------------------------------------------------------------------
1 | pandas==1.0.5
2 | matplotlib==3.2.2
3 | seaborn==0.11.0
4 | streamlit==0.81.1
5 | scikit_learn==0.24.1
6 |
--------------------------------------------------------------------------------
/Chapter09/job_application_example/Screen Shot 2020-11-30 at 1.48.16 PM.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Getting-started-with-Streamlit-for-Data-Science/50677d3f08c78f796b05cb1caf76246df3ff08ff/Chapter09/job_application_example/Screen Shot 2020-11-30 at 1.48.16 PM.png
--------------------------------------------------------------------------------
/Chapter09/job_application_example/airport_location.csv:
--------------------------------------------------------------------------------
1 | Airport Code,Lat,Long
2 | CDG,49.0127983093,2.54999995232
3 | CHC,-43.4893989562988,172.531997680664
4 | DYR,64.7349014282227,177.740997314453
5 | EWR,40.6925010681152,-74.168701171875
6 | HNL,21.3187007904053,-157.921997070312
7 | OME,64.5121994018555,-165.445007324219
8 | ONU,-20.6499996185303,-178.699996948242
9 | PEK,40.0801010131836,116.584999084473
10 |
--------------------------------------------------------------------------------
/Chapter09/job_application_example/haversine.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Getting-started-with-Streamlit-for-Data-Science/50677d3f08c78f796b05cb1caf76246df3ff08ff/Chapter09/job_application_example/haversine.png
--------------------------------------------------------------------------------
/Chapter09/job_application_example/job_problems.md:
--------------------------------------------------------------------------------
1 | ## Question 1: Airport Distance
2 |
3 | The first exercise asks us 'Given the included dataset of airports and locations (in latitude and longitude), write a function that takes an airport code as input and returns the airports listed from nearest to furthest from the input airport.
4 |
5 |
6 | ## Question 2 - Representation
7 |
8 | Note: Don’t worry about writing code in this section, you can just describe any transformations of the data you would perform. Your description should be clear enough that a data scientist reading this would know how to implement your solution if necessary. Here is an example of a single user’s searches in our app:
9 |
10 | How would you transform this collection of searches into a numeric vector representing a trip? Assume that we have hundreds of thousands of users and we want to represent all of their trips this way. We ideally want this to be a general representation we could use in multiple different modeling projects, but we definitely care about finding similar trips.
11 | How, precisely, would you compare two trips to see how similar they are?
12 | What information do you feel might be missing from data above that would be helpful in improving your representation?
--------------------------------------------------------------------------------
/Chapter09/job_application_example/job_streamlit.py:
--------------------------------------------------------------------------------
1 | import streamlit as st
2 | from streamlit_lottie import st_lottie
3 | import pandas as pd
4 | import requests
5 |
6 | password_attempt = st.text_input('Please Enter The Password')
7 | if password_attempt != 'example_password':
8 | st.write('Incorrect Password!')
9 | st.stop()
10 |
11 | def load_lottieurl(url: str):
12 | r = requests.get(url)
13 | if r.status_code != 200:
14 | return None
15 | return r.json()
16 |
17 | lottie_airplane = load_lottieurl('https://assets4.lottiefiles.com/packages/lf20_jhu1lqdz.json')
18 | st_lottie(lottie_airplane, speed=1, height=200, key="initial")
19 |
20 | st.title('Major US Airline Job Application')
21 | st.write('by Tyler Richards')
22 | st.subheader('Question 1: Airport Distance')
23 | '''
24 | The first exercise asks us 'Given the table of airports and
25 | locations (in latitude and longitude) below,
26 | write a function that takes an airport code as input and
27 | returns the airports listed from nearest to furthest from
28 | the input airport.' There are three steps here:
29 |
30 | 1. Load Data
31 | 2. Implement Distance Algorithm
32 | 3. Apply distance formula across all airports other than the input
33 | 4. Return sorted list of airports Distance
34 | '''
35 |
36 | airport_distance_df = pd.read_csv('airport_location.csv')
37 |
38 | with st.echo():
39 | #load necessary data
40 | airport_distance_df = pd.read_csv('airport_location.csv')
41 |
42 | '''
43 | From some quick googling, I found that the haversine distance is
44 | a good approximation for distance. At least good enough to get the
45 | distance between airports! Haversine distances can be off by up to .5%,
46 | because the earth is not actually a sphere. It looks like the latitudes
47 | and longitudes are in degrees, so I'll make sure to have a way to account
48 | for that as well. The haversine distance formula is labeled below,
49 | followed by an implementation in python
50 | '''
51 | st.image('haversine.png')
52 |
53 |
54 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Packt
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Getting Started with Streamlit for Data Science
2 |
3 |
4 |
5 | This is the code repository for [Getting Started with Streamlit for Data Science](https://www.packtpub.com/product/getting-started-with-streamlit-for-data-science/9781800565500?utm_source=github&utm_medium=repository&utm_campaign=978-1-80056-550-0), published by Packt.
6 |
7 | **Create and deploy Streamlit web applications from scratch in Python**
8 |
9 | This book's repository has moved to: https://github.com/tylerjrichards/Getting-Started-with-Streamlit-for-Data-Science
10 |
11 |
12 | ## What is this book about?
13 | Streamlit shortens the development time for the creation of data-focused web applications, allowing data scientists to create web app prototypes using Python in hours instead of days. Getting Started with Streamlit for Data Science takes a hands-on approach to helping you learn the tips and tricks that will have you up and running with Streamlit in no time.
14 |
15 | This book covers the following exciting features:
16 | * Set up your first development environment and create a basic Streamlit app from scratch
17 | * Explore methods for uploading, downloading, and manipulating data in Streamlit apps
18 | * Create dynamic visualizations in Streamlit using built-in and imported Python libraries
19 | * Discover strategies for creating and deploying machine learning models in Streamlit
20 | * Use Streamlit sharing for one-click deployment
21 |
22 | If you feel this book is for you, get your [copy](https://www.amazon.com/dp/B095Z1R3BP) today!
23 |
24 |
26 |
27 |
28 | ## Instructions and Navigations
29 | All of the code is organized into folders.
30 |
31 | The code will look like the following:
32 | ```
33 | import pandas as pd
34 | penguin_df = pd.read_csv('penguins.csv')
35 | print(penguin_df.head())
36 | ```
37 |
38 | **Following is what you need for this book:**
39 | This book is for data scientists and machine learning enthusiasts who want to create web apps using Streamlit. Whether you’re a junior data scientist looking to deploy your first machine learning project in Python to improve your resume or a senior data scientist who wants to use Streamlit to make convincing and dynamic data analyses, this book will help you get there! Prior knowledge of Python programming will assist with understanding the concepts covered. .
40 |
41 | With the following software and hardware list you can run all code files present in the book (Chapter 1-11).
42 |
43 | ### Software and Hardware List
44 |
45 | | Chapter | Software required | OS required |
46 | | -------- | ------------------------------------| -----------------------------------|
47 | | 1 - 11 | Python 3+ | Windows, Mac OS X, and Linux (Any) |
48 | | 1 - 11 | Streamlit 0.81+ | Windows, Mac OS X, and Linux (Any) |
49 | | 1 - 11 | GitHub | Windows, Mac OS X, and Linux (Any) |
50 |
51 |
52 |
53 | We also provide a PDF file that has color images of the screenshots/diagrams used in this book. [Click here to download it](https://static.packt-cdn.com/downloads/9781800565500_ColorImages.pdf).
54 |
55 |
56 | ### Related products
57 | * Interactive Dashboards and Data Apps with Plotly and Dash [[Packt]](https://www.packtpub.com/https://www.packtpub.com/product/interactive-dashboards-and-data-apps-with-plotly-and-dash/9781800568914?utm_source=github&utm_medium=repository&utm_campaign=9781800568914product/interactive-dashboards-and-data-apps-with-plotly-and-dash/9781800568914?utm_source=github&utm_medium=repository&utm_campaign=978-1-80056-891-4) [[Amazon]](https://www.amazon.com/dp/1800568916)
58 |
59 | * Tableau Prep Cookbook [[Packt]](https://www.packtpub.com/product/tableau-prep-cookbook/9781800563766?utm_source=github&utm_medium=repository&utm_campaign=9781800563766) [[Amazon]](https://www.amazon.com/dp/1800563760)
60 |
61 | ## Get to Know the Author
62 | **Tyler Richards**
63 | is a data scientist at Facebook, working on community integrity. Before this gig, his focus was on helping bolster the state of US elections for the nonprofit Protect Democracy. He is a data scientist and industrial engineer by training, which he gets to make use of in fun ways such as applying machine learning to local campus elections, creating algorithms to help P&G target Tide Pod users, and finding ways to determine the best ping pong players in friend groups. He is always looking for a new project, a new adventure.
64 |
65 |
66 |
--------------------------------------------------------------------------------