#!/usr/bin/env python # coding: utf-8 # # Module 4 # # ## Video 19: Querying the SDK # **Python for the Energy Industry** # # To access data from a given endpoint, we do a 'search', which returns all data matching a given criteria. # # Note the Vessels endpoint documentation can be [found here](https://vortechsa.github.io/python-sdk/endpoints/vessels/). # In[1]: import vortexasdk as v query = v.Vessels().search(vessel_classes='vlcc', term='ocean') print(query) # The data returned by the query is not interperatable in this format. We can think of it as a list of items, which each correspond to an item (in this case a vessel) matching the search query. We can see how many matching items were found: # In[2]: len(query) # So there are 8 matching vessels. The data makes a little more sense if we look at just one of these: # In[3]: query[0] # There's a lot of information here! Looking at the keys in this dictionary structure, we can see basic information about the vessel, along with the cargo that it is currently carrying. # # We can use a list comprehension to get the values of a particular key for each vessel in the returned data: # In[4]: [vessel['name'] for vessel in query] # The query has a function `.to_df` which will convert the data into a pandas DataFrame structure. By default, it will only include some of the more important bits of information. We can also specifically list which colulmns we would like: # In[5]: query.to_df(columns=['name', 'imo', 'mmsi', 'related_names']) # ### Exercise # # # Using the Geographies endpoint, do a search for the term 'portsmouth'. How many matching queries are there? Where are they located? # # Note the Geographies endpoint documentation can be [found here](https://vortechsa.github.io/python-sdk/endpoints/geographies/). # In[ ]: