hi, can someone comment if i have written the code right. many thanks.
project name:“chocolate Scrapping with Beautiful Soup”
import codecademylib3_seaborn
from bs4 import BeautifulSoup
import requests
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
webpage_requests =requests.get("https://s3.amazonaws.com/codecademy-content/courses/beautifulsoup/cacao/index.html")
webpage =webpage_response.content
soup =BeautifulSoup(webpage, "html.parser")
print(soup)
soup_links =soup.find_all(attrs ={'Rating':"td"})
ratings =[]
for n in soup_links:
ratings.append(float((soup_links.select(".td").get_text())))
plt.hist(ratings)
plt.show()
soup.select(".Company")
company_name =[]
for td in soup_links[1:]:
company_name.append(td.get_text)
d ={"Company":company_name, "Rating":ratings, "CocoaPercentage":cocoa_percents}
df =pd.DataFrame.from_dict(d)
mean_value =df.group_by("Company").Rating.mean()
ten_best =mean_value.nlargest(10)
print(ten_best)
cocoa_percents =[]
cocoa_percent_tags =soup.select(".CocoaPercent")
for td in cocoa_percent_tags[1:]:
percent =int(td.get_text().strip('%'))
cocoa_percents.append(percent)
d ={"Company":company_name, "Rating":ratings, "CocoaPercentage":cocoa_percents}
plt.clf()
plt.scatter(df.CocoaPercentage,df.Rating)
z=np.polyfit(df.CocoaPercentage,df.Rating,1)
line_function =np.polyld(z)
plt.plot(df.CocoaPercentage,line_function(df.CocoaPercentage),"r--")
plt.show()