From b5c14aa2317dfbdd027b93a6221028d1b4c2b366 Mon Sep 17 00:00:00 2001 From: ClauCarloni Date: Sat, 9 Oct 2021 10:34:54 +0200 Subject: [PATCH 1/7] Adding updated file 01 --- 01_Billboard.ipynb | 223 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 211 insertions(+), 12 deletions(-) diff --git a/01_Billboard.ipynb b/01_Billboard.ipynb index 779a38c..0243143 100644 --- a/01_Billboard.ipynb +++ b/01_Billboard.ipynb @@ -41,7 +41,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "promotional-algorithm", "metadata": {}, "outputs": [], @@ -59,11 +59,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "civic-broad", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "200" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ + "response = requests.get(url)\n", + "response.status_code\n", "# 200 status code means OK!" ] }, @@ -77,11 +90,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "revised-digest", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "soup = BeautifulSoup(response.content, \"html.parser\")" + ] }, { "cell_type": "markdown", @@ -93,20 +108,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "falling-chambers", "metadata": {}, "outputs": [], "source": [ "# song titles\n", + "songs = soup.find_all(\"span\", class_=\"chart-element__information__song text--truncate color--primary\")\n", "\n", "# artists\n", + "artists = soup.find_all(\"span\", class_=\"chart-element__information__artist text--truncate color--secondary\")\n", "\n", "# last week\n", + "last_week_ranks = soup.find_all(\"span\", class_= \"chart-element__meta text--center color--secondary text--last\")\n", "\n", "# peak rank\n", + "peak_ranks = soup.find_all(\"span\", class_= \"chart-element__meta text--center color--secondary text--peak\")\n", "\n", - "# weeks on chart\n" + "# weeks on chart\n", + "weeks_on_chart = soup.find_all(\"span\", class_= \"chart-element__meta text--center color--secondary text--week\")" ] }, { @@ -119,11 +139,15 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "amateur-protocol", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "for i in [songs, artists, last_week_ranks, peak_ranks, weeks_on_chart]:\n", + " for j in range(len(i)):\n", + " i[j] = i[j].getText()" + ] }, { "cell_type": "markdown", @@ -135,11 +159,186 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "id": "external-instrumentation", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "billboard = pd.DataFrame(\n", + " {\"song\": songs,\n", + " \"artist\": artists,\n", + " \"last_week_rank\": last_week_ranks,\n", + " \"peak_rank\": peak_ranks,\n", + " \"weeks_on_chart\": weeks_on_chart}\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "80063bef", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
songartistlast_week_rankpeak_rankweeks_on_chart
0My UniverseColdplay x BTS-11
1StayThe Kid LAROI & Justin Bieber1112
2Industry BabyLil Nas X & Jack Harlow2210
3Way 2 SexyDrake Featuring Future & Young Thug314
4Fancy LikeWalker Hayes5515
..................
95Pipe DownDrake68144
96Papi's HomeDrake6684
97ChosenBlxst & Tyga Featuring Ty Dolla $ign-981
98Toxic PunkYoungBoy Never Broke Again-991
99MoonKanye West76175
\n", + "

100 rows × 5 columns

\n", + "
" + ], + "text/plain": [ + " song artist last_week_rank \\\n", + "0 My Universe Coldplay x BTS - \n", + "1 Stay The Kid LAROI & Justin Bieber 1 \n", + "2 Industry Baby Lil Nas X & Jack Harlow 2 \n", + "3 Way 2 Sexy Drake Featuring Future & Young Thug 3 \n", + "4 Fancy Like Walker Hayes 5 \n", + ".. ... ... ... \n", + "95 Pipe Down Drake 68 \n", + "96 Papi's Home Drake 66 \n", + "97 Chosen Blxst & Tyga Featuring Ty Dolla $ign - \n", + "98 Toxic Punk YoungBoy Never Broke Again - \n", + "99 Moon Kanye West 76 \n", + "\n", + " peak_rank weeks_on_chart \n", + "0 1 1 \n", + "1 1 12 \n", + "2 2 10 \n", + "3 1 4 \n", + "4 5 15 \n", + ".. ... ... \n", + "95 14 4 \n", + "96 8 4 \n", + "97 98 1 \n", + "98 99 1 \n", + "99 17 5 \n", + "\n", + "[100 rows x 5 columns]" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "billboard" + ] } ], "metadata": { @@ -158,7 +357,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.5" + "version": "3.8.8" }, "toc": { "base_numbering": 1, From 1bbd25bb0ea4d34abd1c2a02d6b13082486654f6 Mon Sep 17 00:00:00 2001 From: ClauCarloni Date: Tue, 19 Oct 2021 22:23:45 +0200 Subject: [PATCH 2/7] Adding updated file Billboard for the lab --- 01_Billboard.ipynb | 286 +++++++++++++++++++++++++++++++++------------ 1 file changed, 213 insertions(+), 73 deletions(-) diff --git a/01_Billboard.ipynb b/01_Billboard.ipynb index 0243143..17029be 100644 --- a/01_Billboard.ipynb +++ b/01_Billboard.ipynb @@ -59,7 +59,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "id": "civic-broad", "metadata": {}, "outputs": [ @@ -69,7 +69,7 @@ "200" ] }, - "execution_count": 4, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -90,7 +90,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "id": "revised-digest", "metadata": {}, "outputs": [], @@ -108,7 +108,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "id": "falling-chambers", "metadata": {}, "outputs": [], @@ -139,7 +139,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "id": "amateur-protocol", "metadata": {}, "outputs": [], @@ -159,7 +159,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "id": "external-instrumentation", "metadata": {}, "outputs": [], @@ -175,7 +175,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "id": "80063bef", "metadata": {}, "outputs": [ @@ -210,11 +210,11 @@ " \n", " \n", " 0\n", - " My Universe\n", - " Coldplay x BTS\n", - " -\n", - " 1\n", + " Industry Baby\n", + " Lil Nas X & Jack Harlow\n", + " 2\n", " 1\n", + " 12\n", " \n", " \n", " 1\n", @@ -222,31 +222,31 @@ " The Kid LAROI & Justin Bieber\n", " 1\n", " 1\n", - " 12\n", + " 14\n", " \n", " \n", " 2\n", - " Industry Baby\n", - " Lil Nas X & Jack Harlow\n", - " 2\n", - " 2\n", - " 10\n", + " Fancy Like\n", + " Walker Hayes\n", + " 3\n", + " 3\n", + " 17\n", " \n", " \n", " 3\n", - " Way 2 Sexy\n", - " Drake Featuring Future & Young Thug\n", - " 3\n", - " 1\n", - " 4\n", + " Bad Habits\n", + " Ed Sheeran\n", + " 5\n", + " 2\n", + " 16\n", " \n", " \n", " 4\n", - " Fancy Like\n", - " Walker Hayes\n", - " 5\n", - " 5\n", - " 15\n", + " Way 2 Sexy\n", + " Drake Featuring Future & Young Thug\n", + " 4\n", + " 1\n", + " 6\n", " \n", " \n", " ...\n", @@ -258,43 +258,43 @@ " \n", " \n", " 95\n", - " Pipe Down\n", - " Drake\n", - " 68\n", - " 14\n", - " 4\n", + " Ain't Shit\n", + " Doja Cat\n", + " -\n", + " 24\n", + " 13\n", " \n", " \n", " 96\n", - " Papi's Home\n", - " Drake\n", - " 66\n", - " 8\n", - " 4\n", + " Just About Over You\n", + " Priscilla Block\n", + " -\n", + " 97\n", + " 1\n", " \n", " \n", " 97\n", - " Chosen\n", - " Blxst & Tyga Featuring Ty Dolla $ign\n", + " For Tonight\n", + " Giveon\n", " -\n", - " 98\n", - " 1\n", + " 91\n", + " 2\n", " \n", " \n", " 98\n", - " Toxic Punk\n", - " YoungBoy Never Broke Again\n", + " Praise God\n", + " Kanye West\n", " -\n", - " 99\n", - " 1\n", + " 20\n", + " 3\n", " \n", " \n", " 99\n", - " Moon\n", - " Kanye West\n", - " 76\n", - " 17\n", - " 5\n", + " Bad Morning\n", + " YoungBoy Never Broke Again\n", + " 81\n", + " 28\n", + " 3\n", " \n", " \n", "\n", @@ -302,36 +302,36 @@ "" ], "text/plain": [ - " song artist last_week_rank \\\n", - "0 My Universe Coldplay x BTS - \n", - "1 Stay The Kid LAROI & Justin Bieber 1 \n", - "2 Industry Baby Lil Nas X & Jack Harlow 2 \n", - "3 Way 2 Sexy Drake Featuring Future & Young Thug 3 \n", - "4 Fancy Like Walker Hayes 5 \n", - ".. ... ... ... \n", - "95 Pipe Down Drake 68 \n", - "96 Papi's Home Drake 66 \n", - "97 Chosen Blxst & Tyga Featuring Ty Dolla $ign - \n", - "98 Toxic Punk YoungBoy Never Broke Again - \n", - "99 Moon Kanye West 76 \n", + " song artist last_week_rank \\\n", + "0 Industry Baby Lil Nas X & Jack Harlow 2 \n", + "1 Stay The Kid LAROI & Justin Bieber 1 \n", + "2 Fancy Like Walker Hayes 3 \n", + "3 Bad Habits Ed Sheeran 5 \n", + "4 Way 2 Sexy Drake Featuring Future & Young Thug 4 \n", + ".. ... ... ... \n", + "95 Ain't Shit Doja Cat - \n", + "96 Just About Over You Priscilla Block - \n", + "97 For Tonight Giveon - \n", + "98 Praise God Kanye West - \n", + "99 Bad Morning YoungBoy Never Broke Again 81 \n", "\n", " peak_rank weeks_on_chart \n", - "0 1 1 \n", - "1 1 12 \n", - "2 2 10 \n", - "3 1 4 \n", - "4 5 15 \n", + "0 1 12 \n", + "1 1 14 \n", + "2 3 17 \n", + "3 2 16 \n", + "4 1 6 \n", ".. ... ... \n", - "95 14 4 \n", - "96 8 4 \n", - "97 98 1 \n", - "98 99 1 \n", - "99 17 5 \n", + "95 24 13 \n", + "96 97 1 \n", + "97 91 2 \n", + "98 20 3 \n", + "99 28 3 \n", "\n", "[100 rows x 5 columns]" ] }, - "execution_count": 9, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -339,6 +339,146 @@ "source": [ "billboard" ] + }, + { + "cell_type": "markdown", + "id": "1ea579c6", + "metadata": {}, + "source": [ + "## Recommening a new song" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "d3197368", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "What song do you like? Stay\n" + ] + } + ], + "source": [ + "input_song = input(\"What song do you like? \")" + ] + }, + { + "cell_type": "code", + "execution_count": 92, + "id": "8cf648b3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Moon'" + ] + }, + "execution_count": 92, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "input_song" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "28aa8d62", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
songartistlast_week_rankpeak_rankweeks_on_chart
1StayThe Kid LAROI & Justin Bieber1114
\n", + "
" + ], + "text/plain": [ + " song artist last_week_rank peak_rank weeks_on_chart\n", + "1 Stay The Kid LAROI & Justin Bieber 1 1 14" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "billboard.loc[billboard['song'] == input_song]" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "ff25923e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Recommendation: Fancy Like\n" + ] + } + ], + "source": [ + "pos = -1 #position\n", + "for index, song in enumerate(billboard['song'].tolist()):\n", + " if song == input_song:\n", + " pos = index\n", + "\n", + "edge = len(billboard) - 1\n", + "if pos >= 0:\n", + " if pos <= edge - 1:\n", + " print('Recommendation:', billboard['song'].iloc[pos + 1])\n", + " else:\n", + " print('Recommendation:', billboard['song'].iloc[edge - pos])\n", + "else:\n", + " print('This song is not in the list')" + ] } ], "metadata": { From 337f57557aea4ca6d18ac1714cb595877af04f4b Mon Sep 17 00:00:00 2001 From: ClauCarloni Date: Tue, 19 Oct 2021 23:47:25 +0200 Subject: [PATCH 3/7] Adding updated version of file 02 --- 02_Further_questions.ipynb | 427 ++++++++++++++++++++++++++++++++++++- 1 file changed, 421 insertions(+), 6 deletions(-) diff --git a/02_Further_questions.ipynb b/02_Further_questions.ipynb index 66fb224..135976f 100644 --- a/02_Further_questions.ipynb +++ b/02_Further_questions.ipynb @@ -19,6 +19,18 @@ "As you've seen, scraping the internet is a skill that can get you all sorts of information. Here are some little challenges to gain more experience in the field" ] }, + { + "cell_type": "code", + "execution_count": 1, + "id": "ebcadb1b", + "metadata": {}, + "outputs": [], + "source": [ + "from bs4 import BeautifulSoup\n", + "import requests\n", + "import pandas as pd" + ] + }, { "cell_type": "markdown", "id": "express-introduction", @@ -29,7 +41,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "appreciated-bubble", "metadata": {}, "outputs": [], @@ -37,6 +49,203 @@ "url ='https://en.wikipedia.org/wiki/Python'" ] }, + { + "cell_type": "code", + "execution_count": 3, + "id": "ed026649", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "200" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "response = requests.get(url)\n", + "response.status_code" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "cf8b4107", + "metadata": {}, + "outputs": [], + "source": [ + "soup = BeautifulSoup(response.content, \"html.parser\")" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "95c39303", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Computing',\n", + " 'People',\n", + " 'Roller coasters',\n", + " 'Vehicles',\n", + " 'Weaponry',\n", + " 'Other uses',\n", + " 'See also']" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "contents = []\n", + "pre = soup.find_all('span', attrs={'class': 'toctext'})\n", + "for c in pre:\n", + " contents.append(c.get_text())\n", + "contents" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "3bc0b3a9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'https://en.wikipedia.org/wiki/Python#Computing'" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "links = 'https://en.wikipedia.org/wiki/Python' + soup.find('li', attrs={'class': 'toclevel-1 tocsection-1'}).find('a').get('href')\n", + "links" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "id": "4639eed6", + "metadata": {}, + "outputs": [], + "source": [ + "contents = []\n", + "links = []\n", + "\n", + "pre = soup.find_all('span', attrs={'class': 'toctext'})\n", + "\n", + "for i, c in enumerate(pre):\n", + " contents.append(c.get_text())\n", + " x = i+1\n", + " links.append('https://en.wikipedia.org/wiki/Python' + soup.find('li', attrs={'class': 'toclevel-1 tocsection-'+str(x)}).find('a').get('href'))\n" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "id": "95ccd4f6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
contentlink
0Computinghttps://en.wikipedia.org/wiki/Python#Computing
1Peoplehttps://en.wikipedia.org/wiki/Python#People
2Roller coastershttps://en.wikipedia.org/wiki/Python#Roller_co...
3Vehicleshttps://en.wikipedia.org/wiki/Python#Vehicles
4Weaponryhttps://en.wikipedia.org/wiki/Python#Weaponry
5Other useshttps://en.wikipedia.org/wiki/Python#Other_uses
6See alsohttps://en.wikipedia.org/wiki/Python#See_also
\n", + "
" + ], + "text/plain": [ + " content link\n", + "0 Computing https://en.wikipedia.org/wiki/Python#Computing\n", + "1 People https://en.wikipedia.org/wiki/Python#People\n", + "2 Roller coasters https://en.wikipedia.org/wiki/Python#Roller_co...\n", + "3 Vehicles https://en.wikipedia.org/wiki/Python#Vehicles\n", + "4 Weaponry https://en.wikipedia.org/wiki/Python#Weaponry\n", + "5 Other uses https://en.wikipedia.org/wiki/Python#Other_uses\n", + "6 See also https://en.wikipedia.org/wiki/Python#See_also" + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dct = {'content': contents, 'link': links}\n", + "\n", + "df = pd.DataFrame.from_dict(dct)\n", + "df" + ] + }, { "cell_type": "markdown", "id": "relevant-performer", @@ -47,7 +256,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 56, "id": "scenic-surgeon", "metadata": {}, "outputs": [], @@ -55,6 +264,60 @@ "url = 'http://uscode.house.gov/download/download.shtml'" ] }, + { + "cell_type": "code", + "execution_count": 57, + "id": "2bcc0343", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "200" + ] + }, + "execution_count": 57, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "response = requests.get(url)\n", + "response.status_code" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "id": "8d5778d2", + "metadata": {}, + "outputs": [], + "source": [ + "soup = BeautifulSoup(response.content, \"html.parser\")" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "id": "df61ca56", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Number of titles: 54\n" + ] + } + ], + "source": [ + "titles = []\n", + "pre = soup.find_all('div', attrs={'class': 'usctitle'})\n", + "for t in pre:\n", + " titles.append(t.get_text())\n", + "print('Number of titles:', titles[-1].split()[1])" + ] + }, { "cell_type": "markdown", "id": "acute-necessity", @@ -65,12 +328,69 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 81, "id": "starting-blackberry", "metadata": {}, "outputs": [], "source": [ - "url = 'https://www.fbi.gov/wanted/topten" + "url = 'https://www.fbi.gov/wanted/topten'" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "id": "1b1d7936", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "200" + ] + }, + "execution_count": 82, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "response = requests.get(url)\n", + "response.status_code" + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "id": "6c021c42", + "metadata": {}, + "outputs": [], + "source": [ + "soup = BeautifulSoup(response.content, \"html.parser\")" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "id": "5dd15661", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Arnoldo jimenez', 'Jason derek brown', 'Alexis flores', 'Jose rodolfo villarreal hernandez', 'Octaviano juarez corro', 'Eugene palmer', 'Rafael caro quintero', 'Bhadreshkumar chetanbhai patel', 'Alejandro castillo', 'Robert william fisher']\n" + ] + } + ], + "source": [ + "wanted = []\n", + "pre = soup.find_all('li', attrs={'class': 'portal-type-person castle-grid-block-item'})\n", + "\n", + "for i, c in enumerate(pre):\n", + " wanted.append(c.find('a').get('href').split('/')[-1].replace('-',' ').capitalize())\n", + " x = i+1\n", + "\n", + "print(wanted)\n" ] }, { @@ -83,7 +403,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 96, "id": "copyrighted-taiwan", "metadata": {}, "outputs": [], @@ -91,6 +411,38 @@ "url = 'https://www.emsc-csem.org/Earthquake/'" ] }, + { + "cell_type": "code", + "execution_count": 97, + "id": "d15989b7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "200" + ] + }, + "execution_count": 97, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "response = requests.get(url)\n", + "response.status_code" + ] + }, + { + "cell_type": "code", + "execution_count": 98, + "id": "85cd3c87", + "metadata": {}, + "outputs": [], + "source": [ + "soup = BeautifulSoup(response.content, \"html.parser\")" + ] + }, { "cell_type": "markdown", "id": "dominican-defeat", @@ -109,6 +461,27 @@ "url = 'https://www.wikipedia.org/'" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "a0f9d350", + "metadata": {}, + "outputs": [], + "source": [ + "response = requests.get(url)\n", + "response.status_code" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d7f371f1", + "metadata": {}, + "outputs": [], + "source": [ + "soup = BeautifulSoup(response.content, \"html.parser\")" + ] + }, { "cell_type": "markdown", "id": "split-cartridge", @@ -127,6 +500,27 @@ "url = 'https://data.gov.uk/" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "42e312fd", + "metadata": {}, + "outputs": [], + "source": [ + "response = requests.get(url)\n", + "response.status_code" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "07d043d0", + "metadata": {}, + "outputs": [], + "source": [ + "soup = BeautifulSoup(response.content, \"html.parser\")" + ] + }, { "cell_type": "markdown", "id": "potential-malpractice", @@ -144,6 +538,27 @@ "source": [ "url = 'https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers'" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6b2cda87", + "metadata": {}, + "outputs": [], + "source": [ + "response = requests.get(url)\n", + "response.status_code" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "62ff13a7", + "metadata": {}, + "outputs": [], + "source": [ + "soup = BeautifulSoup(response.content, \"html.parser\")" + ] } ], "metadata": { @@ -162,7 +577,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.5" + "version": "3.8.8" }, "toc": { "base_numbering": 1, From 0f5dc82111fdefbccc9fdfa835afc75afd3d8e0c Mon Sep 17 00:00:00 2001 From: ClauCarloni Date: Wed, 20 Oct 2021 12:03:39 +0200 Subject: [PATCH 4/7] Adding updated version of file 02 --- 02_Further_questions.ipynb | 220 ++++++++++++++++++++++++++++++++----- 1 file changed, 190 insertions(+), 30 deletions(-) diff --git a/02_Further_questions.ipynb b/02_Further_questions.ipynb index 135976f..d3e7dfd 100644 --- a/02_Further_questions.ipynb +++ b/02_Further_questions.ipynb @@ -84,7 +84,7 @@ { "cell_type": "code", "execution_count": 37, - "id": "95c39303", + "id": "4c5a2905", "metadata": {}, "outputs": [ { @@ -115,7 +115,7 @@ { "cell_type": "code", "execution_count": 28, - "id": "3bc0b3a9", + "id": "ffbf71e4", "metadata": {}, "outputs": [ { @@ -137,7 +137,7 @@ { "cell_type": "code", "execution_count": 54, - "id": "4639eed6", + "id": "e09f59ea", "metadata": {}, "outputs": [], "source": [ @@ -155,7 +155,7 @@ { "cell_type": "code", "execution_count": 55, - "id": "95ccd4f6", + "id": "3c9b8924", "metadata": {}, "outputs": [ { @@ -267,7 +267,7 @@ { "cell_type": "code", "execution_count": 57, - "id": "2bcc0343", + "id": "25846b16", "metadata": {}, "outputs": [ { @@ -289,7 +289,7 @@ { "cell_type": "code", "execution_count": 58, - "id": "8d5778d2", + "id": "9404fea2", "metadata": {}, "outputs": [], "source": [ @@ -299,7 +299,7 @@ { "cell_type": "code", "execution_count": 80, - "id": "df61ca56", + "id": "46bdeac2", "metadata": {}, "outputs": [ { @@ -328,7 +328,7 @@ }, { "cell_type": "code", - "execution_count": 81, + "execution_count": 103, "id": "starting-blackberry", "metadata": {}, "outputs": [], @@ -338,8 +338,8 @@ }, { "cell_type": "code", - "execution_count": 82, - "id": "1b1d7936", + "execution_count": 104, + "id": "6af1258d", "metadata": {}, "outputs": [ { @@ -348,7 +348,7 @@ "200" ] }, - "execution_count": 82, + "execution_count": 104, "metadata": {}, "output_type": "execute_result" } @@ -360,8 +360,8 @@ }, { "cell_type": "code", - "execution_count": 83, - "id": "6c021c42", + "execution_count": 105, + "id": "65bce5bf", "metadata": {}, "outputs": [], "source": [ @@ -370,16 +370,28 @@ }, { "cell_type": "code", - "execution_count": 95, - "id": "5dd15661", + "execution_count": 151, + "id": "84c4d9de", "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "['Arnoldo jimenez', 'Jason derek brown', 'Alexis flores', 'Jose rodolfo villarreal hernandez', 'Octaviano juarez corro', 'Eugene palmer', 'Rafael caro quintero', 'Bhadreshkumar chetanbhai patel', 'Alejandro castillo', 'Robert william fisher']\n" - ] + "data": { + "text/plain": [ + "['arnoldo jimenez',\n", + " 'jason derek brown',\n", + " 'alexis flores',\n", + " 'jose rodolfo villarreal hernandez',\n", + " 'octaviano juarez corro',\n", + " 'eugene palmer',\n", + " 'rafael caro quintero',\n", + " 'bhadreshkumar chetanbhai patel',\n", + " 'alejandro castillo',\n", + " 'robert william fisher']" + ] + }, + "execution_count": 151, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ @@ -387,10 +399,158 @@ "pre = soup.find_all('li', attrs={'class': 'portal-type-person castle-grid-block-item'})\n", "\n", "for i, c in enumerate(pre):\n", - " wanted.append(c.find('a').get('href').split('/')[-1].replace('-',' ').capitalize())\n", + " wanted.append(c.find('a').get('href').split('/')[-1].replace('-',' '))\n", " x = i+1\n", + " \n", + "wanted" + ] + }, + { + "cell_type": "code", + "execution_count": 149, + "id": "6eb52ba0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Arnoldo Jimenez',\n", + " 'Jason Derek Brown',\n", + " 'Alexis Flores',\n", + " 'Jose Rodolfo Villarreal Hernandez',\n", + " 'Octaviano Juarez Corro',\n", + " 'Eugene Palmer',\n", + " 'Rafael Caro Quintero',\n", + " 'Bhadreshkumar Chetanbhai Patel',\n", + " 'Alejandro Castillo',\n", + " 'Robert William Fisher']" + ] + }, + "execution_count": 149, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "temp = []\n", + "temp2 = []\n", + "temp3 = []\n", + "\n", + "for w in wanted:\n", + " w = w.split(' ')\n", + " temp.append(w)\n", "\n", - "print(wanted)\n" + "for a in temp:\n", + " newa = []\n", + " for b in a:\n", + " b = b.capitalize()\n", + " newa.append(b)\n", + " temp2.append(newa)\n", + " \n", + "for item in temp2:\n", + " t = ' '.join(item)\n", + " temp3.append(t)\n", + " \n", + "temp3" + ] + }, + { + "cell_type": "code", + "execution_count": 161, + "id": "352f3537", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Name
1Arnoldo Jimenez
2Jason Derek Brown
3Alexis Flores
4Jose Rodolfo Villarreal Hernandez
5Octaviano Juarez Corro
6Eugene Palmer
7Rafael Caro Quintero
8Bhadreshkumar Chetanbhai Patel
9Alejandro Castillo
10Robert William Fisher
\n", + "
" + ], + "text/plain": [ + " Name\n", + "1 Arnoldo Jimenez\n", + "2 Jason Derek Brown\n", + "3 Alexis Flores\n", + "4 Jose Rodolfo Villarreal Hernandez\n", + "5 Octaviano Juarez Corro\n", + "6 Eugene Palmer\n", + "7 Rafael Caro Quintero\n", + "8 Bhadreshkumar Chetanbhai Patel\n", + "9 Alejandro Castillo\n", + "10 Robert William Fisher" + ] + }, + "execution_count": 161, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "topwanted = pd.DataFrame(temp3, index = list(range(1,11)), columns = ['Name'])\n", + "topwanted" ] }, { @@ -414,7 +574,7 @@ { "cell_type": "code", "execution_count": 97, - "id": "d15989b7", + "id": "0ca8bb98", "metadata": {}, "outputs": [ { @@ -436,7 +596,7 @@ { "cell_type": "code", "execution_count": 98, - "id": "85cd3c87", + "id": "4265cb99", "metadata": {}, "outputs": [], "source": [ @@ -464,7 +624,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a0f9d350", + "id": "42582010", "metadata": {}, "outputs": [], "source": [ @@ -475,7 +635,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d7f371f1", + "id": "94b41193", "metadata": {}, "outputs": [], "source": [ @@ -503,7 +663,7 @@ { "cell_type": "code", "execution_count": null, - "id": "42e312fd", + "id": "ccbd559e", "metadata": {}, "outputs": [], "source": [ @@ -514,7 +674,7 @@ { "cell_type": "code", "execution_count": null, - "id": "07d043d0", + "id": "14222574", "metadata": {}, "outputs": [], "source": [ @@ -542,7 +702,7 @@ { "cell_type": "code", "execution_count": null, - "id": "6b2cda87", + "id": "e455cf31", "metadata": {}, "outputs": [], "source": [ @@ -553,7 +713,7 @@ { "cell_type": "code", "execution_count": null, - "id": "62ff13a7", + "id": "439da608", "metadata": {}, "outputs": [], "source": [ From 19efa70cbd98ee7450e171304993791377d65fb8 Mon Sep 17 00:00:00 2001 From: ClauCarloni Date: Wed, 20 Oct 2021 15:39:16 +0200 Subject: [PATCH 5/7] Adding updated version of file 02 --- 02_Further_questions.ipynb | 407 ++++++++++++++++++++++++++++++++++--- 1 file changed, 381 insertions(+), 26 deletions(-) diff --git a/02_Further_questions.ipynb b/02_Further_questions.ipynb index d3e7dfd..253a65e 100644 --- a/02_Further_questions.ipynb +++ b/02_Further_questions.ipynb @@ -21,14 +21,15 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 218, "id": "ebcadb1b", "metadata": {}, "outputs": [], "source": [ "from bs4 import BeautifulSoup\n", "import requests\n", - "import pandas as pd" + "import pandas as pd\n", + "import dateutil.parser as dparser" ] }, { @@ -84,7 +85,7 @@ { "cell_type": "code", "execution_count": 37, - "id": "4c5a2905", + "id": "b2d8c687", "metadata": {}, "outputs": [ { @@ -115,7 +116,7 @@ { "cell_type": "code", "execution_count": 28, - "id": "ffbf71e4", + "id": "b2243b31", "metadata": {}, "outputs": [ { @@ -137,7 +138,7 @@ { "cell_type": "code", "execution_count": 54, - "id": "e09f59ea", + "id": "2f8bcf8f", "metadata": {}, "outputs": [], "source": [ @@ -155,7 +156,7 @@ { "cell_type": "code", "execution_count": 55, - "id": "3c9b8924", + "id": "e4dfc6be", "metadata": {}, "outputs": [ { @@ -267,7 +268,7 @@ { "cell_type": "code", "execution_count": 57, - "id": "25846b16", + "id": "8fbdcb03", "metadata": {}, "outputs": [ { @@ -289,7 +290,7 @@ { "cell_type": "code", "execution_count": 58, - "id": "9404fea2", + "id": "ea0eb3a2", "metadata": {}, "outputs": [], "source": [ @@ -299,7 +300,7 @@ { "cell_type": "code", "execution_count": 80, - "id": "46bdeac2", + "id": "4c1d3a5a", "metadata": {}, "outputs": [ { @@ -339,7 +340,7 @@ { "cell_type": "code", "execution_count": 104, - "id": "6af1258d", + "id": "d3d6c445", "metadata": {}, "outputs": [ { @@ -361,7 +362,7 @@ { "cell_type": "code", "execution_count": 105, - "id": "65bce5bf", + "id": "224fb793", "metadata": {}, "outputs": [], "source": [ @@ -371,7 +372,7 @@ { "cell_type": "code", "execution_count": 151, - "id": "84c4d9de", + "id": "aec49dc7", "metadata": {}, "outputs": [ { @@ -408,7 +409,7 @@ { "cell_type": "code", "execution_count": 149, - "id": "6eb52ba0", + "id": "9eac58af", "metadata": {}, "outputs": [ { @@ -457,7 +458,7 @@ { "cell_type": "code", "execution_count": 161, - "id": "352f3537", + "id": "fbe8cb04", "metadata": {}, "outputs": [ { @@ -563,7 +564,7 @@ }, { "cell_type": "code", - "execution_count": 96, + "execution_count": 162, "id": "copyrighted-taiwan", "metadata": {}, "outputs": [], @@ -573,8 +574,8 @@ }, { "cell_type": "code", - "execution_count": 97, - "id": "0ca8bb98", + "execution_count": 163, + "id": "f6fb65d3", "metadata": {}, "outputs": [ { @@ -583,7 +584,7 @@ "200" ] }, - "execution_count": 97, + "execution_count": 163, "metadata": {}, "output_type": "execute_result" } @@ -595,14 +596,368 @@ }, { "cell_type": "code", - "execution_count": 98, - "id": "4265cb99", + "execution_count": 164, + "id": "d8fc2cad", "metadata": {}, "outputs": [], "source": [ "soup = BeautifulSoup(response.content, \"html.parser\")" ] }, + { + "cell_type": "code", + "execution_count": 251, + "id": "025d45f5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Date', 'Time', 'Latitude degrees', 'Longitude degrees', 'Region name']" + ] + }, + "execution_count": 251, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "columns = []\n", + "\n", + "header = soup.find_all('th', attrs={'class': 'th2'})\n", + "for d in header:\n", + " columns.append(d.get_text())\n", + "\n", + "columns = ['Date', 'Time', columns[2], columns[3], columns[6][:11]]\n", + "\n", + "columns" + ] + }, + { + "cell_type": "code", + "execution_count": 219, + "id": "0349ac69", + "metadata": { + "scrolled": false + }, + "outputs": [], + "source": [ + "date_time = []\n", + "\n", + "dates = soup.find_all('td', attrs={'class': 'tabev6'})\n", + "for d in dates:\n", + " date_time.append(d.get_text())\n", + "\n", + "date = []\n", + "time = []\n", + "marker = \"hr\"\n", + "\n", + "for d in date_time:\n", + " if marker not in d:\n", + " d2 = dparser.parse(d,fuzzy=True)\n", + " date.append(str(d2)[:10])\n", + " time.append(str(d2)[11:16])\n", + " else: \n", + " d2 = dparser.parse(d.split(\"hr\")[0],fuzzy=True)\n", + " date.append(str(d2)[:10])\n", + " time.append(str(d2)[11:16])" + ] + }, + { + "cell_type": "code", + "execution_count": 237, + "id": "994a845c", + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "latitude = []\n", + "longitude = []\n", + "\n", + "temp4 = soup.find_all('td', attrs={'class': 'tabev1'})\n", + "counter = 1\n", + "for l in temp4:\n", + " if (counter%2 == 0) is True:\n", + " longitude.append(l.get_text()[:5])\n", + " counter += 1\n", + " else:\n", + " latitude.append(l.get_text()[:5])\n", + " counter += 1" + ] + }, + { + "cell_type": "code", + "execution_count": 241, + "id": "2ee678e0", + "metadata": {}, + "outputs": [], + "source": [ + "region = []\n", + "\n", + "temp5 = soup.find_all('td', attrs={'class': 'tb_region'})\n", + "for r in temp5:\n", + " region.append(r.get_text().replace('\\xa0',''))" + ] + }, + { + "cell_type": "code", + "execution_count": 254, + "id": "351e8403", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
DateTimeLatitude degreesLongitude degreesRegion name
02021-10-2010:0028.5917.85CANARY ISLANDS, SPAIN REGION
12021-10-2009:5828.5617.83CANARY ISLANDS, SPAIN REGION
22021-10-2009:5528.5517.85CANARY ISLANDS, SPAIN REGION
32021-10-2009:5428.5617.84CANARY ISLANDS, SPAIN REGION
42021-10-2009:4640.63122.4NORTHERN CALIFORNIA
52021-10-2009:4428.5617.83CANARY ISLANDS, SPAIN REGION
62021-10-2009:2842.429.02SPAIN
72021-10-2009:2640.46175.8NORTH ISLAND OF NEW ZEALAND
82021-10-2009:2628.5817.84CANARY ISLANDS, SPAIN REGION
92021-10-2009:2528.5617.86CANARY ISLANDS, SPAIN REGION
102021-10-2009:2328.5617.87CANARY ISLANDS, SPAIN REGION
112021-10-2009:2137.2520.46IONIAN SEA
122021-10-2009:218.26116.7LOMBOK REGION, INDONESIA
132021-10-2009:2018.6969.41TARAPACA, CHILE
142021-10-2009:1828.5717.83CANARY ISLANDS, SPAIN REGION
152021-10-2009:1847.556.56FRANCE
162021-10-2009:0928.5517.84CANARY ISLANDS, SPAIN REGION
172021-10-2009:0628.5617.84CANARY ISLANDS, SPAIN REGION
182021-10-2008:5828.5717.83CANARY ISLANDS, SPAIN REGION
192021-10-2008:5716.4193.20CHIAPAS, MEXICO
\n", + "
" + ], + "text/plain": [ + " Date Time Latitude degrees Longitude degrees \\\n", + "0 2021-10-20 10:00 28.59 17.85 \n", + "1 2021-10-20 09:58 28.56 17.83 \n", + "2 2021-10-20 09:55 28.55 17.85 \n", + "3 2021-10-20 09:54 28.56 17.84 \n", + "4 2021-10-20 09:46 40.63 122.4 \n", + "5 2021-10-20 09:44 28.56 17.83 \n", + "6 2021-10-20 09:28 42.42 9.02  \n", + "7 2021-10-20 09:26 40.46 175.8 \n", + "8 2021-10-20 09:26 28.58 17.84 \n", + "9 2021-10-20 09:25 28.56 17.86 \n", + "10 2021-10-20 09:23 28.56 17.87 \n", + "11 2021-10-20 09:21 37.25 20.46 \n", + "12 2021-10-20 09:21 8.26  116.7 \n", + "13 2021-10-20 09:20 18.69 69.41 \n", + "14 2021-10-20 09:18 28.57 17.83 \n", + "15 2021-10-20 09:18 47.55 6.56  \n", + "16 2021-10-20 09:09 28.55 17.84 \n", + "17 2021-10-20 09:06 28.56 17.84 \n", + "18 2021-10-20 08:58 28.57 17.83 \n", + "19 2021-10-20 08:57 16.41 93.20 \n", + "\n", + " Region name \n", + "0 CANARY ISLANDS, SPAIN REGION \n", + "1 CANARY ISLANDS, SPAIN REGION \n", + "2 CANARY ISLANDS, SPAIN REGION \n", + "3 CANARY ISLANDS, SPAIN REGION \n", + "4 NORTHERN CALIFORNIA \n", + "5 CANARY ISLANDS, SPAIN REGION \n", + "6 SPAIN \n", + "7 NORTH ISLAND OF NEW ZEALAND \n", + "8 CANARY ISLANDS, SPAIN REGION \n", + "9 CANARY ISLANDS, SPAIN REGION \n", + "10 CANARY ISLANDS, SPAIN REGION \n", + "11 IONIAN SEA \n", + "12 LOMBOK REGION, INDONESIA \n", + "13 TARAPACA, CHILE \n", + "14 CANARY ISLANDS, SPAIN REGION \n", + "15 FRANCE \n", + "16 CANARY ISLANDS, SPAIN REGION \n", + "17 CANARY ISLANDS, SPAIN REGION \n", + "18 CANARY ISLANDS, SPAIN REGION \n", + "19 CHIAPAS, MEXICO " + ] + }, + "execution_count": 254, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dct = {'Date': date[:20], 'Time': time[:20], 'Latitude degrees': latitude[:20]\n", + " , 'Longitude degrees': longitude[:20], 'Region name': region[:20]}\n", + "\n", + "earthquakes_info = pd.DataFrame.from_dict(dct)\n", + "earthquakes_info" + ] + }, { "cell_type": "markdown", "id": "dominican-defeat", @@ -624,7 +979,7 @@ { "cell_type": "code", "execution_count": null, - "id": "42582010", + "id": "d450f62c", "metadata": {}, "outputs": [], "source": [ @@ -635,7 +990,7 @@ { "cell_type": "code", "execution_count": null, - "id": "94b41193", + "id": "a3584a1c", "metadata": {}, "outputs": [], "source": [ @@ -663,7 +1018,7 @@ { "cell_type": "code", "execution_count": null, - "id": "ccbd559e", + "id": "470a6c2a", "metadata": {}, "outputs": [], "source": [ @@ -674,7 +1029,7 @@ { "cell_type": "code", "execution_count": null, - "id": "14222574", + "id": "7f9e0ebd", "metadata": {}, "outputs": [], "source": [ @@ -702,7 +1057,7 @@ { "cell_type": "code", "execution_count": null, - "id": "e455cf31", + "id": "b537aa05", "metadata": {}, "outputs": [], "source": [ @@ -713,7 +1068,7 @@ { "cell_type": "code", "execution_count": null, - "id": "439da608", + "id": "15875c1b", "metadata": {}, "outputs": [], "source": [ From e9212ff2f96afb381cf7f0915331642d9e02170b Mon Sep 17 00:00:00 2001 From: ClauCarloni Date: Thu, 21 Oct 2021 16:59:32 +0200 Subject: [PATCH 6/7] Adding updated version of file 02 --- 02_Further_questions.ipynb | 553 ++++++++++++++++++++++++++++++++++--- 1 file changed, 512 insertions(+), 41 deletions(-) diff --git a/02_Further_questions.ipynb b/02_Further_questions.ipynb index 253a65e..165c104 100644 --- a/02_Further_questions.ipynb +++ b/02_Further_questions.ipynb @@ -85,7 +85,7 @@ { "cell_type": "code", "execution_count": 37, - "id": "b2d8c687", + "id": "2deb056c", "metadata": {}, "outputs": [ { @@ -116,7 +116,7 @@ { "cell_type": "code", "execution_count": 28, - "id": "b2243b31", + "id": "5e71e3c9", "metadata": {}, "outputs": [ { @@ -138,7 +138,7 @@ { "cell_type": "code", "execution_count": 54, - "id": "2f8bcf8f", + "id": "3b8662c5", "metadata": {}, "outputs": [], "source": [ @@ -156,7 +156,7 @@ { "cell_type": "code", "execution_count": 55, - "id": "e4dfc6be", + "id": "9739eac1", "metadata": {}, "outputs": [ { @@ -268,7 +268,7 @@ { "cell_type": "code", "execution_count": 57, - "id": "8fbdcb03", + "id": "71b5a7d7", "metadata": {}, "outputs": [ { @@ -290,7 +290,7 @@ { "cell_type": "code", "execution_count": 58, - "id": "ea0eb3a2", + "id": "39d9f386", "metadata": {}, "outputs": [], "source": [ @@ -300,7 +300,7 @@ { "cell_type": "code", "execution_count": 80, - "id": "4c1d3a5a", + "id": "0295ea62", "metadata": {}, "outputs": [ { @@ -340,7 +340,7 @@ { "cell_type": "code", "execution_count": 104, - "id": "d3d6c445", + "id": "4a316a26", "metadata": {}, "outputs": [ { @@ -362,7 +362,7 @@ { "cell_type": "code", "execution_count": 105, - "id": "224fb793", + "id": "0b972913", "metadata": {}, "outputs": [], "source": [ @@ -372,7 +372,7 @@ { "cell_type": "code", "execution_count": 151, - "id": "aec49dc7", + "id": "00e3967f", "metadata": {}, "outputs": [ { @@ -409,7 +409,7 @@ { "cell_type": "code", "execution_count": 149, - "id": "9eac58af", + "id": "ad5d3073", "metadata": {}, "outputs": [ { @@ -458,7 +458,7 @@ { "cell_type": "code", "execution_count": 161, - "id": "fbe8cb04", + "id": "77996fce", "metadata": {}, "outputs": [ { @@ -575,7 +575,7 @@ { "cell_type": "code", "execution_count": 163, - "id": "f6fb65d3", + "id": "9a97d306", "metadata": {}, "outputs": [ { @@ -597,7 +597,7 @@ { "cell_type": "code", "execution_count": 164, - "id": "d8fc2cad", + "id": "ef7cde1e", "metadata": {}, "outputs": [], "source": [ @@ -607,7 +607,7 @@ { "cell_type": "code", "execution_count": 251, - "id": "025d45f5", + "id": "50d3e4af", "metadata": {}, "outputs": [ { @@ -636,7 +636,7 @@ { "cell_type": "code", "execution_count": 219, - "id": "0349ac69", + "id": "2a4fd8bb", "metadata": { "scrolled": false }, @@ -666,7 +666,7 @@ { "cell_type": "code", "execution_count": 237, - "id": "994a845c", + "id": "4a4df35a", "metadata": { "scrolled": true }, @@ -689,7 +689,7 @@ { "cell_type": "code", "execution_count": 241, - "id": "2ee678e0", + "id": "17f0ab41", "metadata": {}, "outputs": [], "source": [ @@ -702,8 +702,8 @@ }, { "cell_type": "code", - "execution_count": 254, - "id": "351e8403", + "execution_count": 258, + "id": "ef99d7ec", "metadata": {}, "outputs": [ { @@ -945,7 +945,7 @@ "19 CHIAPAS, MEXICO " ] }, - "execution_count": 254, + "execution_count": 258, "metadata": {}, "output_type": "execute_result" } @@ -966,9 +966,17 @@ "### List all language names and number of related articles in the order they appear in [wikipedia.org](wikipedia.org)" ] }, + { + "cell_type": "markdown", + "id": "5478e0e1", + "metadata": {}, + "source": [ + "- I couldn't find the place with the number of related articles" + ] + }, { "cell_type": "code", - "execution_count": null, + "execution_count": 255, "id": "metric-vertex", "metadata": {}, "outputs": [], @@ -978,10 +986,23 @@ }, { "cell_type": "code", - "execution_count": null, - "id": "d450f62c", - "metadata": {}, - "outputs": [], + "execution_count": 256, + "id": "bb0d0114", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "200" + ] + }, + "execution_count": 256, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "response = requests.get(url)\n", "response.status_code" @@ -989,14 +1010,156 @@ }, { "cell_type": "code", - "execution_count": null, - "id": "a3584a1c", + "execution_count": 259, + "id": "ded5abd3", "metadata": {}, "outputs": [], "source": [ "soup = BeautifulSoup(response.content, \"html.parser\")" ] }, + { + "cell_type": "code", + "execution_count": 277, + "id": "a7bf3eef", + "metadata": {}, + "outputs": [], + "source": [ + "langs = []\n", + "temp6 = soup.find_all('select', attrs={'id': 'searchLanguage'})\n", + "\n", + "for r in temp6:\n", + " langs.append(r.get_text().replace('/','').split())\n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 280, + "id": "49fdcb62", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Number of languages on Wikipedia: 86\n" + ] + } + ], + "source": [ + "print('Number of languages on Wikipedia:', len(langs[0]))" + ] + }, + { + "cell_type": "code", + "execution_count": 289, + "id": "090d18de", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Languages
1Afrikaans
2Polski
3Slovenčina
4العربية
5Asturianu
......
82Winaray
83粵語
84中文
85မြန်မာဘာသာ
86한국어
\n", + "

86 rows × 1 columns

\n", + "
" + ], + "text/plain": [ + " Languages\n", + "1 Afrikaans\n", + "2 Polski\n", + "3 Slovenčina\n", + "4 العربية\n", + "5 Asturianu\n", + ".. ...\n", + "82 Winaray\n", + "83 粵語\n", + "84 中文\n", + "85 မြန်မာဘာသာ\n", + "86 한국어\n", + "\n", + "[86 rows x 1 columns]" + ] + }, + "execution_count": 289, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "num = len(langs[0])+1\n", + "df = pd.DataFrame(langs[0], index = list(range(1,num)), columns = ['Languages'])\n", + "df" + ] + }, { "cell_type": "markdown", "id": "split-cartridge", @@ -1007,20 +1170,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 292, "id": "actual-parallel", "metadata": {}, "outputs": [], "source": [ - "url = 'https://data.gov.uk/" + "url = 'https://data.gov.uk/'" ] }, { "cell_type": "code", - "execution_count": null, - "id": "470a6c2a", + "execution_count": 293, + "id": "47b68055", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "200" + ] + }, + "execution_count": 293, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "response = requests.get(url)\n", "response.status_code" @@ -1028,14 +1202,157 @@ }, { "cell_type": "code", - "execution_count": null, - "id": "7f9e0ebd", + "execution_count": 294, + "id": "b2aabd0c", "metadata": {}, "outputs": [], "source": [ "soup = BeautifulSoup(response.content, \"html.parser\")" ] }, + { + "cell_type": "code", + "execution_count": 295, + "id": "062d4c14", + "metadata": {}, + "outputs": [], + "source": [ + "datasets = []\n", + "temp7 = soup.find_all('a', attrs={'class': 'govuk-link'})\n", + "\n", + "for d in temp7:\n", + " datasets.append(d.get_text())" + ] + }, + { + "cell_type": "code", + "execution_count": 301, + "id": "f8eae011", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Business and economy',\n", + " 'Crime and justice',\n", + " 'Defence',\n", + " 'Education',\n", + " 'Environment',\n", + " 'Government',\n", + " 'Government spending',\n", + " 'Health',\n", + " 'Mapping',\n", + " 'Society',\n", + " 'Towns and cities',\n", + " 'Transport',\n", + " 'Digital service performance',\n", + " 'Government reference data']" + ] + }, + "execution_count": 301, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "datasets = datasets[4:]\n", + "datasets" + ] + }, + { + "cell_type": "code", + "execution_count": 298, + "id": "aba72aea", + "metadata": {}, + "outputs": [], + "source": [ + "subdatasets = []\n", + "temp8 = soup.find_all('p', attrs={'class': 'govuk-body'})\n", + "\n", + "for d in temp8:\n", + " subdatasets.append(d.get_text())" + ] + }, + { + "cell_type": "code", + "execution_count": 302, + "id": "661f68c9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Small businesses, industry, imports, exports and trade',\n", + " 'Courts, police, prison, offenders, borders and immigration',\n", + " 'Armed forces, health and safety, search and rescue',\n", + " 'Students, training, qualifications and the National Curriculum',\n", + " 'Weather, flooding, rivers, air quality, geology and agriculture',\n", + " 'Staff numbers and pay, local councillors and department business plans',\n", + " 'Includes all payments by government departments over £25,000',\n", + " 'Includes smoking, drugs, alcohol, medicine performance and hospitals',\n", + " 'Addresses, boundaries, land ownership, aerial photographs, seabed and land terrain',\n", + " 'Employment, benefits, household finances, poverty and population',\n", + " 'Includes housing, urban planning, leisure, waste and energy, consumption',\n", + " 'Airports, roads, freight, electric vehicles, parking, buses and footpaths',\n", + " 'Cost, usage, completion rate, digital take-up, satisfaction',\n", + " 'Trusted data that is referenced and shared across government departments']" + ] + }, + "execution_count": 302, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "subdatasets = subdatasets[1:]\n", + "subdatasets" + ] + }, + { + "cell_type": "code", + "execution_count": 305, + "id": "ec49626d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 305, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(datasets) == len(subdatasets)" + ] + }, + { + "cell_type": "code", + "execution_count": 310, + "id": "42eca15e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Business and economy': 'Small businesses, industry, imports, exports and trade', 'Crime and justice': 'Courts, police, prison, offenders, borders and immigration', 'Defence': 'Armed forces, health and safety, search and rescue', 'Education': 'Students, training, qualifications and the National Curriculum', 'Environment': 'Weather, flooding, rivers, air quality, geology and agriculture', 'Government': 'Staff numbers and pay, local councillors and department business plans', 'Government spending': 'Includes all payments by government departments over £25,000', 'Health': 'Includes smoking, drugs, alcohol, medicine performance and hospitals', 'Mapping': 'Addresses, boundaries, land ownership, aerial photographs, seabed and land terrain', 'Society': 'Employment, benefits, household finances, poverty and population', 'Towns and cities': 'Includes housing, urban planning, leisure, waste and energy, consumption', 'Transport': 'Airports, roads, freight, electric vehicles, parking, buses and footpaths', 'Digital service performance': 'Cost, usage, completion rate, digital take-up, satisfaction', 'Government reference data': 'Trusted data that is referenced and shared across government departments'}\n" + ] + } + ], + "source": [ + "#Get pairs of elements\n", + "zip_iterator = zip(datasets, subdatasets)\n", + "\n", + "#Convert to dictionary\n", + "a_dictionary = dict(zip_iterator)\n", + "\n", + "print(a_dictionary)" + ] + }, { "cell_type": "markdown", "id": "potential-malpractice", @@ -1046,7 +1363,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 311, "id": "adaptive-calculator", "metadata": {}, "outputs": [], @@ -1056,10 +1373,21 @@ }, { "cell_type": "code", - "execution_count": null, - "id": "b537aa05", + "execution_count": 312, + "id": "1053e2b6", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "200" + ] + }, + "execution_count": 312, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "response = requests.get(url)\n", "response.status_code" @@ -1067,13 +1395,156 @@ }, { "cell_type": "code", - "execution_count": null, - "id": "15875c1b", + "execution_count": 313, + "id": "c9f5f643", "metadata": {}, "outputs": [], "source": [ "soup = BeautifulSoup(response.content, \"html.parser\")" ] + }, + { + "cell_type": "code", + "execution_count": 320, + "id": "c9e327db", + "metadata": {}, + "outputs": [], + "source": [ + "rank = []\n", + "language = []\n", + "speakers = []\n", + "\n", + "ranktemp = soup.find_all('tr')\n", + "\n", + "for r in ranktemp:\n", + " rank.append(r.get_text().split('\\n'))" + ] + }, + { + "cell_type": "code", + "execution_count": 325, + "id": "068f9167", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['This section needs to be updated. Please help update this article to reflect recent events or newly available information. (December 2020)']" + ] + }, + "execution_count": 325, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rank[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 324, + "id": "fbff8513", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['See also', 'Lists of languages', 'Category:Languages', '']" + ] + }, + "execution_count": 324, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rank[-1]" + ] + }, + { + "cell_type": "code", + "execution_count": 326, + "id": "3273cc0a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "214" + ] + }, + "execution_count": 326, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(rank)" + ] + }, + { + "cell_type": "code", + "execution_count": 335, + "id": "f81f3dcd", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['',\n", + " '91',\n", + " '',\n", + " 'Sylheti',\n", + " '',\n", + " '10.3',\n", + " '',\n", + " '0.134%',\n", + " '',\n", + " 'Indo-European',\n", + " '',\n", + " 'Indo-Aryan',\n", + " '']" + ] + }, + "execution_count": 335, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rank[92]" + ] + }, + { + "cell_type": "code", + "execution_count": 336, + "id": "e5038f82", + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "1 columns passed, passed data had 13 columns", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mAssertionError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\pandas\\core\\internals\\construction.py\u001b[0m in \u001b[0;36m_list_to_arrays\u001b[1;34m(data, columns, coerce_float, dtype)\u001b[0m\n\u001b[0;32m 567\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 568\u001b[1;33m \u001b[0mcolumns\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_validate_or_indexify_columns\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcontent\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcolumns\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 569\u001b[0m \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_convert_object_array\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcontent\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcoerce_float\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcoerce_float\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\pandas\\core\\internals\\construction.py\u001b[0m in \u001b[0;36m_validate_or_indexify_columns\u001b[1;34m(content, columns)\u001b[0m\n\u001b[0;32m 691\u001b[0m \u001b[1;31m# caller's responsibility to check for this...\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 692\u001b[1;33m raise AssertionError(\n\u001b[0m\u001b[0;32m 693\u001b[0m \u001b[1;34mf\"{len(columns)} columns passed, passed data had \"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mAssertionError\u001b[0m: 1 columns passed, passed data had 13 columns", + "\nThe above exception was the direct cause of the following exception:\n", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mdf\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mDataFrame\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mrank\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;36m92\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mrank\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\pandas\\core\\frame.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, data, index, columns, dtype, copy)\u001b[0m\n\u001b[0;32m 568\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mis_named_tuple\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mcolumns\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 569\u001b[0m \u001b[0mcolumns\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_fields\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 570\u001b[1;33m \u001b[0marrays\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcolumns\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mto_arrays\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcolumns\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 571\u001b[0m \u001b[0mcolumns\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mensure_index\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 572\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\pandas\\core\\internals\\construction.py\u001b[0m in \u001b[0;36mto_arrays\u001b[1;34m(data, columns, coerce_float, dtype)\u001b[0m\n\u001b[0;32m 526\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;31m# columns if columns is not None else []\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 527\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mlist\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtuple\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 528\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0m_list_to_arrays\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcolumns\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcoerce_float\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcoerce_float\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 529\u001b[0m \u001b[1;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mabc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mMapping\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 530\u001b[0m return _list_of_dict_to_arrays(\n", + "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\pandas\\core\\internals\\construction.py\u001b[0m in \u001b[0;36m_list_to_arrays\u001b[1;34m(data, columns, coerce_float, dtype)\u001b[0m\n\u001b[0;32m 569\u001b[0m \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_convert_object_array\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcontent\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcoerce_float\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcoerce_float\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 570\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mAssertionError\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 571\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0me\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 572\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcolumns\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 573\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mValueError\u001b[0m: 1 columns passed, passed data had 13 columns" + ] + } + ], + "source": [ + "df = pd.DataFrame(rank[1:92],columns=rank[0])" + ] } ], "metadata": { From 2298f49b6be2dc0173efc36ab8a5587c8aeff261 Mon Sep 17 00:00:00 2001 From: ClauCarloni Date: Thu, 21 Oct 2021 20:42:52 +0200 Subject: [PATCH 7/7] Adding updated version of file 02 --- 02_Further_questions.ipynb | 90 +++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 41 deletions(-) diff --git a/02_Further_questions.ipynb b/02_Further_questions.ipynb index 165c104..9105692 100644 --- a/02_Further_questions.ipynb +++ b/02_Further_questions.ipynb @@ -85,7 +85,7 @@ { "cell_type": "code", "execution_count": 37, - "id": "2deb056c", + "id": "318eca02", "metadata": {}, "outputs": [ { @@ -116,7 +116,7 @@ { "cell_type": "code", "execution_count": 28, - "id": "5e71e3c9", + "id": "bc17895c", "metadata": {}, "outputs": [ { @@ -138,7 +138,7 @@ { "cell_type": "code", "execution_count": 54, - "id": "3b8662c5", + "id": "854fb881", "metadata": {}, "outputs": [], "source": [ @@ -156,7 +156,7 @@ { "cell_type": "code", "execution_count": 55, - "id": "9739eac1", + "id": "9204697d", "metadata": {}, "outputs": [ { @@ -268,7 +268,7 @@ { "cell_type": "code", "execution_count": 57, - "id": "71b5a7d7", + "id": "e8904fdc", "metadata": {}, "outputs": [ { @@ -290,7 +290,7 @@ { "cell_type": "code", "execution_count": 58, - "id": "39d9f386", + "id": "43e37d27", "metadata": {}, "outputs": [], "source": [ @@ -300,7 +300,7 @@ { "cell_type": "code", "execution_count": 80, - "id": "0295ea62", + "id": "d65d5e18", "metadata": {}, "outputs": [ { @@ -340,7 +340,7 @@ { "cell_type": "code", "execution_count": 104, - "id": "4a316a26", + "id": "f5138323", "metadata": {}, "outputs": [ { @@ -362,7 +362,7 @@ { "cell_type": "code", "execution_count": 105, - "id": "0b972913", + "id": "0c5ab86d", "metadata": {}, "outputs": [], "source": [ @@ -372,7 +372,7 @@ { "cell_type": "code", "execution_count": 151, - "id": "00e3967f", + "id": "b29f2f4f", "metadata": {}, "outputs": [ { @@ -409,7 +409,7 @@ { "cell_type": "code", "execution_count": 149, - "id": "ad5d3073", + "id": "8b14afed", "metadata": {}, "outputs": [ { @@ -458,7 +458,7 @@ { "cell_type": "code", "execution_count": 161, - "id": "77996fce", + "id": "dab0cd97", "metadata": {}, "outputs": [ { @@ -575,7 +575,7 @@ { "cell_type": "code", "execution_count": 163, - "id": "9a97d306", + "id": "be4ff9bb", "metadata": {}, "outputs": [ { @@ -597,7 +597,7 @@ { "cell_type": "code", "execution_count": 164, - "id": "ef7cde1e", + "id": "cb40a40f", "metadata": {}, "outputs": [], "source": [ @@ -607,7 +607,7 @@ { "cell_type": "code", "execution_count": 251, - "id": "50d3e4af", + "id": "d4529b73", "metadata": {}, "outputs": [ { @@ -636,7 +636,7 @@ { "cell_type": "code", "execution_count": 219, - "id": "2a4fd8bb", + "id": "4cc71690", "metadata": { "scrolled": false }, @@ -666,7 +666,7 @@ { "cell_type": "code", "execution_count": 237, - "id": "4a4df35a", + "id": "838e55b0", "metadata": { "scrolled": true }, @@ -689,7 +689,7 @@ { "cell_type": "code", "execution_count": 241, - "id": "17f0ab41", + "id": "08f5f323", "metadata": {}, "outputs": [], "source": [ @@ -703,7 +703,7 @@ { "cell_type": "code", "execution_count": 258, - "id": "ef99d7ec", + "id": "7b4f01f5", "metadata": {}, "outputs": [ { @@ -968,7 +968,7 @@ }, { "cell_type": "markdown", - "id": "5478e0e1", + "id": "b58e3972", "metadata": {}, "source": [ "- I couldn't find the place with the number of related articles" @@ -987,7 +987,7 @@ { "cell_type": "code", "execution_count": 256, - "id": "bb0d0114", + "id": "866e9676", "metadata": { "scrolled": true }, @@ -1011,7 +1011,7 @@ { "cell_type": "code", "execution_count": 259, - "id": "ded5abd3", + "id": "101cf814", "metadata": {}, "outputs": [], "source": [ @@ -1021,7 +1021,7 @@ { "cell_type": "code", "execution_count": 277, - "id": "a7bf3eef", + "id": "8d42443c", "metadata": {}, "outputs": [], "source": [ @@ -1037,7 +1037,7 @@ { "cell_type": "code", "execution_count": 280, - "id": "49fdcb62", + "id": "b229b82a", "metadata": {}, "outputs": [ { @@ -1055,7 +1055,7 @@ { "cell_type": "code", "execution_count": 289, - "id": "090d18de", + "id": "c9bc8877", "metadata": {}, "outputs": [ { @@ -1181,7 +1181,7 @@ { "cell_type": "code", "execution_count": 293, - "id": "47b68055", + "id": "69fa6622", "metadata": {}, "outputs": [ { @@ -1203,7 +1203,7 @@ { "cell_type": "code", "execution_count": 294, - "id": "b2aabd0c", + "id": "6f3df064", "metadata": {}, "outputs": [], "source": [ @@ -1213,7 +1213,7 @@ { "cell_type": "code", "execution_count": 295, - "id": "062d4c14", + "id": "4aac849d", "metadata": {}, "outputs": [], "source": [ @@ -1227,7 +1227,7 @@ { "cell_type": "code", "execution_count": 301, - "id": "f8eae011", + "id": "0fa73b55", "metadata": {}, "outputs": [ { @@ -1262,7 +1262,7 @@ { "cell_type": "code", "execution_count": 298, - "id": "aba72aea", + "id": "3b078678", "metadata": {}, "outputs": [], "source": [ @@ -1276,7 +1276,7 @@ { "cell_type": "code", "execution_count": 302, - "id": "661f68c9", + "id": "be374b22", "metadata": {}, "outputs": [ { @@ -1311,7 +1311,7 @@ { "cell_type": "code", "execution_count": 305, - "id": "ec49626d", + "id": "45b748d5", "metadata": {}, "outputs": [ { @@ -1332,7 +1332,7 @@ { "cell_type": "code", "execution_count": 310, - "id": "42eca15e", + "id": "106b2812", "metadata": {}, "outputs": [ { @@ -1361,6 +1361,14 @@ "### Display the top 10 languages by number of native speakers stored in a pandas dataframe" ] }, + { + "cell_type": "markdown", + "id": "3cc62660", + "metadata": {}, + "source": [ + "- On this question the outout I got from the parser was a nested list where I would have all the rows I need. But I couldn't make a script to read it bc in some point the spacement changes. That's why I have the error at the final line. As I'm late with other labs and I think I got the idea of this one I'm leaving it behind." + ] + }, { "cell_type": "code", "execution_count": 311, @@ -1374,7 +1382,7 @@ { "cell_type": "code", "execution_count": 312, - "id": "1053e2b6", + "id": "cd25c104", "metadata": {}, "outputs": [ { @@ -1396,7 +1404,7 @@ { "cell_type": "code", "execution_count": 313, - "id": "c9f5f643", + "id": "e999249f", "metadata": {}, "outputs": [], "source": [ @@ -1406,7 +1414,7 @@ { "cell_type": "code", "execution_count": 320, - "id": "c9e327db", + "id": "3bfacc39", "metadata": {}, "outputs": [], "source": [ @@ -1423,7 +1431,7 @@ { "cell_type": "code", "execution_count": 325, - "id": "068f9167", + "id": "6e766257", "metadata": {}, "outputs": [ { @@ -1444,7 +1452,7 @@ { "cell_type": "code", "execution_count": 324, - "id": "fbff8513", + "id": "5647ed6f", "metadata": {}, "outputs": [ { @@ -1465,7 +1473,7 @@ { "cell_type": "code", "execution_count": 326, - "id": "3273cc0a", + "id": "e3ec0a86", "metadata": {}, "outputs": [ { @@ -1486,7 +1494,7 @@ { "cell_type": "code", "execution_count": 335, - "id": "f81f3dcd", + "id": "1138fd89", "metadata": {}, "outputs": [ { @@ -1519,7 +1527,7 @@ { "cell_type": "code", "execution_count": 336, - "id": "e5038f82", + "id": "d7a352f3", "metadata": {}, "outputs": [ {