p2-m2-rmt018 / eda.py
mukhlishr's picture
Update eda.py
b09c7aa
raw
history blame
No virus
2.01 kB
import streamlit as st
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import plotly.express as px
from PIL import Image
from wordcloud import WordCloud
st.set_page_config(
page_title = 'Sentiment Analysis',
layout = 'wide',
initial_sidebar_state='expanded'
)
def run():
# title
st.title( 'Sentiment Prediction')
# sub header
st.subheader('Positive, Neutral, Negative')
# insert image
image = Image.open('sensi.jpg')
st.image(image, caption='image from AltextSoft, education purpose only')
# Deskripsi
st.write('Exploratory Data from dataset')
# show data frame
st.write('The first 10 Data')
df = pd.read_csv('https://raw.githubusercontent.com/mukhlishr/rasyidi/main/tripadvisor_hotel_reviews.csv')
st.dataframe(df.head(10))
# Barplot target columns
st.write('###### Rating ')
fig=plt.figure(figsize=(15,5))
sns.countplot(x='Rating', data = df)
st.pyplot(fig)
def Sentimen(x):
if x<= 5 and x>3:
return 'positive'
if x== 3:
return 'neutral'
if x< 3 and x>=1:
return 'negative'
# Create column 'sentimen'
df['sentimen'] = df['Rating'].apply(Sentimen)
# Barplot Sentiment
st.write('###### Sentiment of Review ')
fig=plt.figure(figsize=(15,5))
sns.countplot(x='sentimen', data = df)
st.pyplot(fig)
# Wordcloud
st.write('###### Word Cloud ')
def show_wordcloud(data, title = None):
wordcloud = WordCloud(
background_color='black',
max_words=200,
max_font_size=45,
scale=1,
random_state=1
).generate(" ".join(data))
fig = plt.figure(1, figsize=(15, 15))
plt.axis('off')
if title:
fig.suptitle(title, fontsize=20)
fig.subplots_adjust(top=2.3)
plt.imshow(wordcloud)
st.pyplot(fig)
# Wordcloud all
show_wordcloud(df['Review'].values)
if __name__ == '__main__':
run()