Spaces:
Runtime error
Runtime error
jmansfield89
commited on
Commit
•
15d3d18
1
Parent(s):
913253b
Update app.py
Browse filesUpdate to better layout of text and a new form of the bar chart
app.py
CHANGED
@@ -3,35 +3,38 @@ import streamlit as st
|
|
3 |
import pandas as pd
|
4 |
import sys
|
5 |
from streamlit import cli as stcli
|
|
|
|
|
6 |
|
7 |
|
8 |
# DATA IMPORT
|
9 |
# Import data from "df_redacted.csv" as a dataframe
|
10 |
df_redacted = pd.read_csv('df_redacted.csv')
|
11 |
|
|
|
|
|
|
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
value_dict = dict(zip(values, counts))
|
18 |
-
|
19 |
-
# Calculate the max of all 3 sentiment categories
|
20 |
-
sentiment = max(value_dict, key=value_dict.get)
|
21 |
|
|
|
|
|
22 |
|
|
|
|
|
23 |
def main():
|
24 |
# Header display section of app
|
25 |
-
st.
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
# Display the count for each sentiment category and overall sentiment of the tweet replies
|
31 |
-
st.write('Highest sentiment category for the replies to the Facebook Tweet announcing Meta: ', sentiment)
|
32 |
-
|
33 |
# Display histogram of count for each sentiment category
|
34 |
-
|
|
|
35 |
|
36 |
|
37 |
if __name__ == '__main__':
|
|
|
3 |
import pandas as pd
|
4 |
import sys
|
5 |
from streamlit import cli as stcli
|
6 |
+
import plotly.express as px
|
7 |
+
import numpy as np
|
8 |
|
9 |
|
10 |
# DATA IMPORT
|
11 |
# Import data from "df_redacted.csv" as a dataframe
|
12 |
df_redacted = pd.read_csv('df_redacted.csv')
|
13 |
|
14 |
+
# DATA MANIPULATION
|
15 |
+
# Create variable for Tweet being analyzed in this app
|
16 |
+
tweet_url = "https://twitter.com/Meta/status/1453795115701440524"
|
17 |
|
18 |
+
# Create new dataframe, reset the index, and rename columns
|
19 |
+
sentiment_counts = pd.DataFrame(df_redacted['sentiment_score'].value_counts(dropna=False))
|
20 |
+
sentiment_counts = sentiment_counts.reset_index()
|
21 |
+
sentiment_counts.columns = ['Sentiment', 'Count']
|
|
|
|
|
|
|
|
|
22 |
|
23 |
+
# Find sentiment category with the highest count
|
24 |
+
sentiment = sentiment_counts.loc[sentiment_counts['Count'].idxmax(), 'Sentiment']
|
25 |
|
26 |
+
# DISPLAY DATA
|
27 |
+
# Display the count for each sentiment category and overall sentiment of the tweet replies
|
28 |
def main():
|
29 |
# Header display section of app
|
30 |
+
st.markdown("**Objective:** Understand public sentiment of a Tweet by analyzing the sentiment of each reply.")
|
31 |
+
st.markdown("**Analysis:** This app runs sentiment analysis on the replies to a Facebook Tweet announcing their "
|
32 |
+
"rebranding to Meta on 10/28/2021. Link to Tweet: {}".format(tweet_url))
|
33 |
+
st.markdown("**Results:** Most frequent sentiment category for this Tweet's replies: **{}**".format(sentiment))
|
34 |
+
|
|
|
|
|
|
|
35 |
# Display histogram of count for each sentiment category
|
36 |
+
fig = px.bar(sentiment_counts, x='Sentiment', y='Count')
|
37 |
+
st.plotly_chart(fig, use_container_width=True)
|
38 |
|
39 |
|
40 |
if __name__ == '__main__':
|