This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
import pandas as pd | |
import math | |
class UpperConfidenceBound: | |
def __init__(self,path, N, m): | |
self.__dataset = pd.read_csv(path) | |
self.__N = N | |
self.__m = m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
import pandas as pd | |
import random | |
class ThompsonSampling: | |
def __init__(self,path,N,m): | |
self.__N = N | |
self.__m = m | |
self.__machine_selected = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!apt install chromium-chromedriver | |
!cp /usr/lib/chromium-browser/chromedriver /usr/bin | |
!pip install selenium |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ScrapComments(path): | |
authors = [] | |
try: | |
# Configuring the ChromeDriver | |
options = webdriver.ChromeOptions() | |
options.add_argument('-headless') | |
options.add_argument('-no-sandbox') | |
options.add_argument('-disable-dev-shm-usage') | |
#wd = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from selenium import webdriver | |
from selenium.webdriver import Chrome | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions as EC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import pandas as pd | |
def create_df_author_comments1(data): | |
author_comment = [] | |
author=[] | |
for item in data: | |
s = re.sub('\\n[0-9]+ (days|weeks|months|years|week|month|year|hours|hour|day|minutes|minute) ago' ,'',item) | |
s = re.sub('\\nREPLY','',s) | |
s = re.sub('\.\\n[0-9][\.]*[0-9]*[A-Z]*','',s) | |
t = s.split('\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import googleapiclient.discovery | |
def google_api(id): | |
# Disable OAuthlib's HTTPS verification when running locally. | |
# *DO NOT* leave this option enabled in production. | |
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1" | |
api_service_name = "youtube" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
def create_df_author_comments(): | |
authorname = [] | |
comments = [] | |
for i in range(len(response["items"])): | |
authorname.append(response["items"][i]["snippet"]["topLevelComment"]["snippet"]["authorDisplayName"]) | |
comments.append(response["items"][i]["snippet"]["topLevelComment"]["snippet"]["textOriginal"]) | |
df_1 = pd.DataFrame(comments, index = authorname,columns=["Comments"]) | |
return df_1 | |
df_1 = create_df_author_comments() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
with open('response.json') as f: | |
response = json.load(f) | |
f.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
def create_df_author_comments(response): | |
authorname = [] | |
comments = [] | |
for i in range(len(response["items"])): | |
authorname.append(response["items"][i]["snippet"]["topLevelComment"]["snippet"]["authorDisplayName"]) | |
comments.append(response["items"][i]["snippet"]["topLevelComment"]["snippet"]["textOriginal"]) | |
df_1 = pd.DataFrame(comments, index = authorname,columns=["Comments"]) | |
return df_1 | |
df = create_df_author_comments(response) |
OlderNewer