From a0814e2af9669893c68d9161b3b82b7db598bdba Mon Sep 17 00:00:00 2001 From: Oriol Codina Vallori Date: Sun, 29 Oct 2023 20:46:49 +0100 Subject: [PATCH] lab done --- data/bible_with_verse_text.csv | 28 ++ data/madrid_forecast.csv | 49 +++ data/monthly_dog_facts.csv | 11 + your-code/challenge-1.ipynb | 372 ++++++++++++++++-- your-code/challenge-2.ipynb | 682 ++++++++++++++++++++++++++++++++- your-code/challenge-3.ipynb | 297 +++++++++++++- 6 files changed, 1374 insertions(+), 65 deletions(-) create mode 100644 data/bible_with_verse_text.csv create mode 100644 data/madrid_forecast.csv create mode 100644 data/monthly_dog_facts.csv diff --git a/data/bible_with_verse_text.csv b/data/bible_with_verse_text.csv new file mode 100644 index 0000000..1a54695 --- /dev/null +++ b/data/bible_with_verse_text.csv @@ -0,0 +1,28 @@ +Name,Role,Book,Chapter,Verse,Text +Adam,First Man,Genesis,1,1,"In the beginning, God created the heavens and the earth." +Eve,First Woman,Genesis,22,5,"Abraham said to his young men, “Stay here with the donkey. The boy and I will go yonder. We will worship, and come back to you.”" +Noah,Builder of the Ark,Genesis,12,10,"There was a famine in the land. Abram went down into Egypt to live as a foreigner there, for the famine was severe in the land." +Abraham,Father of Nations,Genesis,6,15,"This is how you shall make it. The length of the ship shall be three hundred cubits, its width fifty cubits, and its height thirty cubits." +Sarah,Wife of Abraham,Genesis,28,2,"Arise, go to Paddan Aram, to the house of Bethuel your mother’s father. Take a wife from there from the daughters of Laban, your mother’s brother." +Moses,Leader of the Exodus,Exodus,2,3,"When she could no longer hide him, she took a papyrus basket for him, and coated it with tar and with pitch. She put the child in it, and laid it in the reeds by the river’s bank." +Aaron,Brother of Moses,Exodus,13,8,"You shall tell your son in that day, saying, ‘It is because of that which Yahweh did for me when I came out of Egypt.’" +David,King of Israel,1 Samuel,8,4,Then all the elders of Israel gathered themselves together and came to Samuel to Ramah. +Solomon,Wisest Man,Proverbs,12,9,"Better is he who is little know, and has a servant, +than he who honors himself, and lacks bread." +Isaiah,Prophet,Isaiah,4,6,"There will be a pavilion for a shade in the daytime from the heat, and for a refuge and for a shelter from storm and from rain." +Jeremiah,Prophet,Jeremiah,3,16,"It will come to pass, when you are multiplied and increased in the land, in those days,” says Yahweh, “they will no longer say, ‘the ark of Yahweh’s covenant!’ It will not come to mind. They won’t remember it. They won’t miss it, nor will another be made." +John the Baptist,Forerunner of Jesus,Matthew,12,5,"Or have you not read in the law, that on the Sabbath day, the priests in the temple profane the Sabbath, and are guiltless?" +Jesus Christ,Son of God,Matthew,5,10,"Blessed are those who have been persecuted for righteousness’ sake, + +for theirs is the Kingdom of Heaven." +Mary,Mother of Jesus,Luke,6,15,"Matthew; Thomas; James, the son of Alphaeus; Simon, who was called the Zealot;" +Peter,Apostle,Matthew,4,2,"When he had fasted forty days and forty nights, he was hungry afterward." +Andrew,Apostle,Matthew,3,3,Request did not work properly +James the Greater,Apostle,Matthew,5,8,Request did not work properly +John the Evangelist,Apostle,John,3,4,Request did not work properly +Philip,Apostle,Matthew,6,9,Request did not work properly +Thomas,Apostle,Matthew,4,6,Request did not work properly +James the Lesser,Apostle,Matthew,18,9,Request did not work properly +Jude Thaddeus,Apostle,Matthew,9,12,Request did not work properly +Simon the Zealot,Apostle,Matthew,27,3,Request did not work properly +Bartholomew,Apostle,Matthew,6,2,Request did not work properly diff --git a/data/madrid_forecast.csv b/data/madrid_forecast.csv new file mode 100644 index 0000000..afbbe71 --- /dev/null +++ b/data/madrid_forecast.csv @@ -0,0 +1,49 @@ +cloudBase,cloudCeiling,cloudCover,dewPoint,evapotranspiration,freezingRainIntensity,humidity,iceAccumulation,iceAccumulationLwe,precipitationProbability,pressureSurfaceLevel,rainAccumulation,rainAccumulationLwe,rainIntensity,sleetAccumulation,sleetAccumulationLwe,sleetIntensity,snowAccumulation,snowAccumulationLwe,snowIntensity,temperature,temperatureApparent,uvHealthConcern,uvIndex,visibility,weatherCode,windDirection,windGust,windSpeed,time,location +0.37,,48,11.0,0.039,0,82,0,0,0,933.54,0.0,0.0,0.0,0,0,0,0,0,0,13.88,13.88,0,0,9.99,1101,199.63,9.13,4.63,2023-10-28T20:00:00Z,"Madrid, Comunidad de Madrid, España" +0.37,,44,11.0,0.036,0,82,0,0,0,933.51,0.0,0.0,0.0,0,0,0,0,0,0,13.88,13.88,0,0,9.07,1101,190.13,8.88,4.38,2023-10-28T21:00:00Z,"Madrid, Comunidad de Madrid, España" +0.38,0.38,75,10.88,0.036,0,82,0,0,0,933.78,0.51,0.51,0.0,0,0,0,0,0,0,13.88,13.88,0,0,10.24,1001,179.0,8.81,4.38,2023-10-28T22:00:00Z,"Madrid, Comunidad de Madrid, España" +0.13,0.13,75,11.88,0.034,0,93,0,0,0,933.73,0.0,0.0,0.0,0,0,0,0,0,0,13.0,13.0,0,0,13.42,1001,239.5,10.5,4.13,2023-10-28T23:00:00Z,"Madrid, Comunidad de Madrid, España" +0.13,0.13,75,11.88,0.032,0,93,0,0,0,933.3,0.0,0.0,0.0,0,0,0,0,0,0,13.0,13.0,0,0,9.99,1001,198.13,11.38,4.81,2023-10-29T00:00:00Z,"Madrid, Comunidad de Madrid, España" +0.12,0.12,97,11.88,0.024,0,94,0,0,0,933.36,0.0,0.0,0.0,0,0,0,0,0,0,12.88,12.88,0,0,9.82,1001,177.81,10.63,4.38,2023-10-29T01:00:00Z,"Madrid, Comunidad de Madrid, España" +0.24,0.24,97,11.0,0.027,0,88,0,0,0,932.98,0.0,0.0,0.0,0,0,0,0,0,0,12.88,12.88,0,0,9.99,1001,188.88,9.5,3.69,2023-10-29T02:00:00Z,"Madrid, Comunidad de Madrid, España" +0.12,0.12,97,11.88,0.027,0,94,0,0,0,932.48,0.0,0.0,0.0,0,0,0,0,0,0,12.88,12.88,0,0,9.99,1001,188.63,10.63,3.81,2023-10-29T03:00:00Z,"Madrid, Comunidad de Madrid, España" +0.24,0.24,97,11.0,0.026,0,88,0,0,0,932.22,0.0,0.0,0.0,0,0,0,0,0,0,13.0,13.0,0,0,10.54,1001,198.63,10.38,4.81,2023-10-29T04:00:00Z,"Madrid, Comunidad de Madrid, España" +0.23,0.23,94,11.0,0.025,0,89,0,0,0,932.46,0.0,0.0,0.0,0,0,0,0,0,0,12.88,12.88,0,0,11.15,1001,178.0,10.69,3.81,2023-10-29T05:00:00Z,"Madrid, Comunidad de Madrid, España" +0.23,0.23,75,10.88,0.028,0,88,0,0,0,932.18,0.0,0.0,0.0,0,0,0,0,0,0,12.88,12.88,0,0,9.99,1001,169.19,10.63,3.38,2023-10-29T06:00:00Z,"Madrid, Comunidad de Madrid, España" +0.35,0.35,71,10.0,0.031,0,83,0,0,0,932.31,0.0,0.0,0.0,0,0,0,0,0,0,12.81,12.81,0,0,9.99,1102,179.88,9.88,3.19,2023-10-29T07:00:00Z,"Madrid, Comunidad de Madrid, España" +0.35,0.35,75,10.0,0.034,0,83,0,0,0,932.85,0.0,0.0,0.0,0,0,0,0,0,0,12.88,12.88,0,0,9.99,1001,168.69,9.63,3.13,2023-10-29T08:00:00Z,"Madrid, Comunidad de Madrid, España" +0.35,0.35,73,10.13,0.042,0,83,0,0,0,933.44,0.0,0.0,0.0,0,0,0,0,0,0,12.88,12.88,0,0,9.99,1102,175.5,9.19,3.81,2023-10-29T09:00:00Z,"Madrid, Comunidad de Madrid, España" +0.46,0.46,76,10.13,0.095,0,78,0,0,0,932.84,0.0,0.0,0.0,0,0,0,0,0,0,13.81,13.81,0,1,8.19,1001,179.13,12.19,5.19,2023-10-29T10:00:00Z,"Madrid, Comunidad de Madrid, España" +0.44,0.44,76,11.31,0.117,0,79,0,0,0,932.5,0.0,0.0,0.0,0,0,0,0,0,0,14.81,14.81,0,1,10.7,1001,188.13,12.69,6.88,2023-10-29T11:00:00Z,"Madrid, Comunidad de Madrid, España" +0.54,0.54,76,10.38,0.085,0,75,0,0,0,932.1,0.04,0.04,0.0,0,0,0,0,0,0,14.69,14.69,0,1,9.99,1001,205.38,10.81,4.88,2023-10-29T12:00:00Z,"Madrid, Comunidad de Madrid, España" +0.67,0.67,77,10.31,0.069,0,71,0,0,0,931.5,0.0,0.0,0.0,0,0,0,0,0,0,15.69,15.69,0,1,9.99,1001,200.38,10.38,6.5,2023-10-29T13:00:00Z,"Madrid, Comunidad de Madrid, España" +0.63,0.63,76,11.0,0.052,0,72,0,0,0,931.13,0.0,0.0,0.0,0,0,0,0,0,0,15.88,15.88,0,0,8.99,1001,199.88,11.31,4.63,2023-10-29T14:00:00Z,"Madrid, Comunidad de Madrid, España" +0.59,0.59,75,11.19,0.103,0,74,0,0,0,930.47,0.0,0.0,0.0,0,0,0,0,0,0,15.88,15.88,0,0,9.46,1001,197.69,9.81,4.88,2023-10-29T15:00:00Z,"Madrid, Comunidad de Madrid, España" +0.51,0.51,75,11.69,0.031,0,77,0,0,0,930.3,0.0,0.0,0.0,0,0,0,0,0,0,15.81,15.81,0,0,9.88,1001,198.88,8.69,5.69,2023-10-29T16:00:00Z,"Madrid, Comunidad de Madrid, España" +0.27,0.27,75,12.81,0.009,0,87,0,0,0,930.53,0.0,0.0,0.0,0,0,0,0,0,0,15.0,15.0,0,0,9.98,1001,215.38,8.0,2.63,2023-10-29T17:00:00Z,"Madrid, Comunidad de Madrid, España" +0.51,0.51,75,11.81,0.03,0,77,0,0,0,930.75,0.07,0.07,0.0,0,0,0,0,0,0,15.88,15.88,0,0,10.2,1001,181.19,8.69,6.0,2023-10-29T18:00:00Z,"Madrid, Comunidad de Madrid, España" +0.5,0.5,75,10.88,0.023,0,77,0,0,30,931.2,0.63,0.63,0.25,0,0,0,0,0,0,14.88,14.88,0,0,8.98,1001,168.31,8.31,4.69,2023-10-29T19:00:00Z,"Madrid, Comunidad de Madrid, España" +0.37,,48,11.0,0.039,0,82,0,0,0,933.54,0.0,0.0,0.0,0,0,0,0,0,0,13.88,13.88,0,0,9.99,1101,199.63,9.13,4.63,2023-10-28T20:00:00Z,"Madrid, Comunidad de Madrid, España" +0.37,,44,11.0,0.036,0,82,0,0,0,933.51,0.0,0.0,0.0,0,0,0,0,0,0,13.88,13.88,0,0,9.07,1101,190.13,8.88,4.38,2023-10-28T21:00:00Z,"Madrid, Comunidad de Madrid, España" +0.38,0.38,75,10.88,0.036,0,82,0,0,0,933.78,0.51,0.51,0.0,0,0,0,0,0,0,13.88,13.88,0,0,10.24,1001,179.0,8.81,4.38,2023-10-28T22:00:00Z,"Madrid, Comunidad de Madrid, España" +0.13,0.13,75,11.88,0.034,0,93,0,0,0,933.73,0.0,0.0,0.0,0,0,0,0,0,0,13.0,13.0,0,0,13.42,1001,239.5,10.5,4.13,2023-10-28T23:00:00Z,"Madrid, Comunidad de Madrid, España" +0.13,0.13,75,11.88,0.032,0,93,0,0,0,933.3,0.0,0.0,0.0,0,0,0,0,0,0,13.0,13.0,0,0,9.99,1001,198.13,11.38,4.81,2023-10-29T00:00:00Z,"Madrid, Comunidad de Madrid, España" +0.12,0.12,97,11.88,0.024,0,94,0,0,0,933.36,0.0,0.0,0.0,0,0,0,0,0,0,12.88,12.88,0,0,9.82,1001,177.81,10.63,4.38,2023-10-29T01:00:00Z,"Madrid, Comunidad de Madrid, España" +0.24,0.24,97,11.0,0.027,0,88,0,0,0,932.98,0.0,0.0,0.0,0,0,0,0,0,0,12.88,12.88,0,0,9.99,1001,188.88,9.5,3.69,2023-10-29T02:00:00Z,"Madrid, Comunidad de Madrid, España" +0.12,0.12,97,11.88,0.027,0,94,0,0,0,932.48,0.0,0.0,0.0,0,0,0,0,0,0,12.88,12.88,0,0,9.99,1001,188.63,10.63,3.81,2023-10-29T03:00:00Z,"Madrid, Comunidad de Madrid, España" +0.24,0.24,97,11.0,0.026,0,88,0,0,0,932.22,0.0,0.0,0.0,0,0,0,0,0,0,13.0,13.0,0,0,10.54,1001,198.63,10.38,4.81,2023-10-29T04:00:00Z,"Madrid, Comunidad de Madrid, España" +0.23,0.23,94,11.0,0.025,0,89,0,0,0,932.46,0.0,0.0,0.0,0,0,0,0,0,0,12.88,12.88,0,0,11.15,1001,178.0,10.69,3.81,2023-10-29T05:00:00Z,"Madrid, Comunidad de Madrid, España" +0.23,0.23,75,10.88,0.028,0,88,0,0,0,932.18,0.0,0.0,0.0,0,0,0,0,0,0,12.88,12.88,0,0,9.99,1001,169.19,10.63,3.38,2023-10-29T06:00:00Z,"Madrid, Comunidad de Madrid, España" +0.35,0.35,71,10.0,0.031,0,83,0,0,0,932.31,0.0,0.0,0.0,0,0,0,0,0,0,12.81,12.81,0,0,9.99,1102,179.88,9.88,3.19,2023-10-29T07:00:00Z,"Madrid, Comunidad de Madrid, España" +0.35,0.35,75,10.0,0.034,0,83,0,0,0,932.85,0.0,0.0,0.0,0,0,0,0,0,0,12.88,12.88,0,0,9.99,1001,168.69,9.63,3.13,2023-10-29T08:00:00Z,"Madrid, Comunidad de Madrid, España" +0.35,0.35,73,10.13,0.042,0,83,0,0,0,933.44,0.0,0.0,0.0,0,0,0,0,0,0,12.88,12.88,0,0,9.99,1102,175.5,9.19,3.81,2023-10-29T09:00:00Z,"Madrid, Comunidad de Madrid, España" +0.46,0.46,76,10.13,0.095,0,78,0,0,0,932.84,0.0,0.0,0.0,0,0,0,0,0,0,13.81,13.81,0,1,8.19,1001,179.13,12.19,5.19,2023-10-29T10:00:00Z,"Madrid, Comunidad de Madrid, España" +0.44,0.44,76,11.31,0.117,0,79,0,0,0,932.5,0.0,0.0,0.0,0,0,0,0,0,0,14.81,14.81,0,1,10.7,1001,188.13,12.69,6.88,2023-10-29T11:00:00Z,"Madrid, Comunidad de Madrid, España" +0.54,0.54,76,10.38,0.085,0,75,0,0,0,932.1,0.04,0.04,0.0,0,0,0,0,0,0,14.69,14.69,0,1,9.99,1001,205.38,10.81,4.88,2023-10-29T12:00:00Z,"Madrid, Comunidad de Madrid, España" +0.67,0.67,77,10.31,0.069,0,71,0,0,0,931.5,0.0,0.0,0.0,0,0,0,0,0,0,15.69,15.69,0,1,9.99,1001,200.38,10.38,6.5,2023-10-29T13:00:00Z,"Madrid, Comunidad de Madrid, España" +0.63,0.63,76,11.0,0.052,0,72,0,0,0,931.13,0.0,0.0,0.0,0,0,0,0,0,0,15.88,15.88,0,0,8.99,1001,199.88,11.31,4.63,2023-10-29T14:00:00Z,"Madrid, Comunidad de Madrid, España" +0.59,0.59,75,11.19,0.103,0,74,0,0,0,930.47,0.0,0.0,0.0,0,0,0,0,0,0,15.88,15.88,0,0,9.46,1001,197.69,9.81,4.88,2023-10-29T15:00:00Z,"Madrid, Comunidad de Madrid, España" +0.51,0.51,75,11.69,0.031,0,77,0,0,0,930.3,0.0,0.0,0.0,0,0,0,0,0,0,15.81,15.81,0,0,9.88,1001,198.88,8.69,5.69,2023-10-29T16:00:00Z,"Madrid, Comunidad de Madrid, España" +0.27,0.27,75,12.81,0.009,0,87,0,0,0,930.53,0.0,0.0,0.0,0,0,0,0,0,0,15.0,15.0,0,0,9.98,1001,215.38,8.0,2.63,2023-10-29T17:00:00Z,"Madrid, Comunidad de Madrid, España" +0.51,0.51,75,11.81,0.03,0,77,0,0,0,930.75,0.07,0.07,0.0,0,0,0,0,0,0,15.88,15.88,0,0,10.2,1001,181.19,8.69,6.0,2023-10-29T18:00:00Z,"Madrid, Comunidad de Madrid, España" +0.5,0.5,75,10.88,0.023,0,77,0,0,30,931.2,0.63,0.63,0.25,0,0,0,0,0,0,14.88,14.88,0,0,8.98,1001,168.31,8.31,4.69,2023-10-29T19:00:00Z,"Madrid, Comunidad de Madrid, España" diff --git a/data/monthly_dog_facts.csv b/data/monthly_dog_facts.csv new file mode 100644 index 0000000..1b712dd --- /dev/null +++ b/data/monthly_dog_facts.csv @@ -0,0 +1,11 @@ +facts,success +Many foot disorders in dogs are caused by long toenails.,True +"Just like human fingerprints, no two dogs' nose prints are alike.",True +"Two stray dogs in Afghanistan saved 50 American soliders. A Facebook group raised $21,000 to bring the dogs back to the US and reunite them with the soldiers.",True +"The border collie or sheep dog is often considered to be the most intelligent breed of dog some of them have been trained to recognize the words for up to 1,000 objects and retrieved them by verbal command.",True +Male dogs have a bone in their penis.,True +The most popular breed of domestic dog in the US and the UK is the Labrador Retriever.,True +A dog’s vision is not fully developed until after the first month.,True +Dogs are natural pack animals.,True +The Russians trained dogs during WWII to run suicide missions with mines strapped to their backs.,True +"Paul McCartney of the Beatles recorded a high pitched whistle at the end of ""A Day in the Life"" for his dog.",True diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index fee20c4..f6e1717 100644 --- a/your-code/challenge-1.ipynb +++ b/your-code/challenge-1.ipynb @@ -10,11 +10,15 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 106, "id": "215eb6bc", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "import pandas as pd\n", + "import requests\n", + "import datetime" + ] }, { "cell_type": "markdown", @@ -42,34 +46,34 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 107, "id": "8c147eb7", "metadata": {}, "outputs": [], "source": [ - "# Your code here\n", - "# base_url" + "# base_url\n", + "base_url = \"http://dog-api.kinduff.com\"" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 108, "id": "c503211c", "metadata": {}, "outputs": [], "source": [ - "# Your code here\n", - "# endpoint " + "# endpoint \n", + "endpoint = \"/api/facts\"" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 109, "id": "e8563709", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "url_for_request = base_url + endpoint" ] }, { @@ -82,12 +86,25 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 110, "id": "311d0c28", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'facts': ['George Washington had 36 dogs–all Foxhounds–with one named Sweetlips.'],\n", + " 'success': True}" + ] + }, + "execution_count": 110, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "request = requests.get(url_for_request)\n", + "request.json()" ] }, { @@ -110,12 +127,21 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 111, "id": "e7dc2129", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "def request_dog_facts():\n", + " base_url = \"http://dog-api.kinduff.com\"\n", + " endpoint = \"/api/facts\"\n", + " url_for_request = base_url + endpoint\n", + " response = requests.get(url_for_request)\n", + " try:\n", + " response = requests.get(url_for_request)\n", + " return response.json()\n", + " except requests.exceptions.HTTPError as e:\n", + " print(f\"Request failed with status code: {e.response.status_code}\")" ] }, { @@ -136,12 +162,24 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 112, "id": "9263e7c8", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'facts': ['The Labrador Retriever is the #1 favorite breed in the U.S., Canada, and the U.K.'],\n", + " 'success': True}" + ] + }, + "execution_count": 112, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "request_dog_facts()" ] }, { @@ -162,12 +200,36 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 113, "id": "1e7947fe", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Current Month: 10\n", + "Current Month: 27\n" + ] + }, + { + "data": { + "text/plain": [ + "int" + ] + }, + "execution_count": 113, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "current_month = datetime.datetime.now().month\n", + "current_day = datetime.datetime.now().day\n", + "\n", + "print(\"Current Month:\", current_month)\n", + "print(\"Current Month:\", current_day)\n", + "type(current_month)" ] }, { @@ -180,14 +242,51 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 114, "id": "731959ec", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[{'facts': ['Many foot disorders in dogs are caused by long toenails.'],\n", + " 'success': True},\n", + " {'facts': [\"Just like human fingerprints, no two dogs' nose prints are alike.\"],\n", + " 'success': True},\n", + " {'facts': ['Two stray dogs in Afghanistan saved 50 American soliders. A Facebook group raised $21,000 to bring the dogs back to the US and reunite them with the soldiers.'],\n", + " 'success': True},\n", + " {'facts': ['The border collie or sheep dog is often considered to be the most intelligent breed of dog some of them have been trained to recognize the words for up to 1,000 objects and retrieved them by verbal command.'],\n", + " 'success': True},\n", + " {'facts': ['Male dogs have a bone in their penis.'], 'success': True},\n", + " {'facts': ['The most popular breed of domestic dog in the US and the UK is the Labrador Retriever.'],\n", + " 'success': True},\n", + " {'facts': ['A dog’s vision is not fully developed until after the first month.'],\n", + " 'success': True},\n", + " {'facts': ['Dogs are natural pack animals.'], 'success': True},\n", + " {'facts': ['The Russians trained dogs during WWII to run suicide missions with mines strapped to their backs.'],\n", + " 'success': True},\n", + " {'facts': ['Paul McCartney of the Beatles recorded a high pitched whistle at the end of \"A Day in the Life\" for his dog.'],\n", + " 'success': True}]" + ] + }, + "execution_count": 114, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "facts_per_month = [request_dog_facts() for _ in range(current_month)]\n", + "facts_per_month" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "03abdfef", + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "id": "ec3a47d4", @@ -198,12 +297,121 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 115, "id": "d22652ed", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "monthly_dog_fact = pd.DataFrame(facts_per_month)" + ] + }, + { + "cell_type": "code", + "execution_count": 116, + "id": "60d0ef28", + "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", + "
factssuccess
0[Many foot disorders in dogs are caused by lon...True
1[Just like human fingerprints, no two dogs' no...True
2[Two stray dogs in Afghanistan saved 50 Americ...True
3[The border collie or sheep dog is often consi...True
4[Male dogs have a bone in their penis.]True
5[The most popular breed of domestic dog in the...True
6[A dog’s vision is not fully developed until a...True
7[Dogs are natural pack animals.]True
8[The Russians trained dogs during WWII to run ...True
9[Paul McCartney of the Beatles recorded a high...True
\n", + "
" + ], + "text/plain": [ + " facts success\n", + "0 [Many foot disorders in dogs are caused by lon... True\n", + "1 [Just like human fingerprints, no two dogs' no... True\n", + "2 [Two stray dogs in Afghanistan saved 50 Americ... True\n", + "3 [The border collie or sheep dog is often consi... True\n", + "4 [Male dogs have a bone in their penis.] True\n", + "5 [The most popular breed of domestic dog in the... True\n", + "6 [A dog’s vision is not fully developed until a... True\n", + "7 [Dogs are natural pack animals.] True\n", + "8 [The Russians trained dogs during WWII to run ... True\n", + "9 [Paul McCartney of the Beatles recorded a high... True" + ] + }, + "execution_count": 116, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "monthly_dog_fact" ] }, { @@ -216,12 +424,112 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 117, "id": "b29f4826", "metadata": {}, - "outputs": [], + "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", + "
factssuccess
0Many foot disorders in dogs are caused by long...True
1Just like human fingerprints, no two dogs' nos...True
2Two stray dogs in Afghanistan saved 50 America...True
3The border collie or sheep dog is often consid...True
4Male dogs have a bone in their penis.True
5The most popular breed of domestic dog in the ...True
6A dog’s vision is not fully developed until af...True
7Dogs are natural pack animals.True
8The Russians trained dogs during WWII to run s...True
9Paul McCartney of the Beatles recorded a high ...True
\n", + "
" + ], + "text/plain": [ + " facts success\n", + "0 Many foot disorders in dogs are caused by long... True\n", + "1 Just like human fingerprints, no two dogs' nos... True\n", + "2 Two stray dogs in Afghanistan saved 50 America... True\n", + "3 The border collie or sheep dog is often consid... True\n", + "4 Male dogs have a bone in their penis. True\n", + "5 The most popular breed of domestic dog in the ... True\n", + "6 A dog’s vision is not fully developed until af... True\n", + "7 Dogs are natural pack animals. True\n", + "8 The Russians trained dogs during WWII to run s... True\n", + "9 Paul McCartney of the Beatles recorded a high ... True" + ] + }, + "execution_count": 117, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "monthly_dog_fact[\"facts\"] = monthly_dog_fact[\"facts\"].apply(lambda x: x[0]) # (lambda x: str(x)) also works\n", + "monthly_dog_fact" ] }, { @@ -242,12 +550,12 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 118, "id": "ca21a372", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "monthly_dog_fact.to_csv(\"../data/monthly_dog_facts.csv\", index=False)" ] } ], @@ -255,7 +563,7 @@ "kernelspec": { "display_name": "ironhack", "language": "python", - "name": "ironhack" + "name": "python3" }, "language_info": { "codemirror_mode": { diff --git a/your-code/challenge-2.ipynb b/your-code/challenge-2.ipynb index a573e5f..ab6690a 100644 --- a/your-code/challenge-2.ipynb +++ b/your-code/challenge-2.ipynb @@ -50,12 +50,13 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 33, "id": "215eb6bc", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "import pandas as pd\n", + "import requests" ] }, { @@ -76,12 +77,271 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 34, "id": "6ba76753", "metadata": {}, - "outputs": [], + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
NameRoleBookChapterVerse
0AdamFirst ManGenesis11
1EveFirst WomanGenesis225
2NoahBuilder of the ArkGenesis1210
3AbrahamFather of NationsGenesis615
4SarahWife of AbrahamGenesis282
5MosesLeader of the ExodusExodus23
6AaronBrother of MosesExodus138
7DavidKing of Israel1 Samuel84
8SolomonWisest ManProverbs129
9IsaiahProphetIsaiah46
10JeremiahProphetJeremiah316
11John the BaptistForerunner of JesusMatthew125
12Jesus ChristSon of GodMatthew510
13MaryMother of JesusLuke615
14PeterApostleMatthew42
15AndrewApostleMatthew33
16James the GreaterApostleMatthew58
17John the EvangelistApostleJohn34
18PhilipApostleMatthew69
19ThomasApostleMatthew46
20James the LesserApostleMatthew189
21Jude ThaddeusApostleMatthew912
22Simon the ZealotApostleMatthew273
23BartholomewApostleMatthew62
\n", + "
" + ], + "text/plain": [ + " Name Role Book Chapter Verse\n", + "0 Adam First Man Genesis 1 1\n", + "1 Eve First Woman Genesis 22 5\n", + "2 Noah Builder of the Ark Genesis 12 10\n", + "3 Abraham Father of Nations Genesis 6 15\n", + "4 Sarah Wife of Abraham Genesis 28 2\n", + "5 Moses Leader of the Exodus Exodus 2 3\n", + "6 Aaron Brother of Moses Exodus 13 8\n", + "7 David King of Israel 1 Samuel 8 4\n", + "8 Solomon Wisest Man Proverbs 12 9\n", + "9 Isaiah Prophet Isaiah 4 6\n", + "10 Jeremiah Prophet Jeremiah 3 16\n", + "11 John the Baptist Forerunner of Jesus Matthew 12 5\n", + "12 Jesus Christ Son of God Matthew 5 10\n", + "13 Mary Mother of Jesus Luke 6 15\n", + "14 Peter Apostle Matthew 4 2\n", + "15 Andrew Apostle Matthew 3 3\n", + "16 James the Greater Apostle Matthew 5 8\n", + "17 John the Evangelist Apostle John 3 4\n", + "18 Philip Apostle Matthew 6 9\n", + "19 Thomas Apostle Matthew 4 6\n", + "20 James the Lesser Apostle Matthew 18 9\n", + "21 Jude Thaddeus Apostle Matthew 9 12\n", + "22 Simon the Zealot Apostle Matthew 27 3\n", + "23 Bartholomew Apostle Matthew 6 2" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "df = pd.read_csv(\"../data/bible.csv\")\n", + "df" ] }, { @@ -110,12 +370,40 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 35, "id": "8ab21dfb", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'reference': 'John 3:16',\n", + " 'verses': [{'book_id': 'JHN',\n", + " 'book_name': 'John',\n", + " 'chapter': 3,\n", + " 'verse': 16,\n", + " 'text': '\\nFor God so loved the world, that he gave his one and only Son, that whoever believes in him should not perish, but have eternal life.\\n\\n'}],\n", + " 'text': '\\nFor God so loved the world, that he gave his one and only Son, that whoever believes in him should not perish, but have eternal life.\\n\\n',\n", + " 'translation_id': 'web',\n", + " 'translation_name': 'World English Bible',\n", + " 'translation_note': 'Public Domain'}" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "base_url = \"https://bible-api.com\"\n", + "endpoint = \"/john 3:16\"\n", + "\n", + "url_for_request = base_url + endpoint\n", + "\n", + "request = requests.get(url_for_request)\n", + "\n", + "response = request.json()\n", + "response" ] }, { @@ -128,12 +416,23 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 36, "id": "5ac1bcd2", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'For God so loved the world, that he gave his one and only Son, that whoever believes in him should not perish, but have eternal life.'" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "response['text'].strip()" ] }, { @@ -154,12 +453,34 @@ }, { "cell_type": "code", - "execution_count": 6, - "id": "b3a9a0f0", + "execution_count": 51, + "id": "3defd857", + "metadata": {}, + "outputs": [], + "source": [ + "def get_response(book, chapter, verse):\n", + " base_url = 'https://bible-api.com/'\n", + " endpoint = f'{book} {chapter}:{verse}'\n", + " url_for_request = base_url + endpoint\n", + " res = requests.get(url_for_request)\n", + " \n", + " if res.status_code == 200:\n", + " data = res.json()\n", + " text = data['text']\n", + " text_cleaned = text.strip()\n", + " return text_cleaned\n", + " else:\n", + " return \"Request did not work properly\"" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "id": "a50343e9", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "df['Text'] = df.apply(lambda row: get_response(row['Book'], row['Chapter'], row['Verse']), axis=1)\n" ] }, { @@ -170,6 +491,325 @@ "# Save the dataframe into the data folder. " ] }, + { + "cell_type": "code", + "execution_count": 53, + "id": "e4951a45", + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
NameRoleBookChapterVerseText
0AdamFirst ManGenesis11In the beginning, God created the heavens and ...
1EveFirst WomanGenesis225Abraham said to his young men, “Stay here with...
2NoahBuilder of the ArkGenesis1210There was a famine in the land. Abram went dow...
3AbrahamFather of NationsGenesis615This is how you shall make it. The length of t...
4SarahWife of AbrahamGenesis282Arise, go to Paddan Aram, to the house of Beth...
5MosesLeader of the ExodusExodus23When she could no longer hide him, she took a ...
6AaronBrother of MosesExodus138You shall tell your son in that day, saying, ‘...
7DavidKing of Israel1 Samuel84Then all the elders of Israel gathered themsel...
8SolomonWisest ManProverbs129Better is he who is little know, and has a ser...
9IsaiahProphetIsaiah46There will be a pavilion for a shade in the da...
10JeremiahProphetJeremiah316It will come to pass, when you are multiplied ...
11John the BaptistForerunner of JesusMatthew125Or have you not read in the law, that on the S...
12Jesus ChristSon of GodMatthew510Blessed are those who have been persecuted for...
13MaryMother of JesusLuke615Matthew; Thomas; James, the son of Alphaeus; S...
14PeterApostleMatthew42When he had fasted forty days and forty nights...
15AndrewApostleMatthew33Request did not work properly
16James the GreaterApostleMatthew58Request did not work properly
17John the EvangelistApostleJohn34Request did not work properly
18PhilipApostleMatthew69Request did not work properly
19ThomasApostleMatthew46Request did not work properly
20James the LesserApostleMatthew189Request did not work properly
21Jude ThaddeusApostleMatthew912Request did not work properly
22Simon the ZealotApostleMatthew273Request did not work properly
23BartholomewApostleMatthew62Request did not work properly
\n", + "
" + ], + "text/plain": [ + " Name Role Book Chapter Verse \\\n", + "0 Adam First Man Genesis 1 1 \n", + "1 Eve First Woman Genesis 22 5 \n", + "2 Noah Builder of the Ark Genesis 12 10 \n", + "3 Abraham Father of Nations Genesis 6 15 \n", + "4 Sarah Wife of Abraham Genesis 28 2 \n", + "5 Moses Leader of the Exodus Exodus 2 3 \n", + "6 Aaron Brother of Moses Exodus 13 8 \n", + "7 David King of Israel 1 Samuel 8 4 \n", + "8 Solomon Wisest Man Proverbs 12 9 \n", + "9 Isaiah Prophet Isaiah 4 6 \n", + "10 Jeremiah Prophet Jeremiah 3 16 \n", + "11 John the Baptist Forerunner of Jesus Matthew 12 5 \n", + "12 Jesus Christ Son of God Matthew 5 10 \n", + "13 Mary Mother of Jesus Luke 6 15 \n", + "14 Peter Apostle Matthew 4 2 \n", + "15 Andrew Apostle Matthew 3 3 \n", + "16 James the Greater Apostle Matthew 5 8 \n", + "17 John the Evangelist Apostle John 3 4 \n", + "18 Philip Apostle Matthew 6 9 \n", + "19 Thomas Apostle Matthew 4 6 \n", + "20 James the Lesser Apostle Matthew 18 9 \n", + "21 Jude Thaddeus Apostle Matthew 9 12 \n", + "22 Simon the Zealot Apostle Matthew 27 3 \n", + "23 Bartholomew Apostle Matthew 6 2 \n", + "\n", + " Text \n", + "0 In the beginning, God created the heavens and ... \n", + "1 Abraham said to his young men, “Stay here with... \n", + "2 There was a famine in the land. Abram went dow... \n", + "3 This is how you shall make it. The length of t... \n", + "4 Arise, go to Paddan Aram, to the house of Beth... \n", + "5 When she could no longer hide him, she took a ... \n", + "6 You shall tell your son in that day, saying, ‘... \n", + "7 Then all the elders of Israel gathered themsel... \n", + "8 Better is he who is little know, and has a ser... \n", + "9 There will be a pavilion for a shade in the da... \n", + "10 It will come to pass, when you are multiplied ... \n", + "11 Or have you not read in the law, that on the S... \n", + "12 Blessed are those who have been persecuted for... \n", + "13 Matthew; Thomas; James, the son of Alphaeus; S... \n", + "14 When he had fasted forty days and forty nights... \n", + "15 Request did not work properly \n", + "16 Request did not work properly \n", + "17 Request did not work properly \n", + "18 Request did not work properly \n", + "19 Request did not work properly \n", + "20 Request did not work properly \n", + "21 Request did not work properly \n", + "22 Request did not work properly \n", + "23 Request did not work properly " + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, { "cell_type": "markdown", "id": "2b334e3d", @@ -180,20 +820,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 54, "id": "556829be", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "df.to_csv('../data/bible_with_verse_text.csv', index = False)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0e0f1dd2", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { "display_name": "ironhack", "language": "python", - "name": "ironhack" + "name": "python3" }, "language_info": { "codemirror_mode": { diff --git a/your-code/challenge-3.ipynb b/your-code/challenge-3.ipynb index d6fc5b0..a37fa96 100644 --- a/your-code/challenge-3.ipynb +++ b/your-code/challenge-3.ipynb @@ -10,11 +10,15 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "215eb6bc", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "import requests\n", + "import pandas as pd\n", + "import getpass" + ] }, { "cell_type": "markdown", @@ -50,12 +54,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "id": "7ea8624f", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "token = getpass.getpass(\"Enter your token: \")" ] }, { @@ -68,12 +72,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "id": "968e4e9c", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "location = \"madrid\"" ] }, { @@ -86,12 +90,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "id": "bdc7c366", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "url = f\"https://api.tomorrow.io/v4/weather/history/recent?location={location}&apikey={token}\"" ] }, { @@ -104,12 +108,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "id": "8355e9e6", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "def get_weather_response (location, token):\n", + " url = f\"https://api.tomorrow.io/v4/weather/history/recent?location={location}&apikey={token}\"\n", + " headers = {\"accept\": \"application/json\"}\n", + " res = requests.get(url, headers=headers)\n", + " return res.json()" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "f8bf0716", + "metadata": {}, + "outputs": [], + "source": [ + "data = get_weather_response (location, token)" ] }, { @@ -120,6 +138,30 @@ "# Last step will be to turn it into a Dataframe! 🐼" ] }, + { + "cell_type": "code", + "execution_count": 17, + "id": "107fe8a5", + "metadata": {}, + "outputs": [], + "source": [ + "all_data = []\n", + "def get_responses_into_df (data):\n", + "\n", + " for element in data:\n", + " response = data['timelines']['hourly']\n", + " location = data['location']['name']\n", + " for entry in response:\n", + " data_dict = entry['values']\n", + " data_dict['time'] = entry['time']\n", + " all_data.append(data_dict)\n", + " \n", + " df = pd.DataFrame(all_data)\n", + " df['location'] = data['location']['name']\n", + " \n", + " return df" + ] + }, { "cell_type": "markdown", "id": "d99fe0fd", @@ -138,12 +180,227 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "id": "788c6d98", "metadata": {}, - "outputs": [], + "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", + "
cloudBasecloudCeilingcloudCoverdewPointevapotranspirationfreezingRainIntensityhumidityiceAccumulationiceAccumulationLweprecipitationProbability...temperatureApparentuvHealthConcernuvIndexvisibilityweatherCodewindDirectionwindGustwindSpeedtimelocation
00.37NaN4811.000.039082000...13.88009.991101199.639.134.632023-10-28T20:00:00ZMadrid, Comunidad de Madrid, España
10.37NaN4411.000.036082000...13.88009.071101190.138.884.382023-10-28T21:00:00ZMadrid, Comunidad de Madrid, España
20.380.387510.880.036082000...13.880010.241001179.008.814.382023-10-28T22:00:00ZMadrid, Comunidad de Madrid, España
30.130.137511.880.034093000...13.000013.421001239.5010.504.132023-10-28T23:00:00ZMadrid, Comunidad de Madrid, España
40.130.137511.880.032093000...13.00009.991001198.1311.384.812023-10-29T00:00:00ZMadrid, Comunidad de Madrid, España
\n", + "

5 rows × 31 columns

\n", + "
" + ], + "text/plain": [ + " cloudBase cloudCeiling cloudCover dewPoint evapotranspiration \\\n", + "0 0.37 NaN 48 11.00 0.039 \n", + "1 0.37 NaN 44 11.00 0.036 \n", + "2 0.38 0.38 75 10.88 0.036 \n", + "3 0.13 0.13 75 11.88 0.034 \n", + "4 0.13 0.13 75 11.88 0.032 \n", + "\n", + " freezingRainIntensity humidity iceAccumulation iceAccumulationLwe \\\n", + "0 0 82 0 0 \n", + "1 0 82 0 0 \n", + "2 0 82 0 0 \n", + "3 0 93 0 0 \n", + "4 0 93 0 0 \n", + "\n", + " precipitationProbability ... temperatureApparent uvHealthConcern \\\n", + "0 0 ... 13.88 0 \n", + "1 0 ... 13.88 0 \n", + "2 0 ... 13.88 0 \n", + "3 0 ... 13.00 0 \n", + "4 0 ... 13.00 0 \n", + "\n", + " uvIndex visibility weatherCode windDirection windGust windSpeed \\\n", + "0 0 9.99 1101 199.63 9.13 4.63 \n", + "1 0 9.07 1101 190.13 8.88 4.38 \n", + "2 0 10.24 1001 179.00 8.81 4.38 \n", + "3 0 13.42 1001 239.50 10.50 4.13 \n", + "4 0 9.99 1001 198.13 11.38 4.81 \n", + "\n", + " time location \n", + "0 2023-10-28T20:00:00Z Madrid, Comunidad de Madrid, España \n", + "1 2023-10-28T21:00:00Z Madrid, Comunidad de Madrid, España \n", + "2 2023-10-28T22:00:00Z Madrid, Comunidad de Madrid, España \n", + "3 2023-10-28T23:00:00Z Madrid, Comunidad de Madrid, España \n", + "4 2023-10-29T00:00:00Z Madrid, Comunidad de Madrid, España \n", + "\n", + "[5 rows x 31 columns]" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "df = get_responses_into_df(data)\n", + "df.head()" ] }, { @@ -164,20 +421,28 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 21, "id": "ca21a372", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "df.to_csv('../data/madrid_forecast.csv', index = False)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "33358f05", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { "display_name": "ironhack", "language": "python", - "name": "ironhack" + "name": "python3" }, "language_info": { "codemirror_mode": {