Phạm Anh Tuấn commited on
Commit
1b95adc
·
1 Parent(s): be990ca

update bar chart

Browse files
Files changed (1) hide show
  1. app.py +22 -16
app.py CHANGED
@@ -5,42 +5,48 @@ import matplotlib.pyplot as plt
5
  import seaborn as sns
6
  from wordcloud import WordCloud
7
 
 
8
  # Define the Streamlit app
9
- st.title("Data Analysis and Visualization")
 
10
 
11
  # File upload and processing
12
  uploaded_file = st.file_uploader("Upload JSON File", type=["json"])
13
  if uploaded_file:
14
  loaded_dict = json.load(uploaded_file)
15
  df = pd.DataFrame(loaded_dict)
16
- st.subheader("Dataframe (df)")
17
  st.write(df)
18
 
19
- # Group by and aggregate data
20
- grouped = df.groupby('A').agg({'S': ['count', lambda x: (x == 'great').sum(), lambda x: (x == 'ok').sum(), lambda x: (x == 'bad').sum()]})
21
- grouped.columns = grouped.columns.map('_'.join)
22
- grouped = grouped.reset_index()
23
- grouped = grouped.rename(columns={'A': 'Aspect', 'S_count': 'Freq', 'S_<lambda_0>': 'Great', 'S_<lambda_1>': 'Ok', 'S_<lambda_2>': 'Bad'})
24
-
25
- st.subheader("Top Aspects by Frequency")
26
- st.write(grouped.sort_values(by="Freq", ascending=False).head(5))
27
-
28
  # Sentiment Distribution Chart
29
- sentiment_distribution = df["S"].value_counts(normalize=True) * 100
30
- palette_color = sns.color_palette('bright')
31
 
32
  st.subheader("Sentiment Distribution")
33
  fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 6))
34
 
35
- ax1.pie(sentiment_distribution, labels=sentiment_distribution.index, autopct='%1.1f%%', startangle=140)
36
  ax1.axis('equal')
37
  ax1.set_title("Sentiment Distribution %")
38
 
39
- sns.countplot(x="S", data=df, palette=palette_color, ax=ax2)
 
40
  ax2.set_title("Sentiment Distribution Counts")
41
-
 
 
 
42
  st.pyplot(fig)
43
 
 
 
 
 
 
 
 
 
 
44
  # Word Cloud
45
  aspect_terms = " ".join(df["A"])
46
  wordcloud = WordCloud(
 
5
  import seaborn as sns
6
  from wordcloud import WordCloud
7
 
8
+ st.set_option('deprecation.showPyplotGlobalUse', False)
9
  # Define the Streamlit app
10
+ st.title("Aspected-Based Sentiment Analysis with MVP")
11
+ palette_color = sns.color_palette('Set1')
12
 
13
  # File upload and processing
14
  uploaded_file = st.file_uploader("Upload JSON File", type=["json"])
15
  if uploaded_file:
16
  loaded_dict = json.load(uploaded_file)
17
  df = pd.DataFrame(loaded_dict)
18
+ st.subheader(len(df)," sentiment tuples was detected")
19
  st.write(df)
20
 
 
 
 
 
 
 
 
 
 
21
  # Sentiment Distribution Chart
22
+ sentiment_distribution_perc = df["S"].value_counts(normalize=True) * 100
23
+ sentiment_distribution = df["S"].value_counts()
24
 
25
  st.subheader("Sentiment Distribution")
26
  fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 6))
27
 
28
+ ax1.pie(sentiment_distribution_perc, labels=sentiment_distribution_perc.index, autopct='%1.1f%%', startangle=140,colors=palette_color)
29
  ax1.axis('equal')
30
  ax1.set_title("Sentiment Distribution %")
31
 
32
+ # sns.countplot(x="S", data=df, palette=palette_color, ax=ax2)
33
+
34
  ax2.set_title("Sentiment Distribution Counts")
35
+ ax2.bar(sentiment_distribution.index, sentiment_distribution.values, color=palette_color)
36
+ # ax2.xlabel("Sentiment")
37
+ # ax2.ylabel("Times")
38
+ ax2.xticks(rotation=0) # Rotate x-axis labels if needed
39
  st.pyplot(fig)
40
 
41
+ # Group by and aggregate data
42
+ grouped = df.groupby('A').agg({'S': ['count', lambda x: (x == 'great').sum(), lambda x: (x == 'ok').sum(), lambda x: (x == 'bad').sum()]})
43
+ grouped.columns = grouped.columns.map('_'.join)
44
+ grouped = grouped.reset_index()
45
+ grouped = grouped.rename(columns={'A': 'Aspect', 'S_count': 'Freq', 'S_<lambda_0>': 'Great', 'S_<lambda_1>': 'Ok', 'S_<lambda_2>': 'Bad'})
46
+
47
+ st.subheader("Top 5 Most Mentioned Product Apsects")
48
+ st.write(grouped.sort_values(by="Freq", ascending=False).head(5))
49
+
50
  # Word Cloud
51
  aspect_terms = " ".join(df["A"])
52
  wordcloud = WordCloud(