|
import streamlit as st |
|
import pandas as pd |
|
import os |
|
import base64 |
|
from pathlib import Path |
|
|
|
path = os.path.dirname(__file__) |
|
file_ = open(f"{path}/logo.png", "rb") |
|
contents = file_.read() |
|
data_url = base64.b64encode(contents).decode("utf-8") |
|
file_.close() |
|
|
|
def load_local_css(file_name): |
|
with open(file_name) as f: |
|
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True) |
|
|
|
def set_header(): |
|
return st.markdown( |
|
f"""<div class='main-header'> |
|
<h1>Synthetic Control</h1> |
|
<img src="data:image;base64,{data_url}", alt="Logo"> |
|
</div>""", |
|
unsafe_allow_html=True, |
|
) |
|
|
|
|
|
st.set_page_config(layout="wide") |
|
load_local_css("styles.css") |
|
set_header() |
|
|
|
st.title("Input data") |
|
|
|
data_file = st.file_uploader( |
|
label="Choose a file", |
|
accept_multiple_files=False, |
|
key="user_upload_file", |
|
type=["csv", "xlsx"] |
|
) |
|
|
|
info_placeholder = st.empty() |
|
|
|
if data_file: |
|
|
|
dtype={'individual_id_ov':'str', |
|
'past_3month_GMV_GMA':'float64', |
|
'past_3month_qty_GMA':'int64', |
|
'past_3month_orders_GMA':'int64', |
|
'past_6month_GMV_GMA':'float64', |
|
'past_6month_qty_GMA':'int64', |
|
'past_6month_orders_GMA':'int64', |
|
'past_9month_GMV_GMA':'float64', |
|
'past_9month_qty_GMA':'int64', |
|
'past_9month_orders_GMA':'int64', |
|
'past_12month_GMV_GMA':'float64', |
|
'past_12month_qty_GMA':'int64', |
|
'past_12month_orders_GMA':'int64', |
|
'avg_order_gap_between_GMA_purchases':'float64', |
|
'days_since_last_GMA_purchase':'float64', |
|
'age':'float64', |
|
'gender':'str', |
|
'income_group':'str', |
|
'age_group':'str', |
|
'urbanicity':'str', |
|
'ethnicity':'str', |
|
'Kids':'str', |
|
'hh_size_excl_child':'str', |
|
'hh_adult_qty':'float64', |
|
'hh_scs_est_per1000_income_amt':'float64', |
|
'avg_order_gap_between_WMT_purchases':'float64', |
|
'days_since_last_WMT_purchase':'float64', |
|
'Y':'int64'} |
|
df = pd.read_excel(data_file, sheet_name='sheet1', dtype=dtype,engine='openpyxl') |
|
st.session_state.df = df |
|
st.write(df.head()) |
|
with info_placeholder: |
|
st.success("File upload successful") |
|
|
|
plot_df=pd.read_excel(data_file, sheet_name='sheet2') |
|
st.session_state.plot_df = plot_df |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|