forked from adsoftsito/streamlit-m5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnyc.py
38 lines (28 loc) · 1.07 KB
/
nyc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import streamlit as st
import pandas as pd
import numpy as np
st.title('Cicle Rides in NYC')
DATE_COLUMN = 'started_at'
DATA_URL = ('citibike-tripdata.csv')
@st.cache
def load_data(nrows):
data = pd.read_csv(DATA_URL, nrows=nrows)
lowercase = lambda x: str(x).lower()
data.rename({'start_lat': 'lat', 'start_lng': 'lon'}, axis=1, inplace=True)
data[DATE_COLUMN] = pd.to_datetime(data[DATE_COLUMN])
return data
data_load_state = st.text('Loading cicle nyc data...')
data = load_data(1000)
data_load_state.text("Done! (using st.cache)")
if st.sidebar.checkbox('Show raw data'):
st.subheader('Raw data')
st.write(data)
if st.sidebar.checkbox('Recorridos por hora'):
st.subheader('Numero de recorridos por hora')
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)