Spaces:
Runtime error
Runtime error
Hoang Dinh
commited on
Commit
•
7fa38ab
1
Parent(s):
0811370
Add Application File
Browse files- app.py +34 -0
- config.py +1 -0
- group_by.py +16 -0
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from group_by import group_by_keyword
|
3 |
+
|
4 |
+
df_xang_jupiter = group_by_keyword("Xăng jupiter", 'Must Have')
|
5 |
+
st.write("Xăng jupiter")
|
6 |
+
st.bar_chart(df_xang_jupiter.set_index('Time'))
|
7 |
+
|
8 |
+
df_xang_lead = group_by_keyword("Xăng lead", 'Must Have')
|
9 |
+
st.write("Xăng lead")
|
10 |
+
st.bar_chart(df_xang_lead.set_index('Time'))
|
11 |
+
|
12 |
+
df_vi_tam = group_by_keyword("Vì tâm", 'Nice To Have')
|
13 |
+
st.write("Vì tâm")
|
14 |
+
st.bar_chart(df_vi_tam.set_index('Time'))
|
15 |
+
|
16 |
+
df_dua = group_by_keyword("Dừa", 'Nice To Have')
|
17 |
+
st.write("Dừa")
|
18 |
+
st.bar_chart(df_dua.set_index('Time'))
|
19 |
+
|
20 |
+
df_ve_so = group_by_keyword("Vé số", 'Nice To Have')
|
21 |
+
st.write("Vé số")
|
22 |
+
st.bar_chart(df_ve_so.set_index('Time'))
|
23 |
+
|
24 |
+
df_bivina = group_by_keyword("Bivina", 'Nice To Have')
|
25 |
+
st.write("Bivina")
|
26 |
+
st.bar_chart(df_bivina.set_index('Time'))
|
27 |
+
|
28 |
+
df_lotter = group_by_keyword("Lotte", 'Nice To Have')
|
29 |
+
st.write("Lotte")
|
30 |
+
st.bar_chart(df_lotter.set_index('Time'))
|
31 |
+
|
32 |
+
df_winmart = group_by_keyword("Winmart", 'Nice To Have')
|
33 |
+
st.write("Winmart")
|
34 |
+
st.bar_chart(df_winmart.set_index('Time'))
|
config.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
SPREADSHEET_URL = 'https://docs.google.com/spreadsheets/d/1YAEnVA0NlZJXOVPpAZC8EjlUUpm95uJ1wNRi29lhu2I/export?format=csv&gid=0'
|
group_by.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import config
|
3 |
+
|
4 |
+
def group_by_keyword(keyword, column_type):
|
5 |
+
df = pd.read_csv(config.SPREADSHEET_URL, usecols=[0,1,2,3,4], header=3)
|
6 |
+
df['Time'] = pd.to_datetime(df['Time'], format='%B %d %Y')
|
7 |
+
df_keyword = df[df['Items'].str.contains(keyword)]
|
8 |
+
df_keyword[column_type] = df_keyword[column_type].astype(int)
|
9 |
+
df_groupby = (df_keyword
|
10 |
+
.groupby(df_keyword['Time'].dt.strftime('%Y-%m'))
|
11 |
+
.agg(total = (column_type, 'sum')))
|
12 |
+
|
13 |
+
new_df = df_groupby.reset_index()
|
14 |
+
new_df['Time'] = pd.to_datetime(new_df['Time'], format='%Y-%m').dt.strftime('%Y-%m')
|
15 |
+
new_df.sort_values(by='Time')
|
16 |
+
return new_df
|