forked from streamlit/demo-self-driving
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhist.py
85 lines (75 loc) · 2.44 KB
/
hist.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
#plotly distribution plot
import seaborn as sns
import matplotlib.pyplot as plt
import streamlit as st
import plotly.figure_factory as ff
import numpy as np
import pandas as pd
def main():
# Add histogram data
df = pd.read_csv("https://raw.githubusercontent.com/tyrin/info-topo-dash/master/data/freshdata.csv")
#define variables that the customer will input
sitelist= df['Portal'].unique()
site = np.sort(sitelist)
domain=""
portal=""
portal = st.sidebar.multiselect(
'Portal:', site)
message = st.empty()
if len(portal) == 0:
message.text("Select a portal")
if (len(portal) > 0) and (len(domain) == 0):
message = st.empty()
#df[df['country'] == country]
dff = df.loc[df['Portal'].isin(portal)]
dfs = dff.sort_values(by='Group')
group = dfs['Group'].unique()
domain = st.sidebar.multiselect('Content Domain:', group)
dfff = df.loc[df['Portal'].isin(portal)]
fd = dfff.filter(items=['Date', 'Node'])
#fd['Date'] = fd['Date'].astype('datetime64[ns]')
fd['Date'] = fd['Date'].astype('datetime64')
if (len(portal) > 0) and (len(domain) > 0):
#message.text("Filter by date")
dfff = df.loc[(df['Portal'].isin(portal)) & (df['Group'].isin(domain))]
fd = dfff.filter(items=['Date', 'Node'])
fd['Date'] = fd['Date'].astype('datetime64')
#Using the below causes an error in the streamlit dataframe call even though it should format the dates better, so I have to use the above.
#fd['Date']= pd.to_datetime(df['Date'])
fig, ax = plt.subplots(figsize=(7,3))
fd["Date"].astype(np.int64).plot.hist(ax=ax)
#Creating side bar so it reflect current data
#min_value = fd.index.min()
#start_time = st.sidebar.slider(
# "When do you start?",
# value=fd.index.min(),
# format="MM/DD/YY - hh:mm")
#st.sidebar.write("Start time:", fd.index.min())
labels = ax.get_xticks().tolist()
ax.set_ylabel('# of Files')
labels = pd.to_datetime(labels)
ax.set_xticklabels(labels, rotation=90)
#ax.legend()
st.pyplot(fig, use_container_width=True)
st.dataframe(fd)
@st.cache
def convert_df(fd):
return dff.to_csv().encode('utf-8')
if len(portal) != 0:
csv = convert_df(fd)
st.download_button(
"Press to Download",
csv,
"freshness.csv",
"text/csv",
key='download-csv'
)
#---------
# Data type conversions
# my data is datetime64[ns, tzlocal()]
#df['created_at'] = df['created_at'].astype('datetime64[ns]')
#df['user_type'] = df['user_type'].astype('category')
#
## Show new data types
#df.dtypes
#--------