{ "cells": [ { "cell_type": "markdown", "id": "9e0b4e60", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# DS2500 Day 21\n", "\n", "Mar 31, 2023\n", "\n", "### Content\n", "- Weather API\n", " - timestamps\n", " - representing a tree via nested dictionaries (json format)\n", " - making API calls\n", "- 🐂💩 visualizations\n", " - the colorful language, [it isn't mine](https://www.callingbullshit.org/), though it does add a certain excitement to our ordinarily dry technical lingo\n", "\n", "### Admin\n", "- focus on the project!\n", " - presentatoin preferences due next monday @ 9AM\n", " - https://piazza.com/class/lbxsbawi9yq2f9/post/403\n", " - lab sessions next week will support hw7\n", " - its optional, no need to go if you don't feel the need\n", " - hw7 is due next monday (April 3) to allow you to ask questions in lab\n", "\n", " - no classes next week, sign up for a project team meeting with Prof Higger\n", " - link on course website" ] }, { "cell_type": "markdown", "id": "870b0ff1", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Timestamps\n", "## Unix Time\n", "\n", "- [UTC 00:00](https://en.wikipedia.org/wiki/UTC%2B00:00) Coordinated Universal Time's \"zero\" timezome\n", " - time zone at 0 deg longitude\n", " - how is 0 deg longitude defined? \n", " - A succesfully warring empire (United Kingdom) chose it \n", " - (personally, I'd find it convenient if a metric system loving empire had been more successful at war ...)\n", "- [Unix Time](https://en.wikipedia.org/wiki/Unix_time) is The number of seconds which have passed since 00:00:00 UTC on 1 Jan 1970 (ignoring leap seconds)\n", "- UTC is time zone agnostic \n", " - (more on this next lesson...)\n", "\n", "## Python's `datetime` & `timedelta`\n", "- helpful for all those pesky unit conversions" ] }, { "cell_type": "code", "execution_count": 2, "id": "5adc58fc", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "datetime.datetime(2021, 2, 14, 2, 0)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from datetime import datetime, timedelta\n", "\n", "utc_example = 1613286000\n", "\n", "# WARNING! assumes the time zone of the machine its running on!\n", "# (we'll see this issue again later ...)\n", "dt0 = datetime.fromtimestamp(utc_example)\n", "dt0" ] }, { "cell_type": "markdown", "id": "55cbacb4", "metadata": {}, "source": [ "[further reading](https://docs.python.org/3/library/datetime.html#aware-and-naive-objects) on the datetime above being timezone agnostic." ] }, { "cell_type": "code", "execution_count": 3, "id": "94556cf9", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(2, 14)" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# we can access meaningful date attributes of a datetime object\n", "# year, month, day, hour, minute, second\n", "dt0.month, dt0.day" ] }, { "cell_type": "code", "execution_count": 4, "id": "7f63cfc3", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dt0.second" ] }, { "cell_type": "code", "execution_count": 5, "id": "2ca5cfac", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2021" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dt0.year" ] }, { "cell_type": "code", "execution_count": 26, "id": "faf7f937", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "datetime.datetime(2023, 3, 31, 10, 8, 31, 404973)" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dt1 = datetime.now()\n", "dt1" ] }, { "cell_type": "code", "execution_count": 7, "id": "3ee738bf", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "datetime.datetime(2222, 2, 2, 2, 0)" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dt2 = datetime(year=2222, month=2, day=2, hour=2)\n", "dt2" ] }, { "cell_type": "code", "execution_count": 8, "id": "87f7c545", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "datetime.timedelta(days=72625, seconds=57279, microseconds=96793)" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# time delta measure differences between two datetimes:\n", "dt2 - dt1" ] }, { "cell_type": "code", "execution_count": 16, "id": "d924614d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "datetime.timedelta(days=3, seconds=37056)" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# you can build them explicitly:\n", "offset = timedelta(days=2, seconds=123456)\n", "offset" ] }, { "cell_type": "code", "execution_count": 17, "id": "e2e6b617", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "datetime.datetime(2222, 2, 5, 12, 17, 36)" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# and operate with them (datetime + timedelta = datetime)\n", "dt2 + offset" ] }, { "cell_type": "code", "execution_count": 27, "id": "12d15e2f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "733572534.414235" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# how many seconds old are you?\n", "(datetime.now() - datetime(year=2000, month=1, day=1)).total_seconds()" ] }, { "cell_type": "code", "execution_count": 29, "id": "0de30b1c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "31.70958904109589" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# you've got a billionth second birthday coming up around age 31 or so:\n", "billion_sec = timedelta(seconds=1e9)\n", "billion_sec.days/365" ] }, { "cell_type": "code", "execution_count": 30, "id": "91dea7a1", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "datetime.datetime(2031, 9, 9, 1, 46, 40)" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# be sure to compute below so you can plan that party 10 years from now\n", "datetime(year=2000, month=1, day=1) + billion_sec" ] }, { "cell_type": "markdown", "id": "3f25eeaf", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# `pd.to_datetime()`\n", "\n", "Use pandas's [pd.to_datetime()](https://pandas.pydata.org/docs/reference/api/pandas.to_datetime.html) function to convert a column of your dataframe to datetime objects. \n", "\n", "`to_datetime()` does a pretty good job guessing your format, but if it runs into trouble you've always got [strftime & strptime](https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior)" ] }, { "cell_type": "code", "execution_count": 33, "id": "df2bca22", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0 dec 23, 2000\n", "1 jan 1, 2039 3AM\n", "2 jan 14, 2039 14:00\n", "3 not really a toHFDSOAIUSHFIAUime\n", "dtype: object" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "\n", "s = pd.Series(['dec 23, 2000', 'jan 1, 2039 3AM', 'jan 14, 2039 14:00', 'not really a toHFDSOAIUSHFIAUime'])\n", "\n", "s" ] }, { "cell_type": "code", "execution_count": 35, "id": "7ec7f28f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0 2000-12-23 00:00:00\n", "1 2039-01-01 03:00:00\n", "2 2039-01-14 14:00:00\n", "3 NaT\n", "dtype: datetime64[ns]" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# the errors = 'coerce' argument yield \"NaT\", not-a-time, objects for inputs which\n", "# can't be converted. without this generates an error\n", "pd.to_datetime(s, errors='coerce')" ] }, { "cell_type": "markdown", "id": "8e969b4b", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Do you know what time it is?\n", "[after reading this, I'm not sure that I do ...](https://www.creativedeletion.com/2015/01/28/falsehoods-programmers-date-time-zones.html)\n", "\n", "takeaways:\n", "- don't underestimate the difficulty of describing time unabmiguously, its hard!\n", "- use a library where you might run into time issues:\n", " - timezones\n", " - leap year / second\n", " - varying days of month / year\n", " - time formatting 'Feb' vs 'February' etc\n", "- Unix Time isn't human readable ... but it is unambiguous. \n", "\n", "### Punchline: measuring time is hard, don't underestimate it (I certainly have!)" ] }, { "cell_type": "markdown", "id": "dbf0b3e4", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Representing Trees as Lists & Dictionaries\n", "- useful for representing a tree of data\n", "- (our API calls will return nested dictionaries)\n", "\n", "\"Drawing\"" ] }, { "cell_type": "code", "execution_count": 39, "id": "a917657b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'f': {'a': 0, 'b': 1, 'c': 2}, 'g': {'x': 24, 'y': 25, 'z': 26}}" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "red_branch_dict = {'a': 0, 'b': 1, 'c': 2}\n", "blu_branch_dict = {'x': 24, 'y': 25, 'z': 26}\n", "tree_dict = {'f': red_branch_dict,\n", " 'g': blu_branch_dict}\n", "tree_dict" ] }, { "cell_type": "code", "execution_count": 40, "id": "f131240a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tree_dict['f']['b']" ] }, { "cell_type": "markdown", "id": "4f999d34", "metadata": {}, "source": [ "\"Drawing\"" ] }, { "cell_type": "code", "execution_count": 44, "id": "4493f8d9", "metadata": {}, "outputs": [], "source": [ "dict0 = {'num': [3, 1, 4, 1, 5, 9, 2, 6],\n", " 'letter': 'C'}\n", "dict1 = {'num': 17,\n", " 'letter': 'R'}\n", "dict2 = {'num': 21,\n", " 'letter': 'S'}\n", "dict_of_dict = {0: dict0,\n", " 1: dict1,\n", " 2: dict2}\n", "list_of_dict = [dict0, dict1, dict2]" ] }, { "cell_type": "code", "execution_count": 46, "id": "5ed12c9c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'R'" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dict_of_dict[1]['letter']" ] }, { "cell_type": "code", "execution_count": 45, "id": "140088ac", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'R'" ] }, "execution_count": 45, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list_of_dict[1]['letter']" ] }, { "cell_type": "markdown", "id": "93046c6d", "metadata": {}, "source": [ "## In class activity 1:\n", "1. Express all of the following penguin group's height and weight as a list of dictionaries:\n", "\"Drawing\"" ] }, { "cell_type": "code", "execution_count": 51, "id": "ce5680cb", "metadata": {}, "outputs": [], "source": [ "grn_dict = {'height': [2, 3, 2],\n", " 'weight': [4, 6, 5]}\n", "blu_dict = {'height': [4, 6, 5],\n", " 'weight': [2, 3, 2]}\n", "red_dict = {'height': [10, 7, 8],\n", " 'weight': [11, 6, 5]}\n", "peng_data = [grn_dict,\n", " blu_dict,\n", " red_dict]\n", "peng_data2 = {'penguin0': grn_dict,\n", " 'penguin1': blu_dict,\n", " 'penguin2': red_dict}" ] }, { "cell_type": "code", "execution_count": 49, "id": "9adc4397", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[2, 3, 2]" ] }, "execution_count": 49, "metadata": {}, "output_type": "execute_result" } ], "source": [ "peng_data[0]['height']" ] }, { "cell_type": "code", "execution_count": null, "id": "0ee36cf0", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "5839a432", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# API\n", "### Definitions\n", "**API** Application Program Interface\n", " - within DS: a server which gives out data (often over the internet)\n", " - note: 'API', in general, refers to the barrier between two pieces of software, has a specific meaning in DS\n", " \n", " \n", " **JSON** JavaScript Object Notation\n", " - a method of storing objects as text\n", " - much like the nested dictionaries ... JSON and similar formats are often trees" ] }, { "cell_type": "markdown", "id": "29264c73", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## OpenWeather API\n", "What information does this offer?\n", "\n", "- [https://openweathermap.org/api](https://openweathermap.org/api)\n", "- (note, you won't have access to all that, see the \"free\" column [here](https://openweathermap.org/price))\n", "\n", "How do I get ready to use it?\n", "- sign up for an account\n", " - [https://home.openweathermap.org/users/sign_up](https://home.openweathermap.org/users/sign_up)\n", "- get an api key\n", " - [https://home.openweathermap.org/api_keys](https://home.openweathermap.org/api_keys)\n", " \n", "Think of APIs as a hybrid of a website and a function. Its a website where your query is stored in the address:" ] }, { "cell_type": "code", "execution_count": 53, "id": "ddf57001", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "https://api.openweathermap.org/data/2.5/forecast?lat=42.3601&lon=-71.0589&units=imperial&appid=eea5fcef9a7ea19505dc1c165bacac4a\n" ] } ], "source": [ "api_key = 'eea5fcef9a7ea19505dc1c165bacac4a'\n", "\n", "# north = positive, south = negative\n", "lat = 42.3601\n", "# west = positive, east = negative\n", "lon = -71.0589\n", "\n", "units = 'imperial'\n", "\n", "url = f'https://api.openweathermap.org/data/2.5/forecast?lat={lat}&lon={lon}&units={units}&appid={api_key}'\n", "print(url)" ] }, { "cell_type": "code", "execution_count": 55, "id": "1d51a6ed", "metadata": { "collapsed": true }, "outputs": [ { "data": { "text/plain": [ "'{\"cod\":\"200\",\"message\":0,\"cnt\":40,\"list\":[{\"dt\":1680274800,\"main\":{\"temp\":40.91,\"feels_like\":37.31,\"temp_min\":40.91,\"temp_max\":43.12,\"pressure\":1027,\"sea_level\":1027,\"grnd_level\":1026,\"humidity\":36,\"temp_kf\":-1.23},\"weather\":[{\"id\":803,\"main\":\"Clouds\",\"description\":\"broken clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":75},\"wind\":{\"speed\":5.32,\"deg\":252,\"gust\":10.31},\"visibility\":10000,\"pop\":0,\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2023-03-31 15:00:00\"},{\"dt\":1680285600,\"main\":{\"temp\":44.42,\"feels_like\":41.05,\"temp_min\":44.42,\"temp_max\":51.44,\"pressure\":1026,\"sea_level\":1026,\"grnd_level\":1023,\"humidity\":32,\"temp_kf\":-3.9},\"weather\":[{\"id\":803,\"main\":\"Clouds\",\"description\":\"broken clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":81},\"wind\":{\"speed\":5.95,\"deg\":213,\"gust\":12.77},\"visibility\":10000,\"pop\":0,\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2023-03-31 18:00:00\"},{\"dt\":1680296400,\"main\":{\"temp\":43.93,\"feels_like\":37.71,\"temp_min\":43.93,\"temp_max\":45.45,\"pressure\":1023,\"sea_level\":1023,\"grnd_level\":1020,\"humidity\":48,\"temp_kf\":-0.84},\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"clouds\":{\"all\":92},\"wind\":{\"speed\":12.28,\"deg\":194,\"gust\":18.52},\"visibility\":10000,\"pop\":0.4,\"rain\":{\"3h\":0.11},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2023-03-31 21:00:00\"},{\"dt\":1680307200,\"main\":{\"temp\":39.45,\"feels_like\":33.03,\"temp_min\":39.45,\"temp_max\":39.45,\"pressure\":1019,\"sea_level\":1019,\"grnd_level\":1018,\"humidity\":87,\"temp_kf\":0},\"weather\":[{\"id\":501,\"main\":\"Rain\",\"description\":\"moderate rain\",\"icon\":\"10n\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":9.84,\"deg\":168,\"gust\":29.39},\"visibility\":5974,\"pop\":0.96,\"rain\":{\"3h\":4.27},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2023-04-01 00:00:00\"},{\"dt\":1680318000,\"main\":{\"temp\":43.29,\"feels_like\":38.86,\"temp_min\":43.29,\"temp_max\":43.29,\"pressure\":1014,\"sea_level\":1014,\"grnd_level\":1014,\"humidity\":94,\"temp_kf\":0},\"weather\":[{\"id\":501,\"main\":\"Rain\",\"description\":\"moderate rain\",\"icon\":\"10n\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":7.47,\"deg\":180,\"gust\":26.02},\"visibility\":10000,\"pop\":1,\"rain\":{\"3h\":4.63},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2023-04-01 03:00:00\"},{\"dt\":1680328800,\"main\":{\"temp\":43.86,\"feels_like\":43.86,\"temp_min\":43.86,\"temp_max\":43.86,\"pressure\":1011,\"sea_level\":1011,\"grnd_level\":1010,\"humidity\":98,\"temp_kf\":0},\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10n\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":2.62,\"deg\":271,\"gust\":7.7},\"visibility\":10000,\"pop\":1,\"rain\":{\"3h\":0.58},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2023-04-01 06:00:00\"},{\"dt\":1680339600,\"main\":{\"temp\":43,\"feels_like\":43,\"temp_min\":43,\"temp_max\":43,\"pressure\":1009,\"sea_level\":1009,\"grnd_level\":1008,\"humidity\":98,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04n\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":2.01,\"deg\":275,\"gust\":4.5},\"visibility\":10000,\"pop\":0,\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2023-04-01 09:00:00\"},{\"dt\":1680350400,\"main\":{\"temp\":44.6,\"feels_like\":42.93,\"temp_min\":44.6,\"temp_max\":44.6,\"pressure\":1005,\"sea_level\":1005,\"grnd_level\":1005,\"humidity\":98,\"temp_kf\":0},\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":3.67,\"deg\":146,\"gust\":13.35},\"visibility\":4623,\"pop\":0.21,\"rain\":{\"3h\":0.2},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2023-04-01 12:00:00\"},{\"dt\":1680361200,\"main\":{\"temp\":51.3,\"feels_like\":50.63,\"temp_min\":51.3,\"temp_max\":51.3,\"pressure\":1000,\"sea_level\":1000,\"grnd_level\":999,\"humidity\":96,\"temp_kf\":0},\"weather\":[{\"id\":501,\"main\":\"Rain\",\"description\":\"moderate rain\",\"icon\":\"10d\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":12.21,\"deg\":206,\"gust\":38.54},\"visibility\":10000,\"pop\":1,\"rain\":{\"3h\":5.57},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2023-04-01 15:00:00\"},{\"dt\":1680372000,\"main\":{\"temp\":55.49,\"feels_like\":55.11,\"temp_min\":55.49,\"temp_max\":55.49,\"pressure\":995,\"sea_level\":995,\"grnd_level\":995,\"humidity\":93,\"temp_kf\":0},\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":15.39,\"deg\":217,\"gust\":38.95},\"visibility\":10000,\"pop\":1,\"rain\":{\"3h\":1.93},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2023-04-01 18:00:00\"},{\"dt\":1680382800,\"main\":{\"temp\":58.33,\"feels_like\":57.96,\"temp_min\":58.33,\"temp_max\":58.33,\"pressure\":993,\"sea_level\":993,\"grnd_level\":993,\"humidity\":87,\"temp_kf\":0},\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"clouds\":{\"all\":91},\"wind\":{\"speed\":12.57,\"deg\":217,\"gust\":29.01},\"visibility\":10000,\"pop\":0.8,\"rain\":{\"3h\":0.94},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2023-04-01 21:00:00\"},{\"dt\":1680393600,\"main\":{\"temp\":53.87,\"feels_like\":53.33,\"temp_min\":53.87,\"temp_max\":53.87,\"pressure\":991,\"sea_level\":991,\"grnd_level\":990,\"humidity\":93,\"temp_kf\":0},\"weather\":[{\"id\":803,\"main\":\"Clouds\",\"description\":\"broken clouds\",\"icon\":\"04n\"}],\"clouds\":{\"all\":67},\"wind\":{\"speed\":11.05,\"deg\":196,\"gust\":34.83},\"visibility\":10000,\"pop\":0.66,\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2023-04-02 00:00:00\"},{\"dt\":1680404400,\"main\":{\"temp\":50.86,\"feels_like\":49.69,\"temp_min\":50.86,\"temp_max\":50.86,\"pressure\":990,\"sea_level\":990,\"grnd_level\":989,\"humidity\":86,\"temp_kf\":0},\"weather\":[{\"id\":501,\"main\":\"Rain\",\"description\":\"moderate rain\",\"icon\":\"10n\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":8.75,\"deg\":261,\"gust\":24.56},\"visibility\":10000,\"pop\":1,\"rain\":{\"3h\":5.89},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2023-04-02 03:00:00\"},{\"dt\":1680415200,\"main\":{\"temp\":47.52,\"feels_like\":41.14,\"temp_min\":47.52,\"temp_max\":47.52,\"pressure\":991,\"sea_level\":991,\"grnd_level\":991,\"humidity\":81,\"temp_kf\":0},\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10n\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":16.28,\"deg\":274,\"gust\":30.42},\"visibility\":10000,\"pop\":1,\"rain\":{\"3h\":0.55},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2023-04-02 06:00:00\"},{\"dt\":1680426000,\"main\":{\"temp\":43.83,\"feels_like\":36.18,\"temp_min\":43.83,\"temp_max\":43.83,\"pressure\":996,\"sea_level\":996,\"grnd_level\":996,\"humidity\":75,\"temp_kf\":0},\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10n\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":17.09,\"deg\":299,\"gust\":31.79},\"visibility\":10000,\"pop\":0.35,\"rain\":{\"3h\":0.3},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2023-04-02 09:00:00\"},{\"dt\":1680436800,\"main\":{\"temp\":35.67,\"feels_like\":25.57,\"temp_min\":35.67,\"temp_max\":35.67,\"pressure\":1004,\"sea_level\":1004,\"grnd_level\":1004,\"humidity\":61,\"temp_kf\":0},\"weather\":[{\"id\":803,\"main\":\"Clouds\",\"description\":\"broken clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":62},\"wind\":{\"speed\":17.27,\"deg\":316,\"gust\":36.78},\"visibility\":10000,\"pop\":0.12,\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2023-04-02 12:00:00\"},{\"dt\":1680447600,\"main\":{\"temp\":38.95,\"feels_like\":29.48,\"temp_min\":38.95,\"temp_max\":38.95,\"pressure\":1009,\"sea_level\":1009,\"grnd_level\":1008,\"humidity\":31,\"temp_kf\":0},\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"clear sky\",\"icon\":\"01d\"}],\"clouds\":{\"all\":3},\"wind\":{\"speed\":18.52,\"deg\":326,\"gust\":29.68},\"visibility\":10000,\"pop\":0,\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2023-04-02 15:00:00\"},{\"dt\":1680458400,\"main\":{\"temp\":42.84,\"feels_like\":35.44,\"temp_min\":42.84,\"temp_max\":42.84,\"pressure\":1012,\"sea_level\":1012,\"grnd_level\":1011,\"humidity\":27,\"temp_kf\":0},\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"clear sky\",\"icon\":\"01d\"}],\"clouds\":{\"all\":2},\"wind\":{\"speed\":15.12,\"deg\":328,\"gust\":22.01},\"visibility\":10000,\"pop\":0,\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2023-04-02 18:00:00\"},{\"dt\":1680469200,\"main\":{\"temp\":42.89,\"feels_like\":36.16,\"temp_min\":42.89,\"temp_max\":42.89,\"pressure\":1014,\"sea_level\":1014,\"grnd_level\":1013,\"humidity\":28,\"temp_kf\":0},\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"clear sky\",\"icon\":\"01d\"}],\"clouds\":{\"all\":0},\"wind\":{\"speed\":12.97,\"deg\":326,\"gust\":18.54},\"visibility\":10000,\"pop\":0,\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2023-04-02 21:00:00\"},{\"dt\":1680480000,\"main\":{\"temp\":37.83,\"feels_like\":30.81,\"temp_min\":37.83,\"temp_max\":37.83,\"pressure\":1018,\"sea_level\":1018,\"grnd_level\":1017,\"humidity\":36,\"temp_kf\":0},\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"clear sky\",\"icon\":\"01n\"}],\"clouds\":{\"all\":1},\"wind\":{\"speed\":10.31,\"deg\":330,\"gust\":20},\"visibility\":10000,\"pop\":0,\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2023-04-03 00:00:00\"},{\"dt\":1680490800,\"main\":{\"temp\":34,\"feels_like\":27.43,\"temp_min\":34,\"temp_max\":34,\"pressure\":1019,\"sea_level\":1019,\"grnd_level\":1019,\"humidity\":40,\"temp_kf\":0},\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"clear sky\",\"icon\":\"01n\"}],\"clouds\":{\"all\":9},\"wind\":{\"speed\":7.74,\"deg\":328,\"gust\":16.71},\"visibility\":10000,\"pop\":0,\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2023-04-03 03:00:00\"},{\"dt\":1680501600,\"main\":{\"temp\":32.67,\"feels_like\":32.67,\"temp_min\":32.67,\"temp_max\":32.67,\"pressure\":1020,\"sea_level\":1020,\"grnd_level\":1019,\"humidity\":41,\"temp_kf\":0},\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"clear sky\",\"icon\":\"01n\"}],\"clouds\":{\"all\":9},\"wind\":{\"speed\":2.39,\"deg\":301,\"gust\":4.63},\"visibility\":10000,\"pop\":0,\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2023-04-03 06:00:00\"},{\"dt\":1680512400,\"main\":{\"temp\":32.38,\"feels_like\":29.25,\"temp_min\":32.38,\"temp_max\":32.38,\"pressure\":1020,\"sea_level\":1020,\"grnd_level\":1020,\"humidity\":45,\"temp_kf\":0},\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"clear sky\",\"icon\":\"01n\"}],\"clouds\":{\"all\":10},\"wind\":{\"speed\":3.38,\"deg\":195,\"gust\":6.62},\"visibility\":10000,\"pop\":0,\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2023-04-03 09:00:00\"},{\"dt\":1680523200,\"main\":{\"temp\":35.87,\"feels_like\":30.72,\"temp_min\":35.87,\"temp_max\":35.87,\"pressure\":1021,\"sea_level\":1021,\"grnd_level\":1021,\"humidity\":44,\"temp_kf\":0},\"weather\":[{\"id\":801,\"main\":\"Clouds\",\"description\":\"few clouds\",\"icon\":\"02d\"}],\"clouds\":{\"all\":13},\"wind\":{\"speed\":6.17,\"deg\":208,\"gust\":12.24},\"visibility\":10000,\"pop\":0,\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2023-04-03 12:00:00\"},{\"dt\":1680534000,\"main\":{\"temp\":45.79,\"feels_like\":40.24,\"temp_min\":45.79,\"temp_max\":45.79,\"pressure\":1019,\"sea_level\":1019,\"grnd_level\":1019,\"humidity\":30,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":11.65,\"deg\":210,\"gust\":19.33},\"visibility\":10000,\"pop\":0,\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2023-04-03 15:00:00\"},{\"dt\":1680544800,\"main\":{\"temp\":54.7,\"feels_like\":51.37,\"temp_min\":54.7,\"temp_max\":54.7,\"pressure\":1015,\"sea_level\":1015,\"grnd_level\":1015,\"humidity\":32,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":99},\"wind\":{\"speed\":14.29,\"deg\":213,\"gust\":24.54},\"visibility\":10000,\"pop\":0,\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2023-04-03 18:00:00\"},{\"dt\":1680555600,\"main\":{\"temp\":53.56,\"feels_like\":50.59,\"temp_min\":53.56,\"temp_max\":53.56,\"pressure\":1012,\"sea_level\":1012,\"grnd_level\":1012,\"humidity\":42,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":14.85,\"deg\":208,\"gust\":30.44},\"visibility\":10000,\"pop\":0,\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2023-04-03 21:00:00\"},{\"dt\":1680566400,\"main\":{\"temp\":49.3,\"feels_like\":43.99,\"temp_min\":49.3,\"temp_max\":49.3,\"pressure\":1013,\"sea_level\":1013,\"grnd_level\":1012,\"humidity\":61,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04n\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":14.05,\"deg\":216,\"gust\":39.19},\"visibility\":10000,\"pop\":0,\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2023-04-04 00:00:00\"},{\"dt\":1680577200,\"main\":{\"temp\":49.23,\"feels_like\":44.37,\"temp_min\":49.23,\"temp_max\":49.23,\"pressure\":1012,\"sea_level\":1012,\"grnd_level\":1012,\"humidity\":72,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04n\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":12.26,\"deg\":224,\"gust\":36.57},\"visibility\":10000,\"pop\":0.04,\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2023-04-04 03:00:00\"},{\"dt\":1680588000,\"main\":{\"temp\":47.82,\"feels_like\":45.63,\"temp_min\":47.82,\"temp_max\":47.82,\"pressure\":1014,\"sea_level\":1014,\"grnd_level\":1013,\"humidity\":85,\"temp_kf\":0},\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10n\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":5.06,\"deg\":286,\"gust\":16.06},\"visibility\":10000,\"pop\":0.49,\"rain\":{\"3h\":0.54},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2023-04-04 06:00:00\"},{\"dt\":1680598800,\"main\":{\"temp\":46.51,\"feels_like\":44.82,\"temp_min\":46.51,\"temp_max\":46.51,\"pressure\":1014,\"sea_level\":1014,\"grnd_level\":1013,\"humidity\":93,\"temp_kf\":0},\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10n\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":4.03,\"deg\":162,\"gust\":7.07},\"visibility\":10000,\"pop\":0.79,\"rain\":{\"3h\":0.87},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2023-04-04 09:00:00\"},{\"dt\":1680609600,\"main\":{\"temp\":48.15,\"feels_like\":46.36,\"temp_min\":48.15,\"temp_max\":48.15,\"pressure\":1015,\"sea_level\":1015,\"grnd_level\":1015,\"humidity\":90,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":4.5,\"deg\":192,\"gust\":9.35},\"visibility\":10000,\"pop\":0.66,\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2023-04-04 12:00:00\"},{\"dt\":1680620400,\"main\":{\"temp\":57.43,\"feels_like\":55.94,\"temp_min\":57.43,\"temp_max\":57.43,\"pressure\":1016,\"sea_level\":1016,\"grnd_level\":1015,\"humidity\":65,\"temp_kf\":0},\"weather\":[{\"id\":803,\"main\":\"Clouds\",\"description\":\"broken clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":79},\"wind\":{\"speed\":1.83,\"deg\":266,\"gust\":4.21},\"visibility\":10000,\"pop\":0,\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2023-04-04 15:00:00\"},{\"dt\":1680631200,\"main\":{\"temp\":62.13,\"feels_like\":60.26,\"temp_min\":62.13,\"temp_max\":62.13,\"pressure\":1016,\"sea_level\":1016,\"grnd_level\":1015,\"humidity\":47,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":88},\"wind\":{\"speed\":2.77,\"deg\":308,\"gust\":8.99},\"visibility\":10000,\"pop\":0,\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2023-04-04 18:00:00\"},{\"dt\":1680642000,\"main\":{\"temp\":63.36,\"feels_like\":61.56,\"temp_min\":63.36,\"temp_max\":63.36,\"pressure\":1017,\"sea_level\":1017,\"grnd_level\":1017,\"humidity\":46,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":3.36,\"deg\":328,\"gust\":9.86},\"visibility\":10000,\"pop\":0,\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2023-04-04 21:00:00\"},{\"dt\":1680652800,\"main\":{\"temp\":54.3,\"feels_like\":52.63,\"temp_min\":54.3,\"temp_max\":54.3,\"pressure\":1020,\"sea_level\":1020,\"grnd_level\":1020,\"humidity\":68,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04n\"}],\"clouds\":{\"all\":99},\"wind\":{\"speed\":2.53,\"deg\":122,\"gust\":5.53},\"visibility\":10000,\"pop\":0,\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2023-04-05 00:00:00\"},{\"dt\":1680663600,\"main\":{\"temp\":52,\"feels_like\":50.52,\"temp_min\":52,\"temp_max\":52,\"pressure\":1022,\"sea_level\":1022,\"grnd_level\":1021,\"humidity\":77,\"temp_kf\":0},\"weather\":[{\"id\":803,\"main\":\"Clouds\",\"description\":\"broken clouds\",\"icon\":\"04n\"}],\"clouds\":{\"all\":73},\"wind\":{\"speed\":1.92,\"deg\":63,\"gust\":3.24},\"visibility\":10000,\"pop\":0,\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2023-04-05 03:00:00\"},{\"dt\":1680674400,\"main\":{\"temp\":49.55,\"feels_like\":49.55,\"temp_min\":49.55,\"temp_max\":49.55,\"pressure\":1022,\"sea_level\":1022,\"grnd_level\":1022,\"humidity\":86,\"temp_kf\":0},\"weather\":[{\"id\":803,\"main\":\"Clouds\",\"description\":\"broken clouds\",\"icon\":\"04n\"}],\"clouds\":{\"all\":76},\"wind\":{\"speed\":1.88,\"deg\":69,\"gust\":3.8},\"visibility\":10000,\"pop\":0,\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2023-04-05 06:00:00\"},{\"dt\":1680685200,\"main\":{\"temp\":48.72,\"feels_like\":46.9,\"temp_min\":48.72,\"temp_max\":48.72,\"pressure\":1024,\"sea_level\":1024,\"grnd_level\":1023,\"humidity\":89,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04n\"}],\"clouds\":{\"all\":92},\"wind\":{\"speed\":4.7,\"deg\":34,\"gust\":6.96},\"visibility\":10000,\"pop\":0,\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2023-04-05 09:00:00\"},{\"dt\":1680696000,\"main\":{\"temp\":47.46,\"feels_like\":45.36,\"temp_min\":47.46,\"temp_max\":47.46,\"pressure\":1025,\"sea_level\":1025,\"grnd_level\":1024,\"humidity\":90,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":94},\"wind\":{\"speed\":4.81,\"deg\":76,\"gust\":8.99},\"visibility\":10000,\"pop\":0,\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2023-04-05 12:00:00\"}],\"city\":{\"id\":4930956,\"name\":\"Boston\",\"coord\":{\"lat\":42.3601,\"lon\":-71.0589},\"country\":\"US\",\"population\":617594,\"timezone\":-14400,\"sunrise\":1680258525,\"sunset\":1680304072}}'" ] }, "execution_count": 55, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import requests\n", "\n", "# get url as a string\n", "url_text = requests.get(url).text \n", "url_text" ] }, { "cell_type": "markdown", "id": "5e6ef615", "metadata": {}, "source": [ "The resulting JSON object is a dictionary of dictionaries (or a list of dictionaries) tree as seen in the previous section.\n", "\n", "You can convert it from string to dicts and lists via:" ] }, { "cell_type": "code", "execution_count": 67, "id": "7fe29f4b", "metadata": {}, "outputs": [], "source": [ "import json\n", "\n", "# convert json to a nested dict\n", "weather_dict = json.loads(url_text)\n", "\n", "weather_dict;" ] }, { "cell_type": "code", "execution_count": 70, "id": "aa60c358", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "{'dt': 1680296400,\n", " 'main': {'temp': 43.93,\n", " 'feels_like': 37.71,\n", " 'temp_min': 43.93,\n", " 'temp_max': 45.45,\n", " 'pressure': 1023,\n", " 'sea_level': 1023,\n", " 'grnd_level': 1020,\n", " 'humidity': 48,\n", " 'temp_kf': -0.84},\n", " 'weather': [{'id': 500,\n", " 'main': 'Rain',\n", " 'description': 'light rain',\n", " 'icon': '10d'}],\n", " 'clouds': {'all': 92},\n", " 'wind': {'speed': 12.28, 'deg': 194, 'gust': 18.52},\n", " 'visibility': 10000,\n", " 'pop': 0.4,\n", " 'rain': {'3h': 0.11},\n", " 'sys': {'pod': 'd'},\n", " 'dt_txt': '2023-03-31 21:00:00'}" ] }, "execution_count": 70, "metadata": {}, "output_type": "execute_result" } ], "source": [ "weather_dict['list'][2]" ] }, { "cell_type": "markdown", "id": "f3c16f79", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Cleaning up data from one instant" ] }, { "cell_type": "code", "execution_count": 71, "id": "ff400cff", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'dt': 1680274800,\n", " 'main': {'temp': 40.91,\n", " 'feels_like': 37.31,\n", " 'temp_min': 40.91,\n", " 'temp_max': 43.12,\n", " 'pressure': 1027,\n", " 'sea_level': 1027,\n", " 'grnd_level': 1026,\n", " 'humidity': 36,\n", " 'temp_kf': -1.23},\n", " 'weather': [{'id': 803,\n", " 'main': 'Clouds',\n", " 'description': 'broken clouds',\n", " 'icon': '04d'}],\n", " 'clouds': {'all': 75},\n", " 'wind': {'speed': 5.32, 'deg': 252, 'gust': 10.31},\n", " 'visibility': 10000,\n", " 'pop': 0,\n", " 'sys': {'pod': 'd'},\n", " 'dt_txt': '2023-03-31 15:00:00'}" ] }, "execution_count": 71, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d = weather_dict['list'][0]\n", "d" ] }, { "cell_type": "code", "execution_count": 72, "id": "82ec7713", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "{'dt': 1680274800,\n", " 'main': {'temp': 40.91,\n", " 'feels_like': 37.31,\n", " 'temp_min': 40.91,\n", " 'temp_max': 43.12,\n", " 'pressure': 1027,\n", " 'sea_level': 1027,\n", " 'grnd_level': 1026,\n", " 'humidity': 36,\n", " 'temp_kf': -1.23},\n", " 'weather': [{'id': 803,\n", " 'main': 'Clouds',\n", " 'description': 'broken clouds',\n", " 'icon': '04d'}],\n", " 'clouds': {'all': 75},\n", " 'wind': {'speed': 5.32, 'deg': 252, 'gust': 10.31},\n", " 'visibility': 10000,\n", " 'pop': 0,\n", " 'sys': {'pod': 'd'},\n", " 'dt_txt': '2023-03-31 15:00:00',\n", " 'datetime': datetime.datetime(2023, 3, 31, 11, 0)}" ] }, "execution_count": 72, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# lets convert from unix time to a datetime (easier to use)\n", "d['datetime'] = datetime.fromtimestamp(d['dt'])\n", "\n", "d" ] }, { "cell_type": "code", "execution_count": 82, "id": "e6bb1264", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'a': 1, 'b': 2}" ] }, "execution_count": 82, "metadata": {}, "output_type": "execute_result" } ], "source": [ "some_dict = {'a': 1, 'b': 2}\n", "some_dict" ] }, { "cell_type": "code", "execution_count": 84, "id": "47b8f878", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'a': 1, 'b': 2, 'c': 3, 'd': 1000}" ] }, "execution_count": 84, "metadata": {}, "output_type": "execute_result" } ], "source": [ "some_other_dict = {'c': 3, 'd': 1000}\n", "\n", "# some_dict.update(some_other_dict)\n", "\n", "for key, val in some_other_dict:\n", " some_dict[key] = val\n", "\n", "some_dict" ] }, { "cell_type": "code", "execution_count": 75, "id": "59086e4f", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "{'dt': 1680274800,\n", " 'weather': [{'id': 803,\n", " 'main': 'Clouds',\n", " 'description': 'broken clouds',\n", " 'icon': '04d'}],\n", " 'clouds': {'all': 75},\n", " 'wind': {'speed': 5.32, 'deg': 252, 'gust': 10.31},\n", " 'visibility': 10000,\n", " 'pop': 0,\n", " 'sys': {'pod': 'd'},\n", " 'dt_txt': '2023-03-31 15:00:00',\n", " 'datetime': datetime.datetime(2023, 3, 31, 11, 0),\n", " 'temp': 40.91,\n", " 'feels_like': 37.31,\n", " 'temp_min': 40.91,\n", " 'temp_max': 43.12,\n", " 'pressure': 1027,\n", " 'sea_level': 1027,\n", " 'grnd_level': 1026,\n", " 'humidity': 36,\n", " 'temp_kf': -1.23}" ] }, "execution_count": 75, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# lets \"flatten\" the main dictionary\n", "d.update(d['main'])\n", "del d['main']\n", "\n", "d" ] }, { "cell_type": "markdown", "id": "d252d486", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Why doesn't our datetime match the \"dt_txt\"?\n", "\n", "[lets examine the API's documentation](https://openweathermap.org/forecast5)\n", "\n", "(spoiler: the forecasted day is in UTC 00:00, our function converts it to our computer's timezone ... see how sneaky measuring time can be?)" ] }, { "cell_type": "markdown", "id": "346d2cf0", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Storing an API key in another file\n", "\n", "- security of your account\n", "- easily swappable with another user" ] }, { "cell_type": "code", "execution_count": 77, "id": "e5b86ee5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'eea5fcef9a7ea19505dc1c165bacac4a'" ] }, "execution_count": 77, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from weather_api import api_key\n", "\n", "# nice to keep it a bit more hidden in your code\n", "# (though you'd do better not to parrot it on a jupyter output cell,\n", "# I just want to show you all how this works)\n", "api_key" ] }, { "cell_type": "markdown", "id": "dbad9bd6", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## In Class Activity 2\n", " \n", "1. Make a function `get_forecast` which accepts:\n", " - `lat`\n", " - `lon`\n", " - `api_key`\n", " - `units` (default = 'imperial')\n", " \n", " and returns a dataframe of the forecasted weather\n", " \n", "```python\n", "# clean it up\n", "row_list = list()\n", "for d in weather_dict['list']:\n", " # process dictionary into a row\n", "\n", " # store\n", " row_list.append(d)\n", "\n", "# convert list of dictionaries to dataframe\n", "df = pd.DataFrame(row_list)\n", "```\n", "\n", "2. \"flatten\" the parts of the dictionary which make sense (see \"main\" example a few cells above).\n", "\n", "\n", "## Test Case\n", "\n", "Osaka, Japan is located at:\n", "\n", " 34.6937° N, 135.5023° E\n", " \n", "The first few rows of my call \n", "\n", "```python\n", "df_osaka = get_forecast(lat=34.6937, lon=135.5023, api_key=api_key)\n", "```\n", "\n", "yielded the following dataframe:\n", "\n", "| | dt | visibility | pop | dt_txt | all | speed | deg | gust | pod | temp | feels_like | temp_min | temp_max | pressure | sea_level | grnd_level | humidity | temp_kf | id | main | description | icon |\n", "|---|------------|------------|-----|---------------------|-----|-------|-----|------|-----|-------|------------|----------|----------|----------|-----------|------------|----------|---------|-----|--------|-------------|------|\n", "| 0 | 1680264000 | 10000 | 0 | 2023-03-31 12:00:00 | 0 | 4.79 | 222 | 7.87 | n | 60.35 | 58.24 | 60.04 | 60.35 | 1016 | 1016 | 1016 | 46 | 0.17 | 800 | Clear | clear sky | 01n |\n", "| 1 | 1680274800 | 10000 | 0 | 2023-03-31 15:00:00 | 11 | 3.18 | 211 | 6.51 | n | 59.38 | 57.56 | 57.43 | 59.38 | 1017 | 1017 | 1016 | 54 | 1.08 | 801 | Clouds | few clouds | 02n |\n", "| 2 | 1680285600 | 10000 | 0 | 2023-03-31 18:00:00 | 21 | 1.72 | 78 | 2.37 | n | 57.18 | 55.42 | 55.6 | 57.18 | 1017 | 1017 | 1015 | 60 | 0.88 | 801 | Clouds | few clouds | 02n |\n", "| 3 | 1680296400 | 10000 | 0 | 2023-03-31 21:00:00 | 4 | 3 | 58 | 4.52 | d | 53.69 | 51.82 | 53.69 | 53.69 | 1017 | 1017 | 1015 | 65 | 0 | 800 | Clear | clear sky | 01d |\n", "| 4 | 1680307200 | 10000 | 0 | 2023-04-01 00:00:00 | 2 | 3.69 | 50 | 4.34 | d | 61.18 | 59.25 | 61.18 | 61.18 | 1018 | 1018 | 1016 | 48 | 0 | 800 | Clear | clear sky | 01d |" ] }, { "cell_type": "code", "execution_count": 79, "id": "a65a3b4b", "metadata": {}, "outputs": [], "source": [ "from weather_api import api_key\n", "\n", "\n", "def get_forecast(lat, lon, api_key, units='imperial'):\n", " \"\"\" returns forecast\n", " \n", " https://openweathermap.org/forecast5\n", " \n", " Args:\n", " lat (float): lattitude (positive is north)\n", " lon (float): longitude (positive is east)\n", " api_key (str): api key for openweather\n", " units (str): standard, metric or imperial. see link for\n", " details\n", " \n", " Returns:\n", " df (pd.DataFrame): forecasted weather, one row per \n", " instant and one column per feature\n", " \"\"\"\n", " \n", " # get data from api\n", " url = f'https://api.openweathermap.org/data/2.5/forecast?lat={lat}&lon={lon}&units={units}&appid={api_key}'\n", " url_text = requests.get(url).text \n", " weather_dict = json.loads(url_text)\n", " \n", " # clean it up\n", " row_list = list()\n", " for d in weather_dict['list']:\n", " # process dictionary into a row\n", " \n", " # lets \"flatten\" the main dictionary\n", " for feat in ['clouds', 'wind', 'sys', 'main']:\n", " d.update(d[feat])\n", " del d[feat]\n", " \n", " # flattening \"weather\" is funny, its a list (of length 1) of dicts\n", " d.update(d['weather'][0])\n", " del d['weather']\n", "\n", " row_list.append(d)\n", " \n", " return pd.DataFrame(row_list)" ] }, { "cell_type": "code", "execution_count": 80, "id": "e2d2458c", "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
dtvisibilitypopdt_txtallspeeddeggustpodtemp...pressuresea_levelgrnd_levelhumiditytemp_kfidmaindescriptioniconrain
01680274800100000.002023-03-31 15:00:0005.6425510.49d42.44...10281028102436-0.39800Clearclear sky01dNaN
11680285600100000.002023-03-31 18:00:00316.4222212.33d45.30...10261026102133-3.19802Cloudsscattered clouds03dNaN
21680296400100000.352023-03-31 21:00:006713.4419621.12d43.30...10231023101951-0.24500Rainlight rain10d{'3h': 0.1}
31680307200100000.912023-04-01 00:00:0010010.3316831.03n40.30...101910191017810.00500Rainlight rain10n{'3h': 2.83}
41680318000100001.002023-04-01 03:00:0010011.4118234.87n44.56...101410141012930.00501Rainmoderate rain10n{'3h': 4.21}
51680328800100001.002023-04-01 06:00:001004.9423516.51n46.24...101110111009970.00500Rainlight rain10n{'3h': 0.41}
61680339600100000.002023-04-01 09:00:001002.572348.03n45.07...100810081006980.00804Cloudsovercast clouds04nNaN
716803504007870.162023-04-01 12:00:001004.2717117.85d46.47...100510051003990.00804Cloudsovercast clouds04dNaN
81680361200100001.002023-04-01 15:00:0010013.8920840.06d51.55...10001000998960.00501Rainmoderate rain10d{'3h': 5.22}
9168037200082901.002023-04-01 18:00:0010016.9821542.14d55.00...996996994930.00500Rainlight rain10d{'3h': 1.98}
101680382800100000.832023-04-01 21:00:009813.4421731.27d57.15...994994991880.00500Rainlight rain10d{'3h': 0.42}
111680393600100000.612023-04-02 00:00:007711.8319934.25n52.90...991991989940.00803Cloudsbroken clouds04nNaN
121680404400100001.002023-04-02 03:00:001009.0124823.98n50.83...990990988850.00501Rainmoderate rain10n{'3h': 5.28}
131680415200100001.002023-04-02 06:00:0010016.7127531.56n47.62...991991989800.00500Rainlight rain10n{'3h': 0.88}
141680426000100000.472023-04-02 09:00:009517.8329232.86n43.54...996996994760.00500Rainlight rain10n{'3h': 0.29}
151680436800100000.222023-04-02 12:00:006717.8131636.46d36.52...100410041002610.00803Cloudsbroken clouds04dNaN
161680447600100000.002023-04-02 15:00:00519.3032729.57d39.74...100810081006310.00800Clearclear sky01dNaN
171680458400100000.002023-04-02 18:00:00315.3533321.59d43.23...101210121010260.00800Clearclear sky01dNaN
181680469200100000.002023-04-02 21:00:00012.6832917.29d43.65...101410141012280.00800Clearclear sky01dNaN
191680480000100000.002023-04-03 00:00:00010.4233218.68n38.93...101810181015350.00800Clearclear sky01nNaN
201680490800100000.002023-04-03 03:00:0087.6333013.27n34.79...101910191017400.00800Clearclear sky01nNaN
211680501600100000.002023-04-03 06:00:0082.133053.51n33.30...102010201018410.00800Clearclear sky01nNaN
221680512400100000.002023-04-03 09:00:0074.031947.29n32.65...102110211018460.00800Clearclear sky01nNaN
231680523200100000.002023-04-03 12:00:00116.5820712.95d36.05...102210221019460.00801Cloudsfew clouds02dNaN
241680534000100000.002023-04-03 15:00:0010012.3721219.75d45.81...101910191017320.00804Cloudsovercast clouds04dNaN
251680544800100000.002023-04-03 18:00:009915.1021124.38d53.42...101610161013350.00804Cloudsovercast clouds04dNaN
261680555600100000.002023-04-03 21:00:0010015.3220631.54d52.43...101310131011450.00804Cloudsovercast clouds04dNaN
271680566400100000.002023-04-04 00:00:009915.1921541.41n48.43...101310131011630.00804Cloudsovercast clouds04nNaN
281680577200100000.002023-04-04 03:00:0010013.6222039.35n48.81...101310131010730.00804Cloudsovercast clouds04nNaN
291680588000100000.372023-04-04 06:00:001006.3526720.13n48.18...101410141011820.00500Rainlight rain10n{'3h': 0.19}
301680598800100000.892023-04-04 09:00:001004.091566.04n46.40...101410141012940.00500Rainlight rain10n{'3h': 1.38}
311680609600100000.792023-04-04 12:00:001005.061888.61d47.64...101510151013910.00804Cloudsovercast clouds04dNaN
321680620400100000.002023-04-04 15:00:00751.972913.60d56.52...101610161014670.00803Cloudsbroken clouds04dNaN
331680631200100000.002023-04-04 18:00:00882.443447.87d60.53...101610161014530.00804Cloudsovercast clouds04dNaN
341680642000100000.002023-04-04 21:00:001003.29118.34d61.48...101710171015520.00804Cloudsovercast clouds04dNaN
351680652800100000.002023-04-05 00:00:00973.801375.21n53.87...102010201018730.00804Cloudsovercast clouds04nNaN
361680663600100000.002023-04-05 03:00:00761.521141.99n52.36...102210221019790.00803Cloudsbroken clouds04nNaN
371680674400100000.002023-04-05 06:00:00832.211334.12n50.27...102210221020880.00803Cloudsbroken clouds04nNaN
381680685200100000.002023-04-05 09:00:00993.49404.27n48.99...102410241021910.00804Cloudsovercast clouds04nNaN
391680696000100000.002023-04-05 12:00:00974.47807.72d47.93...102510251022910.00804Cloudsovercast clouds04dNaN
\n", "

40 rows × 23 columns

\n", "
" ], "text/plain": [ " dt visibility pop dt_txt all speed deg gust \\\n", "0 1680274800 10000 0.00 2023-03-31 15:00:00 0 5.64 255 10.49 \n", "1 1680285600 10000 0.00 2023-03-31 18:00:00 31 6.42 222 12.33 \n", "2 1680296400 10000 0.35 2023-03-31 21:00:00 67 13.44 196 21.12 \n", "3 1680307200 10000 0.91 2023-04-01 00:00:00 100 10.33 168 31.03 \n", "4 1680318000 10000 1.00 2023-04-01 03:00:00 100 11.41 182 34.87 \n", "5 1680328800 10000 1.00 2023-04-01 06:00:00 100 4.94 235 16.51 \n", "6 1680339600 10000 0.00 2023-04-01 09:00:00 100 2.57 234 8.03 \n", "7 1680350400 787 0.16 2023-04-01 12:00:00 100 4.27 171 17.85 \n", "8 1680361200 10000 1.00 2023-04-01 15:00:00 100 13.89 208 40.06 \n", "9 1680372000 8290 1.00 2023-04-01 18:00:00 100 16.98 215 42.14 \n", "10 1680382800 10000 0.83 2023-04-01 21:00:00 98 13.44 217 31.27 \n", "11 1680393600 10000 0.61 2023-04-02 00:00:00 77 11.83 199 34.25 \n", "12 1680404400 10000 1.00 2023-04-02 03:00:00 100 9.01 248 23.98 \n", "13 1680415200 10000 1.00 2023-04-02 06:00:00 100 16.71 275 31.56 \n", "14 1680426000 10000 0.47 2023-04-02 09:00:00 95 17.83 292 32.86 \n", "15 1680436800 10000 0.22 2023-04-02 12:00:00 67 17.81 316 36.46 \n", "16 1680447600 10000 0.00 2023-04-02 15:00:00 5 19.30 327 29.57 \n", "17 1680458400 10000 0.00 2023-04-02 18:00:00 3 15.35 333 21.59 \n", "18 1680469200 10000 0.00 2023-04-02 21:00:00 0 12.68 329 17.29 \n", "19 1680480000 10000 0.00 2023-04-03 00:00:00 0 10.42 332 18.68 \n", "20 1680490800 10000 0.00 2023-04-03 03:00:00 8 7.63 330 13.27 \n", "21 1680501600 10000 0.00 2023-04-03 06:00:00 8 2.13 305 3.51 \n", "22 1680512400 10000 0.00 2023-04-03 09:00:00 7 4.03 194 7.29 \n", "23 1680523200 10000 0.00 2023-04-03 12:00:00 11 6.58 207 12.95 \n", "24 1680534000 10000 0.00 2023-04-03 15:00:00 100 12.37 212 19.75 \n", "25 1680544800 10000 0.00 2023-04-03 18:00:00 99 15.10 211 24.38 \n", "26 1680555600 10000 0.00 2023-04-03 21:00:00 100 15.32 206 31.54 \n", "27 1680566400 10000 0.00 2023-04-04 00:00:00 99 15.19 215 41.41 \n", "28 1680577200 10000 0.00 2023-04-04 03:00:00 100 13.62 220 39.35 \n", "29 1680588000 10000 0.37 2023-04-04 06:00:00 100 6.35 267 20.13 \n", "30 1680598800 10000 0.89 2023-04-04 09:00:00 100 4.09 156 6.04 \n", "31 1680609600 10000 0.79 2023-04-04 12:00:00 100 5.06 188 8.61 \n", "32 1680620400 10000 0.00 2023-04-04 15:00:00 75 1.97 291 3.60 \n", "33 1680631200 10000 0.00 2023-04-04 18:00:00 88 2.44 344 7.87 \n", "34 1680642000 10000 0.00 2023-04-04 21:00:00 100 3.29 11 8.34 \n", "35 1680652800 10000 0.00 2023-04-05 00:00:00 97 3.80 137 5.21 \n", "36 1680663600 10000 0.00 2023-04-05 03:00:00 76 1.52 114 1.99 \n", "37 1680674400 10000 0.00 2023-04-05 06:00:00 83 2.21 133 4.12 \n", "38 1680685200 10000 0.00 2023-04-05 09:00:00 99 3.49 40 4.27 \n", "39 1680696000 10000 0.00 2023-04-05 12:00:00 97 4.47 80 7.72 \n", "\n", " pod temp ... pressure sea_level grnd_level humidity temp_kf id \\\n", "0 d 42.44 ... 1028 1028 1024 36 -0.39 800 \n", "1 d 45.30 ... 1026 1026 1021 33 -3.19 802 \n", "2 d 43.30 ... 1023 1023 1019 51 -0.24 500 \n", "3 n 40.30 ... 1019 1019 1017 81 0.00 500 \n", "4 n 44.56 ... 1014 1014 1012 93 0.00 501 \n", "5 n 46.24 ... 1011 1011 1009 97 0.00 500 \n", "6 n 45.07 ... 1008 1008 1006 98 0.00 804 \n", "7 d 46.47 ... 1005 1005 1003 99 0.00 804 \n", "8 d 51.55 ... 1000 1000 998 96 0.00 501 \n", "9 d 55.00 ... 996 996 994 93 0.00 500 \n", "10 d 57.15 ... 994 994 991 88 0.00 500 \n", "11 n 52.90 ... 991 991 989 94 0.00 803 \n", "12 n 50.83 ... 990 990 988 85 0.00 501 \n", "13 n 47.62 ... 991 991 989 80 0.00 500 \n", "14 n 43.54 ... 996 996 994 76 0.00 500 \n", "15 d 36.52 ... 1004 1004 1002 61 0.00 803 \n", "16 d 39.74 ... 1008 1008 1006 31 0.00 800 \n", "17 d 43.23 ... 1012 1012 1010 26 0.00 800 \n", "18 d 43.65 ... 1014 1014 1012 28 0.00 800 \n", "19 n 38.93 ... 1018 1018 1015 35 0.00 800 \n", "20 n 34.79 ... 1019 1019 1017 40 0.00 800 \n", "21 n 33.30 ... 1020 1020 1018 41 0.00 800 \n", "22 n 32.65 ... 1021 1021 1018 46 0.00 800 \n", "23 d 36.05 ... 1022 1022 1019 46 0.00 801 \n", "24 d 45.81 ... 1019 1019 1017 32 0.00 804 \n", "25 d 53.42 ... 1016 1016 1013 35 0.00 804 \n", "26 d 52.43 ... 1013 1013 1011 45 0.00 804 \n", "27 n 48.43 ... 1013 1013 1011 63 0.00 804 \n", "28 n 48.81 ... 1013 1013 1010 73 0.00 804 \n", "29 n 48.18 ... 1014 1014 1011 82 0.00 500 \n", "30 n 46.40 ... 1014 1014 1012 94 0.00 500 \n", "31 d 47.64 ... 1015 1015 1013 91 0.00 804 \n", "32 d 56.52 ... 1016 1016 1014 67 0.00 803 \n", "33 d 60.53 ... 1016 1016 1014 53 0.00 804 \n", "34 d 61.48 ... 1017 1017 1015 52 0.00 804 \n", "35 n 53.87 ... 1020 1020 1018 73 0.00 804 \n", "36 n 52.36 ... 1022 1022 1019 79 0.00 803 \n", "37 n 50.27 ... 1022 1022 1020 88 0.00 803 \n", "38 n 48.99 ... 1024 1024 1021 91 0.00 804 \n", "39 d 47.93 ... 1025 1025 1022 91 0.00 804 \n", "\n", " main description icon rain \n", "0 Clear clear sky 01d NaN \n", "1 Clouds scattered clouds 03d NaN \n", "2 Rain light rain 10d {'3h': 0.1} \n", "3 Rain light rain 10n {'3h': 2.83} \n", "4 Rain moderate rain 10n {'3h': 4.21} \n", "5 Rain light rain 10n {'3h': 0.41} \n", "6 Clouds overcast clouds 04n NaN \n", "7 Clouds overcast clouds 04d NaN \n", "8 Rain moderate rain 10d {'3h': 5.22} \n", "9 Rain light rain 10d {'3h': 1.98} \n", "10 Rain light rain 10d {'3h': 0.42} \n", "11 Clouds broken clouds 04n NaN \n", "12 Rain moderate rain 10n {'3h': 5.28} \n", "13 Rain light rain 10n {'3h': 0.88} \n", "14 Rain light rain 10n {'3h': 0.29} \n", "15 Clouds broken clouds 04d NaN \n", "16 Clear clear sky 01d NaN \n", "17 Clear clear sky 01d NaN \n", "18 Clear clear sky 01d NaN \n", "19 Clear clear sky 01n NaN \n", "20 Clear clear sky 01n NaN \n", "21 Clear clear sky 01n NaN \n", "22 Clear clear sky 01n NaN \n", "23 Clouds few clouds 02d NaN \n", "24 Clouds overcast clouds 04d NaN \n", "25 Clouds overcast clouds 04d NaN \n", "26 Clouds overcast clouds 04d NaN \n", "27 Clouds overcast clouds 04n NaN \n", "28 Clouds overcast clouds 04n NaN \n", "29 Rain light rain 10n {'3h': 0.19} \n", "30 Rain light rain 10n {'3h': 1.38} \n", "31 Clouds overcast clouds 04d NaN \n", "32 Clouds broken clouds 04d NaN \n", "33 Clouds overcast clouds 04d NaN \n", "34 Clouds overcast clouds 04d NaN \n", "35 Clouds overcast clouds 04n NaN \n", "36 Clouds broken clouds 04n NaN \n", "37 Clouds broken clouds 04n NaN \n", "38 Clouds overcast clouds 04n NaN \n", "39 Clouds overcast clouds 04d NaN \n", "\n", "[40 rows x 23 columns]" ] }, "execution_count": 80, "metadata": {}, "output_type": "execute_result" } ], "source": [ "get_forecast(lat=42.21, lon=-71, api_key=api_key)" ] }, { "cell_type": "code", "execution_count": 27, "id": "1501f143", "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
dtvisibilitypopdt_txtallspeeddeggustpodtemp...temp_maxpressuresea_levelgrnd_levelhumiditytemp_kfidmaindescriptionicon
01680264000100000.002023-03-31 12:00:0004.792227.87n58.62...60.0410171017101644-0.79800Clearclear sky01n
11680274800100000.002023-03-31 15:00:00113.182116.51n58.23...58.23101710171016520.44801Cloudsfew clouds02n
21680285600100000.002023-03-31 18:00:00211.72782.37n56.61...56.61101710171015600.56801Cloudsfew clouds02n
31680296400100000.002023-03-31 21:00:0043.00584.52d53.69...53.69101710171015650.00800Clearclear sky01d
41680307200100000.002023-04-01 00:00:0023.69504.34d61.18...61.18101810181016480.00800Clearclear sky01d
51680318000100000.002023-04-01 03:00:0044.27216.55d70.41...70.41101610161014240.00800Clearclear sky01d
61680328800100000.002023-04-01 06:00:00152.803465.66d73.67...73.67101310131011180.00801Cloudsfew clouds02d
71680339600100000.002023-04-01 09:00:006610.2935613.22d67.93...67.93101410141012280.00803Cloudsbroken clouds04d
81680350400100000.002023-04-01 12:00:00818.901413.04n61.41...61.41101610161014410.00803Cloudsbroken clouds04n
91680361200100000.002023-04-01 15:00:00457.722312.24n57.07...57.07101610161014500.00802Cloudsscattered clouds03n
101680372000100000.002023-04-01 18:00:00276.602611.68n54.52...54.52101610161014510.00802Cloudsscattered clouds03n
111680382800100000.002023-04-01 21:00:00175.302910.80d53.11...53.11101710171015540.00801Cloudsfew clouds02d
121680393600100000.002023-04-02 00:00:0099.104513.24d61.88...61.88101710171015540.00800Clearclear sky01d
131680404400100000.002023-04-02 03:00:0079.803810.74d70.75...70.75101510151013360.00800Clearclear sky01d
141680415200100000.072023-04-02 06:00:001610.601810.47d73.06...73.06101310131012270.00801Cloudsfew clouds02d
151680426000100000.152023-04-02 09:00:004813.4735416.75d64.11...64.11101610161014380.00802Cloudsscattered clouds03d
161680436800100000.152023-04-02 12:00:002611.95316.62n57.18...57.18101910191017450.00802Cloudsscattered clouds03n
171680447600100000.002023-04-02 15:00:0009.57514.14n54.16...54.16101910191017560.00800Clearclear sky01n
181680458400100000.012023-04-02 18:00:0028.05412.71n52.68...52.68101910191017620.00800Clearclear sky01n
191680469200100000.012023-04-02 21:00:0046.493539.82d51.24...51.24102110211019660.00800Clearclear sky01d
201680480000100000.012023-04-03 00:00:0046.4037.90d57.79...57.79102310231021490.00800Clearclear sky01d
211680490800100000.112023-04-03 03:00:0004.25327.45d66.00...66.00102210221020300.00800Clearclear sky01d
221680501600100000.072023-04-03 06:00:0005.083376.35d69.35...69.35102110211019250.00800Clearclear sky01d
231680512400100000.002023-04-03 09:00:0016.203477.90d65.91...65.91102210221020330.00800Clearclear sky01d
241680523200100000.002023-04-03 12:00:0015.193529.15n58.71...58.71102510251023530.00800Clearclear sky01n
251680534000100000.002023-04-03 15:00:0001.923513.13n56.37...56.37102610261024610.00800Clearclear sky01n
261680544800100000.002023-04-03 18:00:00102.80643.89n54.70...54.70102610261024640.00800Clearclear sky01n
271680555600100000.002023-04-03 21:00:00133.09494.56d53.62...53.62102610261024690.00801Cloudsfew clouds02d
281680566400100000.002023-04-04 00:00:0081.451652.30d60.08...60.08102710271025580.00800Clearclear sky01d
291680577200100000.002023-04-04 03:00:00715.372376.11d65.08...65.08102510251024440.00803Cloudsbroken clouds04d
301680588000100000.002023-04-04 06:00:008511.432499.33d65.32...65.32102410241022460.00804Cloudsovercast clouds04d
311680598800100000.002023-04-04 09:00:007211.5623515.57d61.61...61.61102410241022580.00803Cloudsbroken clouds04d
321680609600100000.002023-04-04 12:00:00598.6822713.60n59.16...59.16102610261024620.00803Cloudsbroken clouds04n
331680620400100000.002023-04-04 15:00:0043.222145.59n57.25...57.25102510251023670.00800Clearclear sky01n
341680631200100000.002023-04-04 18:00:0092.731313.51n55.42...55.42102410241022690.00800Clearclear sky01n
351680642000100000.002023-04-04 21:00:00264.031125.10d52.93...52.93102410241022650.00802Cloudsscattered clouds03d
361680652800100000.002023-04-05 00:00:00534.05993.78d59.20...59.20102410241022480.00803Cloudsbroken clouds04d
371680663600100000.002023-04-05 03:00:001001.212016.96d66.20...66.20102110211019350.00804Cloudsovercast clouds04d
381680674400100000.002023-04-05 06:00:0010011.4824313.69d68.07...68.07101910191017440.00804Cloudsovercast clouds04d
391680685200100000.002023-04-05 09:00:009812.9722519.28d64.53...64.53101910191017500.00804Cloudsovercast clouds04d
\n", "

40 rows × 22 columns

\n", "
" ], "text/plain": [ " dt visibility pop dt_txt all speed deg gust \\\n", "0 1680264000 10000 0.00 2023-03-31 12:00:00 0 4.79 222 7.87 \n", "1 1680274800 10000 0.00 2023-03-31 15:00:00 11 3.18 211 6.51 \n", "2 1680285600 10000 0.00 2023-03-31 18:00:00 21 1.72 78 2.37 \n", "3 1680296400 10000 0.00 2023-03-31 21:00:00 4 3.00 58 4.52 \n", "4 1680307200 10000 0.00 2023-04-01 00:00:00 2 3.69 50 4.34 \n", "5 1680318000 10000 0.00 2023-04-01 03:00:00 4 4.27 21 6.55 \n", "6 1680328800 10000 0.00 2023-04-01 06:00:00 15 2.80 346 5.66 \n", "7 1680339600 10000 0.00 2023-04-01 09:00:00 66 10.29 356 13.22 \n", "8 1680350400 10000 0.00 2023-04-01 12:00:00 81 8.90 14 13.04 \n", "9 1680361200 10000 0.00 2023-04-01 15:00:00 45 7.72 23 12.24 \n", "10 1680372000 10000 0.00 2023-04-01 18:00:00 27 6.60 26 11.68 \n", "11 1680382800 10000 0.00 2023-04-01 21:00:00 17 5.30 29 10.80 \n", "12 1680393600 10000 0.00 2023-04-02 00:00:00 9 9.10 45 13.24 \n", "13 1680404400 10000 0.00 2023-04-02 03:00:00 7 9.80 38 10.74 \n", "14 1680415200 10000 0.07 2023-04-02 06:00:00 16 10.60 18 10.47 \n", "15 1680426000 10000 0.15 2023-04-02 09:00:00 48 13.47 354 16.75 \n", "16 1680436800 10000 0.15 2023-04-02 12:00:00 26 11.95 3 16.62 \n", "17 1680447600 10000 0.00 2023-04-02 15:00:00 0 9.57 5 14.14 \n", "18 1680458400 10000 0.01 2023-04-02 18:00:00 2 8.05 4 12.71 \n", "19 1680469200 10000 0.01 2023-04-02 21:00:00 4 6.49 353 9.82 \n", "20 1680480000 10000 0.01 2023-04-03 00:00:00 4 6.40 3 7.90 \n", "21 1680490800 10000 0.11 2023-04-03 03:00:00 0 4.25 32 7.45 \n", "22 1680501600 10000 0.07 2023-04-03 06:00:00 0 5.08 337 6.35 \n", "23 1680512400 10000 0.00 2023-04-03 09:00:00 1 6.20 347 7.90 \n", "24 1680523200 10000 0.00 2023-04-03 12:00:00 1 5.19 352 9.15 \n", "25 1680534000 10000 0.00 2023-04-03 15:00:00 0 1.92 351 3.13 \n", "26 1680544800 10000 0.00 2023-04-03 18:00:00 10 2.80 64 3.89 \n", "27 1680555600 10000 0.00 2023-04-03 21:00:00 13 3.09 49 4.56 \n", "28 1680566400 10000 0.00 2023-04-04 00:00:00 8 1.45 165 2.30 \n", "29 1680577200 10000 0.00 2023-04-04 03:00:00 71 5.37 237 6.11 \n", "30 1680588000 10000 0.00 2023-04-04 06:00:00 85 11.43 249 9.33 \n", "31 1680598800 10000 0.00 2023-04-04 09:00:00 72 11.56 235 15.57 \n", "32 1680609600 10000 0.00 2023-04-04 12:00:00 59 8.68 227 13.60 \n", "33 1680620400 10000 0.00 2023-04-04 15:00:00 4 3.22 214 5.59 \n", "34 1680631200 10000 0.00 2023-04-04 18:00:00 9 2.73 131 3.51 \n", "35 1680642000 10000 0.00 2023-04-04 21:00:00 26 4.03 112 5.10 \n", "36 1680652800 10000 0.00 2023-04-05 00:00:00 53 4.05 99 3.78 \n", "37 1680663600 10000 0.00 2023-04-05 03:00:00 100 1.21 201 6.96 \n", "38 1680674400 10000 0.00 2023-04-05 06:00:00 100 11.48 243 13.69 \n", "39 1680685200 10000 0.00 2023-04-05 09:00:00 98 12.97 225 19.28 \n", "\n", " pod temp ... temp_max pressure sea_level grnd_level humidity \\\n", "0 n 58.62 ... 60.04 1017 1017 1016 44 \n", "1 n 58.23 ... 58.23 1017 1017 1016 52 \n", "2 n 56.61 ... 56.61 1017 1017 1015 60 \n", "3 d 53.69 ... 53.69 1017 1017 1015 65 \n", "4 d 61.18 ... 61.18 1018 1018 1016 48 \n", "5 d 70.41 ... 70.41 1016 1016 1014 24 \n", "6 d 73.67 ... 73.67 1013 1013 1011 18 \n", "7 d 67.93 ... 67.93 1014 1014 1012 28 \n", "8 n 61.41 ... 61.41 1016 1016 1014 41 \n", "9 n 57.07 ... 57.07 1016 1016 1014 50 \n", "10 n 54.52 ... 54.52 1016 1016 1014 51 \n", "11 d 53.11 ... 53.11 1017 1017 1015 54 \n", "12 d 61.88 ... 61.88 1017 1017 1015 54 \n", "13 d 70.75 ... 70.75 1015 1015 1013 36 \n", "14 d 73.06 ... 73.06 1013 1013 1012 27 \n", "15 d 64.11 ... 64.11 1016 1016 1014 38 \n", "16 n 57.18 ... 57.18 1019 1019 1017 45 \n", "17 n 54.16 ... 54.16 1019 1019 1017 56 \n", "18 n 52.68 ... 52.68 1019 1019 1017 62 \n", "19 d 51.24 ... 51.24 1021 1021 1019 66 \n", "20 d 57.79 ... 57.79 1023 1023 1021 49 \n", "21 d 66.00 ... 66.00 1022 1022 1020 30 \n", "22 d 69.35 ... 69.35 1021 1021 1019 25 \n", "23 d 65.91 ... 65.91 1022 1022 1020 33 \n", "24 n 58.71 ... 58.71 1025 1025 1023 53 \n", "25 n 56.37 ... 56.37 1026 1026 1024 61 \n", "26 n 54.70 ... 54.70 1026 1026 1024 64 \n", "27 d 53.62 ... 53.62 1026 1026 1024 69 \n", "28 d 60.08 ... 60.08 1027 1027 1025 58 \n", "29 d 65.08 ... 65.08 1025 1025 1024 44 \n", "30 d 65.32 ... 65.32 1024 1024 1022 46 \n", "31 d 61.61 ... 61.61 1024 1024 1022 58 \n", "32 n 59.16 ... 59.16 1026 1026 1024 62 \n", "33 n 57.25 ... 57.25 1025 1025 1023 67 \n", "34 n 55.42 ... 55.42 1024 1024 1022 69 \n", "35 d 52.93 ... 52.93 1024 1024 1022 65 \n", "36 d 59.20 ... 59.20 1024 1024 1022 48 \n", "37 d 66.20 ... 66.20 1021 1021 1019 35 \n", "38 d 68.07 ... 68.07 1019 1019 1017 44 \n", "39 d 64.53 ... 64.53 1019 1019 1017 50 \n", "\n", " temp_kf id main description icon \n", "0 -0.79 800 Clear clear sky 01n \n", "1 0.44 801 Clouds few clouds 02n \n", "2 0.56 801 Clouds few clouds 02n \n", "3 0.00 800 Clear clear sky 01d \n", "4 0.00 800 Clear clear sky 01d \n", "5 0.00 800 Clear clear sky 01d \n", "6 0.00 801 Clouds few clouds 02d \n", "7 0.00 803 Clouds broken clouds 04d \n", "8 0.00 803 Clouds broken clouds 04n \n", "9 0.00 802 Clouds scattered clouds 03n \n", "10 0.00 802 Clouds scattered clouds 03n \n", "11 0.00 801 Clouds few clouds 02d \n", "12 0.00 800 Clear clear sky 01d \n", "13 0.00 800 Clear clear sky 01d \n", "14 0.00 801 Clouds few clouds 02d \n", "15 0.00 802 Clouds scattered clouds 03d \n", "16 0.00 802 Clouds scattered clouds 03n \n", "17 0.00 800 Clear clear sky 01n \n", "18 0.00 800 Clear clear sky 01n \n", "19 0.00 800 Clear clear sky 01d \n", "20 0.00 800 Clear clear sky 01d \n", "21 0.00 800 Clear clear sky 01d \n", "22 0.00 800 Clear clear sky 01d \n", "23 0.00 800 Clear clear sky 01d \n", "24 0.00 800 Clear clear sky 01n \n", "25 0.00 800 Clear clear sky 01n \n", "26 0.00 800 Clear clear sky 01n \n", "27 0.00 801 Clouds few clouds 02d \n", "28 0.00 800 Clear clear sky 01d \n", "29 0.00 803 Clouds broken clouds 04d \n", "30 0.00 804 Clouds overcast clouds 04d \n", "31 0.00 803 Clouds broken clouds 04d \n", "32 0.00 803 Clouds broken clouds 04n \n", "33 0.00 800 Clear clear sky 01n \n", "34 0.00 800 Clear clear sky 01n \n", "35 0.00 802 Clouds scattered clouds 03d \n", "36 0.00 803 Clouds broken clouds 04d \n", "37 0.00 804 Clouds overcast clouds 04d \n", "38 0.00 804 Clouds overcast clouds 04d \n", "39 0.00 804 Clouds overcast clouds 04d \n", "\n", "[40 rows x 22 columns]" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_osaka = get_forecast(lat=34.6937, lon=135.5023, api_key=api_key)\n", "df_osaka" ] } ], "metadata": { "celltoolbar": "Slideshow", "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.6" } }, "nbformat": 4, "nbformat_minor": 5 }