Recently, I came across an open source framework — Streamlit which is used to create data apps. So I spent some time on the documentation and did some data visualization on a Food Demand Forecasting Dataset.
Streamlit’s open-source app framework is the easiest way for data scientists and machine learning engineers to create beautiful, performant apps in only a few hours! All in pure Python. All for free.
To get started just type this command:
pip install streamlit
To check whether it was installed properly run the below command:
streamlit hello
If this appears on your browser, then streamlit is installed and working properly!
Now we will plot some simple charts using the dataset provided in the link above.
Importing the necessary libraries first and give a title.
import streamlit as st
import pandas as pd
import numpy as np
import plotly.figure_factory as ff
import matplotlib.pyplot as plt
st.title(‘Food Demand Forecasting — Analytics Vidhya’)
In the dataset you will see 3 csv files and we will import that now using pandas. @st.cache is quite important here for smooth and fast functioning. Read about it in detail here.
@st.cache
def load_data(nrows):
data = pd.read_csv('train.csv', nrows=nrows)
return data
@st.cache
def load_center_data(nrows):
data = pd.read_csv('fulfilment_center_info.csv',nrows=nrows)
return data
@st.cache
def load_meal_data(nrows):
data = pd.read_csv('meal_info.csv',nrows=nrows)
return data
Let’s call these functions now. I am right now taking only 1000 rows you can take your entire dataset.
data_load_state = st.text('Loading data...')
weekly_data = load_data(1000)
center_info_data = load_center_data(1000)
meal_data = load_meal_data(1000)
First we will look at the Weekly Demand Data. We will be plotting bar chart, histograms, line chart and area chart.
Bar Chart
st.subheader(‘Weekly Demand Data’)
st.write(weekly_data)
#Bar Chart
st.bar_chart(weekly_data[‘num_orders’])
#python #streamlit #analytics #data-visualization #data-analysis