Update src/streamlit_app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940import altair as altimport numpy as npimport pandas as pdimport streamlit as st"""# Welcome to Streamlit!Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [communityforums](https://discuss.streamlit.io).In the meantime, below is an example of what you can do with just a few lines of code:"""num_points = st.slider("Number of points in spiral", 1, 10000, 1100)num_turns = st.slider("Number of turns in spiral", 1, 300, 31)indices = np.linspace(0, 1, num_points)theta = 2 * np.pi * num_turns * indicesradius = indicesx = radius * np.cos(theta)y = radius * np.sin(theta)df = pd.DataFrame({"x": x,"y": y,"idx": indices,"rand": np.random.randn(num_points),})st.altair_chart(alt.Chart(df, height=700, width=700).mark_point(filled=True).encode(x=alt.X("x", axis=None),y=alt.Y("y", axis=None),color=alt.Color("idx", legend=None, scale=alt.Scale()),size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),))123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687import streamlit as stimport pandas as pdst.title("Анализ скидок WB")uploaded_file = st.file_uploader("Загрузите Excel-файл",type=["xlsx", "xls"])if uploaded_file is not None:# =========================# Чтение Excel# =========================df = pd.read_excel(uploaded_file,sheet_name='Финансовый отчёт')# =========================# Подготовка данных# =========================df['Дата и время продажи'] = pd.to_datetime(df['Дата и время продажи'],errors='coerce')df['Цена розничная'] = pd.to_numeric(df['Цена розничная'],errors='coerce')df['Wildberries реализовал товар'] = pd.to_numeric(df['Wildberries реализовал товар'],errors='coerce')df = df.dropna(subset=['Дата и время продажи','Цена розничная','Wildberries реализовал товар'])df = df[(df['Цена розничная'] > 0) &(df['Wildberries реализовал товар'] > 0)]# =========================# Расчёт скидки# =========================df['Скидка %'] = ((df['Цена розничная']- df['Wildberries реализовал товар'])/ df['Цена розничная']* 100).round(2)df['Дата'] = (df['Дата и время продажи'].dt.date)daily_discount = (df.groupby('Дата').agg(Средняя_скидка=('Скидка %', 'mean'),Количество_заказов=('Скидка %', 'count')).round(2).reset_index())st.subheader("Средняя скидка по дням")st.dataframe(daily_discount,use_container_width=True)
src/streamlit_app.py+85-38