Causion / src /basic_plot.py
tappyness1
added in heatmap charts
6f8fd55
raw
history blame
1.05 kB
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