File size: 1,049 Bytes
471f224
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6f8fd55
471f224
 
6f8fd55
471f224
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd
import plotly.express as px
from datasets import load_dataset
import os

    
def basic_chart(counts_df):
    # data processing
    counts_df['traffic'] = counts_df['car'] + counts_df['motorcycle'] + counts_df['large_vehicle']
    counts_df['datetime'] = pd.to_datetime(counts_df['date'] + ' ' + counts_df['time'])
    counts_df['weekday'] = counts_df['datetime'].dt.strftime('%A')
    counts_df['hour'] = counts_df['datetime'].dt.strftime('%H')
    
    # plot types
    plot = st.selectbox('Choose Plot', options=['Day','Hour','Raw'])
    
    # view types
    view = st.selectbox('Choose View', options=counts_df['view'].unique())
    filtered_views = counts_df[counts_df['view'] == view]
    
    # conditional views
    if plot == 'Day':    
        fig = px.bar(filtered_views, x='weekday', y='traffic')
    elif plot == 'Hour':
        fig = px.bar(filtered_views, x='hour', y='traffic')
    elif plot == 'Raw':
        fig = px.bar(filtered_views, x='datetime', y='traffic')
        
    return fig