<jupyter_start><jupyter_text>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/).<jupyter_code>import vortexasdk as v
query = v.Vessels().search(vessel_classes='vlcc', term='ocean')

print(query)<jupyter_output>2020-12-10 14:56:08,231 vortexasdk.client — WARNING — You are using vortexasdk version 0.26.0, however version 0.27.1 is available.
You should consider upgrading via the 'pip install vortexasdk --upgrade' command.
[{'call_sign': 'SVBC9', 'dead_weight': 299999, 'gross_tonnage': 161273, 'id': '508bc4b650b1eb69c0054c6bc3b3f40996c032f74e0fca06e344cec0f6bf8922', 'imo': 9532757, 'mmsi': 241089000, 'name': 'OCEANIS', 'to_bow': 278, 'to_port': 52, 'to_starboard': 27, 'to_stern': 33, 'related_names': ['OCEANIS'], 'current_product_type': [{'cargo_movement_id': '881caebc9311dd066c59927a123f6dc0881caebc9311dd066c59927a123f6dc0', 'product_type': [{'id': '54af755a090118dcf9b0724c9a4e9f14745c26165385ffa7f1445bc768f06f11', 'layer': 'group', 'label': 'Crude/Condensates'}, {'id': '<KEY>', 'layer': 'group_product', 'label': 'Crude'}], 'active': False}, {'cargo_movement_id': '3488985d684cf1f28e1b2b8dd6589efc3488985d684cf1f28e1b2b8dd6589efc', 'prod[...]<jupyter_text>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:<jupyter_code>len(query)<jupyter_output><empty_output><jupyter_text>So there are 8 matching vessels. The data makes a little more sense if we look at just one of these:<jupyter_code>query[0]<jupyter_output><empty_output><jupyter_text>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:<jupyter_code>[vessel['name'] for vessel in query]<jupyter_output><empty_output><jupyter_text>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:<jupyter_code>query.to_df(columns=['name', 'imo', 'mmsi', 'related_names'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10911179173047474, 'fraction_numerical': 0.08843797856049004, 'mean_word_length': 7.242902208201893, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '494740', 'license': 'Apache-2.0', 'n_tokens_mistral': 1036, 'n_tokens_neox': 886, 'n_words': 279, 'path': 'docs/examples/academy/19. Querying the SDK.ipynb', 'repo_name': 'VorTECHsa/python-sdk', 'size': '2671'}