Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,36 @@
|
|
1 |
-
"""
|
2 |
-
# My first app
|
3 |
-
Here's our first attempt at using data to create a table:
|
4 |
-
"""
|
5 |
-
|
6 |
import streamlit as st
|
7 |
import pandas as pd
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
st.title('Uber pickups in NYC')
|
6 |
+
|
7 |
+
DATE_COLUMN = 'date/time'
|
8 |
+
DATA_URL = ('https://s3-us-west-2.amazonaws.com/'
|
9 |
+
'streamlit-demo-data/uber-raw-data-sep14.csv.gz')
|
10 |
+
|
11 |
+
@st.cache_data
|
12 |
+
def load_data(nrows):
|
13 |
+
data = pd.read_csv(DATA_URL, nrows=nrows)
|
14 |
+
lowercase = lambda x: str(x).lower()
|
15 |
+
data.rename(lowercase, axis='columns', inplace=True)
|
16 |
+
data[DATE_COLUMN] = pd.to_datetime(data[DATE_COLUMN])
|
17 |
+
return data
|
18 |
+
|
19 |
+
data_load_state = st.text('Loading data...')
|
20 |
+
data = load_data(10000)
|
21 |
+
data_load_state.text("Done! (using st.cache_data)")
|
22 |
+
|
23 |
+
if st.checkbox('Show raw data'):
|
24 |
+
st.subheader('Raw data')
|
25 |
+
st.write(data)
|
26 |
+
|
27 |
+
st.subheader('Number of pickups by hour')
|
28 |
+
hist_values = np.histogram(data[DATE_COLUMN].dt.hour, bins=24, range=(0,24))[0]
|
29 |
+
st.bar_chart(hist_values)
|
30 |
+
|
31 |
+
# Some number in the range 0-23
|
32 |
+
hour_to_filter = st.slider('hour', 0, 23, 17)
|
33 |
+
filtered_data = data[data[DATE_COLUMN].dt.hour == hour_to_filter]
|
34 |
|
35 |
+
st.subheader('Map of all pickups at %s:00' % hour_to_filter)
|
36 |
+
st.map(filtered_data)
|