{"id":3430,"date":"2021-02-28T22:13:51","date_gmt":"2021-02-28T21:13:51","guid":{"rendered":"http:\/\/van-maanen.com\/?p=3430"},"modified":"2021-02-28T22:13:51","modified_gmt":"2021-02-28T21:13:51","slug":"python-using-api","status":"publish","type":"post","link":"http:\/\/archief.van-maanen.com\/?p=3430","title":{"rendered":"Python using API"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A small example on using an API is provided below. I have attempted to make the programme as small as possible. It shows how the response is derived. This response is then translated into a dataframe. this dataframe is then split into keys and values.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import requests\nimport pandas as pd<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">response = requests.get(\"http:\/\/api.open-notify.org\/astros.json\")\nif (response.status_code == 200):\n  dataframe = pd.DataFrame.from_dict(response.json(),   orient=\"Index\")\n  ff=dataframe.iloc[2]\n  w = ff[0]\n  for j in range(len(w)):\n    for key, value in w[j].items():\n    print('key ',key,' value ',value)<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">elif (response.status_code == 404) :\n  print(\"Result not found!\")<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A small example on using an API is provided below. I have attempted to make the programme as small as possible. It shows how the response is derived. This response is then translated into a dataframe. this dataframe is then split into keys and values. import requests import pandas as pd response = requests.get(&#8220;http:\/\/api.open-notify.org\/astros.json&#8221;) if [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-3430","post","type-post","status-publish","format-standard","hentry","category-allgemein"],"_links":{"self":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/3430","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3430"}],"version-history":[{"count":0,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/3430\/revisions"}],"wp:attachment":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3430"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}