forked from CarrieZijing/Project_8_Group_6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUber_Pickups.py
95 lines (75 loc) · 2.47 KB
/
Uber_Pickups.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
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 6 22:27:08 2022
@author: Mtime
"""
import streamlit as st
import pandas as pd
import numpy as np
import altair as alt
import pydeck as pdk
import datetime
from streamlit_folium import folium_static
import folium
# st.set_page_config(layout="wide")
# load data
DATE_COLUMN = "date/time"
DATA_URL = (
"https://s3-us-west-2.amazonaws.com/"
"streamlit-demo-data/uber-raw-data-sep14.csv.gz"
)
# prepare the sidebar options
daysofweek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
hours = [i for i in range(0, 24)]
@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
# Create a text element and let the reader know the data is loading.
data_load_state = st.text("Loading data...")
# Load 10,000 rows of data into the dataframe.
data = load_data(10000)
# Notify the reader that the data was successfully loaded.
data_load_state.text("Done! (using st.cache)")
# Maps function (overwrite)
def map_1(data, lat, lon, zoom):
st.write(
pdk.Deck(
map_style="mapbox://styles/mapbox/light-v9",
initial_view_state={
"latitude": lat,
"longitude": lon,
"zoom": zoom,
"pitch": 50,
},
layers=[
pdk.Layer(
"HexagonLayer",
data=data,
get_position=["lon", "lat"],
radius=10,
elevation_scale=4,
elevation_range=[0, 1000],
pickable=True,
extruded=True,
),
],
)
)
if st.checkbox("Show raw data"):
st.subheader("Raw data")
st.write(data)
# histogram of pickups per hour
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) # supports other libraries as well
# map - all pickups
st.subheader("Map of all pickups")
st.map(data)
# map - all pickups with density
st.subheader("Map of density of all pickups")
midpoint = (np.average(data["lat"]), np.average(data["lon"]))
map_1(data, midpoint[0], midpoint[1], 11)