In [52]:
import requests
import pandas as pd
import datetime

In [53]:
response = requests.get("http://api.open-notify.org/iss-now.json")

In [54]:
# A status code of 200 means the API call was processed successfully.
response.status_code


Out[54]:
200

In [55]:
# Read the data into a Pandas DataFrame and transpose it for easy viewing.
df = pd.read_json(response.content)

In [56]:
# Create a date object with today's date.
today = datetime.date.today().strftime('%b %d %Y')

In [57]:
# Rename the iss_position column as today's date.
df.rename(index=str, columns = {'iss_position':today}, inplace=True)

In [58]:
# Drop the columns we are not using.
df.drop(['message', 'timestamp'], axis=1, inplace=True)

In [59]:
# Print the current table.
df


Out[59]:
Jan 02 2017
latitude 50.632
longitude -5.951

In [41]:
# Access the API endpoint specifying the number of astronauts currently aboard the ISS
response = requests.get("http://api.open-notify.org/astros.json")

In [ ]:
# Convert JSON object to dictionary and access the 'number' key.
astronauts = response.json()['number']

In [60]:
# Add another row to the dataframe with the current number of astronauts.
df.ix['astronauts_in_space'] = astronauts

In [68]:
# Transpose the dataframe so that each column can represent a separate data type.
df = df.T
df


Out[68]:
latitude longitude astronauts_in_space
Jan 02 2017 50.632 -5.951 6.0

In [72]:
# Imagine you have a master dataframe where you are tracking these observations over time.
df_master = pd.DataFrame([[35.895,-4.233,7.0],[40.110,-4.855,6.0]], 
                         index=['Dec 31 2017', 'Jan 1 2017'],
                        columns = ['latitude', 'longitude', 'astronauts_in_space'])

In [73]:
df_master


Out[73]:
latitude longitude astronauts_in_space
Dec 31 2017 35.895 -4.233 7.0
Jan 1 2017 40.110 -4.855 6.0

In [74]:
# Add the new observation to the master dataframe
df_master = df_master.append(df)
df_master


Out[74]:
latitude longitude astronauts_in_space
Dec 31 2017 35.895 -4.233 7.0
Jan 1 2017 40.110 -4.855 6.0
Jan 02 2017 50.632 -5.951 6.0

In [ ]: