-
Notifications
You must be signed in to change notification settings - Fork 3
/
youtubegraph.py
executable file
·89 lines (77 loc) · 2.71 KB
/
youtubegraph.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from Youtube import search_vidid,all_cmt
from Senti import analyse_sentiment
import plotly.graph_objs as go
import pandas as pd
import datetime as dt
#FUNCTION TO PLOT YOUTUBE GRAPH
days = dt.timedelta(days=10)
end_date = dt.date.today()
begin_date = end_date - days
global yt_vid_comments
yt_vid_comments = []
def YT_graph(n_clicks,input_value):
videoid_list=search_vidid(begin_date, end_date, input_value)
ansdf=all_cmt(videoid_list)
ansdf = analyse_sentiment(ansdf,"comments")
#answt = analyse_sentimentwt(ansdf,"comments")
ansdf['Date'] = ansdf.apply(lambda row: str(row.CommentPublishDate).split("T", 1)[0], axis = 1)
ansdf['RoundPolarity'] = round(ansdf['sentiment'],1)
ansdf2 = ansdf.groupby('Date', as_index=False)[['sentiment']].mean()
#yaha tkk toh bss dataframe creation hai jo tere paas hai
data=[]
trace_close = go.Scatter(x = list(ansdf2.Date),
y=list(ansdf2.sentiment),
name="Close"
)
data.append(trace_close)
figure1 = go.Figure(data)
figure1.update_layout(
title="Date-Wise Mean Sentiment Score Line Plot",
xaxis_title="Date",
yaxis_title="Mean Score",
template='plotly_dark',
plot_bgcolor= 'rgba(0, 0, 0, 0)'
)
data=[]
trace_close = go.Scatter(x = list(ansdf.CommentPublishDate),
y=list(ansdf.sentiment),
mode='markers',
name='markers',
marker_color=ansdf['sentiment']
)
data.append(trace_close)
figure2 = go.Figure(data)
figure2.update_layout(
title="Date-Wise Sentiment Score Scatter Plot [negative(-1) to positive(+1)]",
xaxis_title="Date",
yaxis_title="(-ve) Sentiment Score (+ve)",
template='plotly_dark',
plot_bgcolor= 'rgba(0, 0, 0, 0)'
)
data=[]
trace_close = go.Box(x = list(ansdf.Date),
y=list(ansdf.sentiment),
name="Close",
line=dict(color="#ff3333"))
data.append(trace_close)
figure3 = go.Figure(data)
figure3.update_layout(
title="Date-Wise Sentiment Score Box Plot [negative(-1) to positive(+1)]",
xaxis_title="Date",
yaxis_title="(-ve) Sentiment Score (+ve)",
template='plotly_dark',
plot_bgcolor= 'rgba(0, 0, 0, 0)'
)
data=[]
trace_close = go.Pie(labels=list(ansdf.roundoff),
name="Close"
)
data.append(trace_close)
figure4 = go.Figure(data)
figure4.update_layout(
title="Pie-Chart",
template='plotly_dark',
plot_bgcolor= 'rgba(0, 0, 0, 0)'
)
figure = (figure1,figure2,figure3,figure4)
return figure