-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
46 lines (35 loc) · 1.37 KB
/
test.py
File metadata and controls
46 lines (35 loc) · 1.37 KB
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
import streamlit as st
import pandas as pd
import numpy as np
import altair as alt
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')
# 데이터 불러오기
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...')
# 10000개의 행의 데이터를 로드한다.
data = load_data(10000)
# 데이터가 성공적으로 로드 되었음을 알린다.
data_load_state.text('Loading data...done!')
# 부제목 만들기
st.subheader('Raw data')
st.write(data)
# Hour 별 픽업 수 계산
data['hour'] = data[DATE_COLUMN].dt.hour
hist_values = np.histogram(data['hour'], bins=24, range=(0,24))[0]
# Altair를 사용하여 히스토그램 그리기
st.subheader('Number of pickups by hour')
chart_data = pd.DataFrame({'hour': range(24), 'pickups': hist_values})
chart = alt.Chart(chart_data).mark_bar().encode(
x=alt.X('hour', title='Hour of day'),
y=alt.Y('pickups', title='Number of pickups')
)
st.altair_chart(chart, use_container_width=True)