#!/usr/bin/env python # coding: utf-8 # In[144]: from datetime import datetime import matplotlib as plt from vortexasdk import CargoMovements, Geographies, Products # In[145]: singapore = [g.id for g in Geographies().search(term='singapore').to_list() if 'port' in g.layer] # In[146]: fuel_oil = [p.id for p in Products().search(term='fuel oil').to_list()] # In[147]: df = CargoMovements()\ .search(filter_activity='unloading_state', filter_destinations=singapore, filter_products=fuel_oil, filter_time_min=datetime(2019, 1, 1), filter_time_max=datetime(2019, 12, 31))\ .to_df() # In[148]: timestamp_col = 'events.cargo_port_unload_event.0.start_timestamp' df['month'] = pd.to_datetime(df[timestamp_col]).dt.month # In[149]: monthly_aggregate = df.groupby(by='month')['quantity'].sum() monthly_aggregate.plot(title='Singapore Fuel Oil Imports ahead of IMO 2020', ylim=(0, 3.5e7), figsize=(15, 5))