-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp1.py
43 lines (32 loc) · 1.6 KB
/
app1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import streamlit as st
import pandas as pd
import numpy as np
import plotly.express as px
st.title("Sentiment Analysis of Tweets about US Airlines")
st.sidebar.title("Sentiment Analysis of Tweets about US Airlines")
st.markdown("This dashboard present visual analysis of tweets about US Airlines")
st.sidebar.markdown("This dashboard present visual analysis of tweets about US Airlines")
#data_path = r"C:\Users\shrid\anaconda3\envs\textviz\Tweets.csv"
data_path = r"Tweets.csv"
@st.cache(persist = True)
def load_data():
data = pd.read_csv(data_path)
data['tweet_created'] = pd.to_datetime(data['tweet_created'])
return data
data = load_data()
st.sidebar.subheader("Show random tweets as per sentiment")
random_tweet = st.sidebar.radio('Sentiment', ('positive', 'negative', 'neutral'))
st.sidebar.markdown(data.query("airline_sentiment== @random_tweet")[["text"]].sample(n=1).iat[0,0])
st.sidebar.markdown("### Number of tweets by sentiment")
#st.sidebar.markdown("#### Uncheck Hide checkbox to view chart")
select = st.sidebar.selectbox("Visualization type", ['Histogram', 'Piechart'], key = '1')
sentiment_count = data['airline_sentiment'].value_counts()
sentiment_count = pd.DataFrame({'Sentiment': sentiment_count.index, 'Tweets':sentiment_count.values})
#if not st.sidebar.checkbox("Hide", True):
st.markdown("### Number of tweets by sentiment")
if select == "Histogram":
fig = px.bar(sentiment_count, x= 'Sentiment', y ='Tweets', color = 'Tweets')
st.plotly_chart(fig)
else:
fig = px.pie(sentiment_count , values = 'Tweets', names = 'Sentiment')
st.plotly_chart(fig)