<jupyter_start><jupyter_text>By analyzing the HTML code, I found that the first table with class=sortable is the one I wantI converted the fields, and created a dict to make things easier. We would also have used a list<jupyter_code>table = soup.find('table',attrs={"class":"sortable"})

my_dict = {}

#I got the table that I want...
#Now I will navigate:
# For each row (<tr>), I will get the <td>s. 
for tr in table.findAll("tr"):
    td_list = tr.findAll("td")

    # JUST MAKING SURE THAT I AM GETTING THE TRs WITH TDs (not the THS)
    if (len(td_list) > 0):

        ### I USED THE EXISTENCE OF AN IMAGE (FLAG) TO FILTER THE LINES I WANT
        if(len(td_list[1].findAll("img")) > 0):

            ##Looking at the table I want the 2nd, 3rd, 4th, and 5th columns
            ### I know that se second column (second position in my list with the tds)
            country_name = td_list[1].text.strip()
            #for each field, I curated the numbers to remove the ',' so it is possible to convert to float/int
            areakm = td_list[2].text.replace(',','')
            areami = td_list[3].text.replace(',','')
            population = td_list[4].text.replace(',','')
            #created a dictionary to make it easier to work
            my_dict[country_name] = {'area_km2': float(areakm),
                                     'area_mi2': float(areami),  
                                     'population': int(population)  
            }<jupyter_output><empty_output><jupyter_text>Exercise 2* It is facilitated because I converted the fields as I was scraping.<jupyter_code># THis is the magical function I used to come from a dict to a dataframe
# the parameter orient. If dict keys are row, you use index. If the dict keys are columns, you don't need the param.
df = pandas.DataFrame.from_dict(my_dict, orient= 'index')
df<jupyter_output><empty_output><jupyter_text>Exercise 3* Summarizing our data<jupyter_code>df.describe()<jupyter_output><empty_output><jupyter_text>Exercise 4* Creating the correlation matrix<jupyter_code>df.corr(method='pearson').style.background_gradient(cmap='coolwarm')<jupyter_output><empty_output><jupyter_text>Exercise 5* Scatterplot<jupyter_code>df.plot.scatter(x = "area_km2", y = "population")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11086669599648043, 'fraction_numerical': 0.007919049714034315, 'mean_word_length': 3.38996138996139, 'pattern_counts': {'":': 1, '<': 23, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '92393', 'license': 'Unlicense', 'n_tokens_mistral': 752, 'n_tokens_neox': 713, 'n_words': 236, 'path': 'assignments/Scraping_Pandas_inClass.ipynb', 'repo_name': 'tossyne01/INF502-Fall2020', 'size': '2273'}