File size: 1,487 Bytes
531597e 9757169 aed86da 2695dfd aed86da 531597e aed86da 9757169 2695dfd 9757169 531597e 9757169 531597e ba63584 aed86da 9757169 aed86da 9757169 aed86da 9757169 aed86da 9757169 aed86da 9757169 aed86da 9757169 f578c56 aa1a2e9 531597e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | import os
from pathlib import Path
import numpy as np
import pandas as pd
import streamlit as st
from athai.data_utils import cached_download_csv
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"
)
DATA_PATH = Path(os.environ.get("APP_DATA"))
@st.cache_resource
def load_data(nrows):
data = cached_download_csv(DATA_PATH, DATA_URL, nrows=nrows)
def lowercase(x):
return 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)
uploaded_file = st.file_uploader("Choose a file")
if uploaded_file is not None:
st.write(uploaded_file.name)
bytes_data = uploaded_file.getvalue()
st.write(len(bytes_data), "bytes")
st.markdown("")
|