Kurkur99 commited on
Commit
1f04d3e
1 Parent(s): f346719

Update eda.py

Browse files
Files changed (1) hide show
  1. eda.py +17 -3
eda.py CHANGED
@@ -3,11 +3,25 @@ import pandas as pd
3
  import matplotlib.pyplot as plt
4
  from wordcloud import WordCloud
5
 
 
 
 
 
 
 
 
 
 
 
 
6
  def display_eda(data):
7
- # Check if 'sentiment' column exists in the dataset
8
  if 'sentiment' not in data.columns:
9
- st.error("The dataset does not contain a 'sentiment' column. Please check the data source.")
10
- return
 
 
 
11
 
12
  # Distribution of sentiments
13
  st.subheader("Distribution of Sentiments")
 
3
  import matplotlib.pyplot as plt
4
  from wordcloud import WordCloud
5
 
6
+ def label_sentiment(rating):
7
+ """Label sentiment based on the rating."""
8
+ if rating in [1, 2]:
9
+ return 'negative'
10
+ elif rating == 3:
11
+ return 'neutral'
12
+ elif rating in [4, 5]:
13
+ return 'positive'
14
+ else:
15
+ return 'unknown'
16
+
17
  def display_eda(data):
18
+ # Derive the 'sentiment' column from 'rating' if it doesn't exist
19
  if 'sentiment' not in data.columns:
20
+ if 'rating' not in data.columns:
21
+ st.error("The dataset does not contain a 'rating' or 'sentiment' column. Please check the data source.")
22
+ return
23
+ else:
24
+ data['sentiment'] = data['rating'].apply(label_sentiment)
25
 
26
  # Distribution of sentiments
27
  st.subheader("Distribution of Sentiments")