mirror of
https://github.com/bluxmit/alnoda-workspaces.git
synced 2024-06-29 11:40:21 +12:00
49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
import streamlit as st
|
|
import pandas as pd
|
|
import numpy as np
|
|
|
|
# Using object notation
|
|
add_selectbox = st.sidebar.selectbox(
|
|
"How would you like to be contacted?",
|
|
("Email", "Home phone", "Mobile phone")
|
|
)
|
|
|
|
# Using "with" notation
|
|
with st.sidebar:
|
|
add_radio = st.radio(
|
|
"Choose a shipping method",
|
|
("Standard (5-15 days)", "Express (2-5 days)")
|
|
)
|
|
|
|
st.title('Uber pickups in NYC')
|
|
|
|
DATE_COLUMN = 'date/time'
|
|
DATA_URL = ('https://s3-us-west-2.amazonaws.com/'
|
|
'streamlit-demo-data/uber-raw-data-sep14.csv.gz')
|
|
|
|
@st.cache
|
|
def load_data(nrows):
|
|
data = pd.read_csv(DATA_URL, nrows=nrows)
|
|
lowercase = lambda x: str(x).lower()
|
|
data.rename(lowercase, axis='columns', inplace=True)
|
|
data[DATE_COLUMN] = pd.to_datetime(data[DATE_COLUMN])
|
|
return data
|
|
|
|
data_load_state = st.text('Loading data...')
|
|
data = load_data(10000)
|
|
data_load_state.text("Done! (using st.cache)")
|
|
|
|
if st.checkbox('Show raw data'):
|
|
st.subheader('Raw data')
|
|
st.write(data)
|
|
|
|
st.subheader('Number of pickups by hour')
|
|
hist_values = np.histogram(data[DATE_COLUMN].dt.hour, bins=24, range=(0,24))[0]
|
|
st.bar_chart(hist_values)
|
|
|
|
# Some number in the range 0-23
|
|
hour_to_filter = st.slider('hour', 0, 23, 17)
|
|
filtered_data = data[data[DATE_COLUMN].dt.hour == hour_to_filter]
|
|
|
|
st.subheader('Map of all pickups at %s:00' % hour_to_filter)
|
|
st.map(filtered_data) |