Create an app to visualize e-commerce orders
To upload files, please first save the app
import streamlit as st
import pandas as pd
import altair as alt
@st.cache_data
def fetch_orders():
# Sample data for e-commerce orders
data = {
'Order ID': [1, 2, 3, 4, 5],
'Product': ['Widget A', 'Widget B', 'Widget C', 'Widget D', 'Widget E'],
'Quantity': [4, 2, 5, 3, 1],
'Price': [20.00, 15.00, 30.00, 25.00, 10.00],
'Order Date': [
'2023-01-01', '2023-01-02', '2023-01-03', '2023-01-04', '2023-01-05'
]
}
return pd.DataFrame(data)
st.title('E-commerce Orders Visualization')
# Fetch orders data
orders_df = fetch_orders()
# Create a chart to visualize total sales
orders_df['Total Sales'] = orders_df['Quantity'] * orders_df['Price']
chart = alt.Chart(orders_df).mark_bar().encode(
x='Product:N',
y='sum(Total Sales):Q',
tooltip=['Product', 'sum(Total Sales):Q']
).properties(
title='Total Sales by Product'
)
st.altair_chart(chart, use_container_width=True)
# Show the raw data
st.subheader('Raw Orders Data')
st.write(orders_df)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?