{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Module 7\n", "\n", "## Video 33: Analysing Imports/Exports Data\n", "**Python for the Energy Industry**\n", "\n", "We will now extend the work of the previous lesson towards and example of analysing data on imports and exports.\n", "\n", "\n", "[Cargo Time Series documentation.](https://vortechsa.github.io/python-sdk/endpoints/cargo_timeseries/)\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# initial imports\n", "import pandas as pd\n", "import numpy as np\n", "from datetime import datetime\n", "from dateutil.relativedelta import relativedelta\n", "import vortexasdk as v\n", "\n", "# The cargo unit for the time series (barrels)\n", "TS_UNIT = 'b'\n", "\n", "# The granularity of the time series\n", "TS_FREQ = 'day'\n", "# datetimes to access last 7 weeks of data\n", "now = datetime.utcnow()\n", "seven_weeks_ago = now - relativedelta(weeks=7)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's grab the Chinese imports data, as we did in the previous lesson:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# Find China ID\n", "china = [g.id for g in v.Geographies().search('china').to_list() if 'country' in g.layer]\n", "assert len(china) == 1\n", "\n", "search_result = v.CargoTimeSeries().search(\n", " timeseries_frequency=TS_FREQ,\n", " timeseries_unit=TS_UNIT,\n", " filter_destinations=china,\n", " filter_time_min=seven_weeks_ago,\n", " filter_time_max=now,\n", " filter_activity=\"unloading_state\",\n", ")\n", "\n", "imports_df = search_result.to_df().rename(columns={'key':'date','value':'total'})[['date','total']]" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | date | \n", "total | \n", "
---|---|---|
0 | \n", "2020-10-23 00:00:00+00:00 | \n", "40022773 | \n", "
1 | \n", "2020-10-24 00:00:00+00:00 | \n", "47899427 | \n", "
2 | \n", "2020-10-25 00:00:00+00:00 | \n", "41827724 | \n", "
3 | \n", "2020-10-26 00:00:00+00:00 | \n", "44226467 | \n", "
4 | \n", "2020-10-27 00:00:00+00:00 | \n", "43840099 | \n", "