Spaces:
Sleeping
Sleeping
Commit
·
c7e0507
1
Parent(s):
598c992
Show investing in a chart
Browse files- page_investing.py +26 -9
- page_shopping.py +5 -5
page_investing.py
CHANGED
@@ -1,20 +1,37 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
-
|
|
|
|
|
4 |
|
5 |
@st.cache_data
|
6 |
def show(df):
|
|
|
|
|
7 |
st.title("Investing")
|
8 |
-
show_investment_count(df)
|
9 |
|
10 |
|
11 |
-
def show_investment_count(df):
|
12 |
# Count the number of people who have invested and who have not
|
13 |
-
investment_count = df[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
#
|
16 |
-
|
17 |
-
{'Do you have any investment currently?': investment_count.index, 'Count': investment_count.values})
|
18 |
|
19 |
-
# Display the DataFrame as a table in Streamlit
|
20 |
-
st.table(investment_table)
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
+
from matplotlib.font_manager import FontProperties
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
import seaborn as sns
|
6 |
|
7 |
@st.cache_data
|
8 |
def show(df):
|
9 |
+
# Load the Chinese font
|
10 |
+
chinese_font = FontProperties(fname='mingliu.ttf', size=12)
|
11 |
st.title("Investing")
|
12 |
+
show_investment_count(df, font_prop=chinese_font)
|
13 |
|
14 |
|
15 |
+
def show_investment_count(df, font_prop):
|
16 |
# Count the number of people who have invested and who have not
|
17 |
+
investment_count = df["你/妳覺得目前有任何投資嗎?"].value_counts().reset_index()
|
18 |
+
investment_count.columns = ['Investment', 'Count']
|
19 |
+
|
20 |
+
# Create a bar chart using seaborn
|
21 |
+
plt.figure(figsize=(10, 6))
|
22 |
+
barplot = sns.barplot(x='Investment', y='Count', data=investment_count, palette='viridis')
|
23 |
+
ax = plt.gca() # Get the current Axes instance on the current figure matching the given keyword args, or create one.
|
24 |
+
ax.set_xticklabels(ax.get_xticklabels(), fontproperties=font_prop)
|
25 |
+
|
26 |
+
# Add labels and title
|
27 |
+
plt.xlabel('Do you currently have any investment?', fontsize=12, fontproperties=font_prop)
|
28 |
+
plt.ylabel('Count', fontsize=12, fontproperties=font_prop)
|
29 |
+
plt.title("Number of People Who Have/Haven't Invested", fontsize=16, fontproperties=font_prop)
|
30 |
+
|
31 |
+
# Display values on the bars
|
32 |
+
for index, value in enumerate(investment_count['Count']):
|
33 |
+
plt.text(index, value, str(value), ha='center', va='bottom', fontproperties=font_prop)
|
34 |
|
35 |
+
# Display the chart in Streamlit
|
36 |
+
st.pyplot(plt)
|
|
|
37 |
|
|
|
|
page_shopping.py
CHANGED
@@ -8,7 +8,7 @@ import numpy as np
|
|
8 |
from fields.prod_feat_flat_fields import prod_feat_flat_fields
|
9 |
from fields.feature_translations import feature_translations
|
10 |
|
11 |
-
|
12 |
def show(df):
|
13 |
# Load the Chinese font
|
14 |
chinese_font = FontProperties(fname='mingliu.ttf', size=12)
|
@@ -24,12 +24,12 @@ def show(df):
|
|
24 |
|
25 |
def show_boycott_count(df, font_prop):
|
26 |
# Count the number of people who have invested and who have not
|
27 |
-
|
28 |
-
|
29 |
|
30 |
# Create a bar chart using seaborn
|
31 |
plt.figure(figsize=(10, 6))
|
32 |
-
barplot = sns.barplot(x='Boycott', y='Count', data=
|
33 |
ax = plt.gca() # Get the current Axes instance on the current figure matching the given keyword args, or create one.
|
34 |
ax.set_xticklabels(ax.get_xticklabels(), fontproperties=font_prop)
|
35 |
|
@@ -39,7 +39,7 @@ def show_boycott_count(df, font_prop):
|
|
39 |
plt.title("Number of People Who Have/Haven't Boycotted a Company", fontsize=16, fontproperties=font_prop)
|
40 |
|
41 |
# Display values on the bars
|
42 |
-
for index, value in enumerate(
|
43 |
plt.text(index, value, str(value), ha='center', va='bottom', fontproperties=font_prop)
|
44 |
|
45 |
# Display the chart in Streamlit
|
|
|
8 |
from fields.prod_feat_flat_fields import prod_feat_flat_fields
|
9 |
from fields.feature_translations import feature_translations
|
10 |
|
11 |
+
@st.cache_data
|
12 |
def show(df):
|
13 |
# Load the Chinese font
|
14 |
chinese_font = FontProperties(fname='mingliu.ttf', size=12)
|
|
|
24 |
|
25 |
def show_boycott_count(df, font_prop):
|
26 |
# Count the number of people who have invested and who have not
|
27 |
+
boycott_count = df["你/妳有沒有抵制過某公司?"].value_counts().reset_index()
|
28 |
+
boycott_count.columns = ['Boycott', 'Count']
|
29 |
|
30 |
# Create a bar chart using seaborn
|
31 |
plt.figure(figsize=(10, 6))
|
32 |
+
barplot = sns.barplot(x='Boycott', y='Count', data=boycott_count, palette='viridis')
|
33 |
ax = plt.gca() # Get the current Axes instance on the current figure matching the given keyword args, or create one.
|
34 |
ax.set_xticklabels(ax.get_xticklabels(), fontproperties=font_prop)
|
35 |
|
|
|
39 |
plt.title("Number of People Who Have/Haven't Boycotted a Company", fontsize=16, fontproperties=font_prop)
|
40 |
|
41 |
# Display values on the bars
|
42 |
+
for index, value in enumerate(boycott_count['Count']):
|
43 |
plt.text(index, value, str(value), ha='center', va='bottom', fontproperties=font_prop)
|
44 |
|
45 |
# Display the chart in Streamlit
|