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
def fetch_data():
# This function would ideally fetch data from a database or API
# For demonstration, we will use synthetic data
data = {
'order_id': range(1, 101),
'customer_name': [f'Customer {i}' for i in range(1, 101)],
'order_amount': [round(random.uniform(10, 500), 2) for _ in range(100)],
'order_date': pd.date_range(start='2023-01-01', periods=100)
}
return pd.DataFrame(data)
st.title('E-commerce Orders Visualizer')
# Fetching data
orders_df = fetch_data()
# Display the table
st.subheader('Orders Data')
st.table(orders_df)
# Visualization
st.subheader('Orders Amount Over Time')
chart = alt.Chart(orders_df).mark_line().encode(
x='order_date:T',
y='sum(order_amount):Q'
).properties(
title='Total Order Amount Over Time'
)
st.altair_chart(chart, use_container_width=True)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?