├── Data └── dataset-covid19-trade-impact.csv ├── README.md ├── country_analysis.png ├── covid_19_trade_impact_analysis.ipynb ├── exports_vs_imports.png ├── overall_trade_trend.png ├── top_commodities_affected.png └── transport_mode_analysis.png /README.md: -------------------------------------------------------------------------------- 1 | # COVID-19 Trade Impact Data Analysis 2 | This repository contains an analysis of the effects of COVID-19 on trade trends up to December 2021. The dataset used provides daily trade values. We identified annual trends, commodity impacts, transport mode influences, and country-specific effects by using Python, Pandas and Matplotlib 3 | 4 | # :man_student:Dashboard::electron: 5 | 6 | ![Overall Trade Trend](https://github.com/farhansadeed/Python-COVID-19-Trade-Impact-Data-Analysis/blob/main/overall_trade_trend.png) 7 | Fig 1: Overall Trade Trend 8 | 9 | ![Exports vs. Imports](https://github.com/farhansadeed/Python-COVID-19-Trade-Impact-Data-Analysis/blob/main/exports_vs_imports.png) 10 | Fig 2: Exports vs. Imports 11 | 12 | ![Top Commodities Affected](https://github.com/farhansadeed/Python-COVID-19-Trade-Impact-Data-Analysis/blob/main/top_commodities_affected.png) 13 | Fig 3: Top Commodities Affected 14 | 15 | ![Transport Mode Analysis](https://github.com/farhansadeed/Python-COVID-19-Trade-Impact-Data-Analysis/blob/main/transport_mode_analysis.png) 16 | Fig 4: Transport Mode Analysis 17 | 18 | ![Country Analysis](https://github.com/farhansadeed/Python-COVID-19-Trade-Impact-Data-Analysis/blob/main/transport_mode_analysis.png) 19 | Fig 5: Country Analysis 20 | ## Dataset 21 | 22 | The dataset, "Effects of COVID-19 on trade: At 15 December 2021 (provisional)", contains columns indicating trade direction (imports/exports), date, country, commodity type, transport mode, and trade values. 23 | 24 | ## Analyses Performed 25 | 26 | 1. **Overall Trade Trend**: Visualized the increasing trade value over the years 2019, 2020, and 2021. 27 | 2. **Exports vs. Imports**: Compared the cumulative exports and imports over the mentioned years. 28 | 3. **Top Commodities Affected**: Identified commodities with the most significant changes in trade value. 29 | 4. **Transport Mode Analysis**: Analyzed the effect on different modes of transport. 30 | 5. **Country Analysis**: Checked the trade impact on specific countries. 31 | 32 | ## Tools Used: 33 | 34 | - **Python**: The primary language for data processing and analysis. 35 | - **Pandas**: Used for data manipulation and analysis. 36 | - **Matplotlib**: For data visualization and creating charts. 37 | 38 | 39 | -------------------------------------------------------------------------------- /country_analysis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/farhansadeed/Python-COVID-19-Trade-Impact-Data-Analysis/682cc7c78e29feb4666fe9f4aa716460ec28e356/country_analysis.png -------------------------------------------------------------------------------- /covid_19_trade_impact_analysis.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "id": "b9090699", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "\n", 11 | "import pandas as pd\n", 12 | "\n", 13 | "# Load the dataset into a DataFrame\n", 14 | "data = pd.read_csv('/mnt/data/effects-of-covid-19-on-trade-at-15-december-2021-provisional.csv')\n", 15 | "\n", 16 | "# Display the first few rows\n", 17 | "data.head()\n", 18 | "import matplotlib.pyplot as plt\n", 19 | "\n", 20 | "# Filter data for the years 2019, 2020, and 2021\n", 21 | "data_filtered = data[data['Year'].isin([2019, 2020, 2021])]\n", 22 | "\n", 23 | "# Group by Year and Date and sum the cumulative values\n", 24 | "grouped_data = data_filtered.groupby(['Year', 'Date'])['Cumulative'].mean().reset_index()\n", 25 | "\n", 26 | "# Plot\n", 27 | "plt.figure(figsize=(14, 7))\n", 28 | "for year in [2019, 2020, 2021]:\n", 29 | " yearly_data = grouped_data[grouped_data['Year'] == year]\n", 30 | " plt.plot(yearly_data['Date'], yearly_data['Cumulative'], label=f'Year {year}')\n", 31 | "\n", 32 | "plt.title('Overall Trade Trend (2019-2021)')\n", 33 | "plt.xlabel('Date')\n", 34 | "plt.ylabel('Cumulative Trade Value')\n", 35 | "plt.xticks(yearly_data['Date'][::30], rotation=45)\n", 36 | "plt.legend()\n", 37 | "plt.tight_layout()\n", 38 | "plt.show()\n", 39 | "# Group by Year, Date, and Direction and sum the cumulative values\n", 40 | "grouped_direction = data_filtered.groupby(['Year', 'Date', 'Direction'])['Cumulative'].mean().reset_index()\n", 41 | "\n", 42 | "# Plot\n", 43 | "plt.figure(figsize=(14, 7))\n", 44 | "for year in [2019, 2020, 2021]:\n", 45 | " for direction in ['Exports', 'Imports']:\n", 46 | " subset_data = grouped_direction[(grouped_direction['Year'] == year) & (grouped_direction['Direction'] == direction)]\n", 47 | " plt.plot(subset_data['Date'], subset_data['Cumulative'], label=f'{direction} {year}')\n", 48 | "\n", 49 | "plt.title('Exports vs. Imports (2019-2021)')\n", 50 | "plt.xlabel('Date')\n", 51 | "plt.ylabel('Cumulative Trade Value')\n", 52 | "plt.xticks(subset_data['Date'][::30], rotation=45)\n", 53 | "plt.legend()\n", 54 | "plt.tight_layout()\n", 55 | "plt.show()\n", 56 | "# Group by Year, Commodity and sum the cumulative values for the last date of each year\n", 57 | "last_dates = data_filtered.groupby('Year')['Date'].max().values\n", 58 | "commodity_data = data_filtered[data_filtered['Date'].isin(last_dates)].groupby(['Year', 'Commodity'])['Cumulative'].mean().reset_index()\n", 59 | "\n", 60 | "# Calculate change in trade value for each commodity between 2019-2020 and 2020-2021\n", 61 | "commodity_data['Change_2019_2020'] = commodity_data.groupby('Commodity').apply(lambda x: x['Cumulative'].pct_change().fillna(0)).values\n", 62 | "commodity_data['Change_2020_2021'] = commodity_data.groupby('Commodity').apply(lambda x: x['Cumulative'].pct_change().shift(-1).fillna(0)).values\n", 63 | "\n", 64 | "# Filter for commodities with the most significant changes\n", 65 | "top_commodities_2019_2020 = commodity_data[commodity_data['Year'] == 2020].sort_values('Change_2019_2020', ascending=False).head(10)\n", 66 | "top_commodities_2020_2021 = commodity_data[commodity_data['Year'] == 2021].sort_values('Change_2020_2021', ascending=False).head(10)\n", 67 | "\n", 68 | "# Plot\n", 69 | "fig, ax = plt.subplots(2, 1, figsize=(14, 14))\n", 70 | "\n", 71 | "ax[0].barh(top_commodities_2019_2020['Commodity'], top_commodities_2019_2020['Change_2019_2020']*100, color='skyblue')\n", 72 | "ax[0].set_title('Top 10 Commodities with Highest Growth in Trade Value (2019-2020)')\n", 73 | "ax[0].set_xlabel('% Change')\n", 74 | "ax[0].invert_yaxis()\n", 75 | "\n", 76 | "ax[1].barh(top_commodities_2020_2021['Commodity'], top_commodities_2020_2021['Change_2020_2021']*100, color='coral')\n", 77 | "ax[1].set_title('Top 10 Commodities with Highest Growth in Trade Value (2020-2021)')\n", 78 | "ax[1].set_xlabel('% Change')\n", 79 | "ax[1].invert_yaxis()\n", 80 | "\n", 81 | "plt.tight_layout()\n", 82 | "plt.show()\n", 83 | "# Group by Year, Transport_Mode and sum the cumulative values for the last date of each year\n", 84 | "transport_data = data_filtered[data_filtered['Date'].isin(last_dates)].groupby(['Year', 'Transport_Mode'])['Cumulative'].mean().reset_index()\n", 85 | "\n", 86 | "# Calculate change in trade value for each transport mode between 2019-2020 and 2020-2021\n", 87 | "transport_data['Change_2019_2020'] = transport_data.groupby('Transport_Mode').apply(lambda x: x['Cumulative'].pct_change().fillna(0)).values\n", 88 | "transport_data['Change_2020_2021'] = transport_data.groupby('Transport_Mode').apply(lambda x: x['Cumulative'].pct_change().shift(-1).fillna(0)).values\n", 89 | "\n", 90 | "# Plot\n", 91 | "fig, ax = plt.subplots(2, 1, figsize=(14, 14))\n", 92 | "\n", 93 | "ax[0].barh(transport_data[transport_data['Year'] == 2020]['Transport_Mode'], transport_data[transport_data['Year'] == 2020]['Change_2019_2020']*100, color='skyblue')\n", 94 | "ax[0].set_title('Change in Trade Value by Transport Mode (2019-2020)')\n", 95 | "ax[0].set_xlabel('% Change')\n", 96 | "ax[0].invert_yaxis()\n", 97 | "\n", 98 | "ax[1].barh(transport_data[transport_data['Year'] == 2021]['Transport_Mode'], transport_data[transport_data['Year'] == 2021]['Change_2020_2021']*100, color='coral')\n", 99 | "ax[1].set_title('Change in Trade Value by Transport Mode (2020-2021)')\n", 100 | "ax[1].set_xlabel('% Change')\n", 101 | "ax[1].invert_yaxis()\n", 102 | "\n", 103 | "plt.tight_layout()\n", 104 | "plt.show()\n", 105 | "# Group by Year, Country and sum the cumulative values for the last date of each year\n", 106 | "country_data = data_filtered[data_filtered['Date'].isin(last_dates) & (data_filtered['Country'] != 'All')].groupby(['Year', 'Country'])['Cumulative'].mean().reset_index()\n", 107 | "\n", 108 | "# Calculate change in trade value for each country between 2019-2020 and 2020-2021\n", 109 | "country_data['Change_2019_2020'] = country_data.groupby('Country').apply(lambda x: x['Cumulative'].pct_change().fillna(0)).values\n", 110 | "country_data['Change_2020_2021'] = country_data.groupby('Country').apply(lambda x: x['Cumulative'].pct_change().shift(-1).fillna(0)).values\n", 111 | "\n", 112 | "# Filter for countries with the most significant changes\n", 113 | "top_countries_2019_2020 = country_data[country_data['Year'] == 2020].sort_values('Change_2019_2020', ascending=False).head(10)\n", 114 | "top_countries_2020_2021 = country_data[country_data['Year'] == 2021].sort_values('Change_2020_2021', ascending=False).head(10)\n", 115 | "\n", 116 | "# Plot\n", 117 | "fig, ax = plt.subplots(2, 1, figsize=(14, 14))\n", 118 | "\n", 119 | "ax[0].barh(top_countries_2019_2020['Country'], top_countries_2019_2020['Change_2019_2020']*100, color='skyblue')\n", 120 | "ax[0].set_title('Top 10 Countries with Highest Growth in Trade Value (2019-2020)')\n", 121 | "ax[0].set_xlabel('% Change')\n", 122 | "ax[0].invert_yaxis()\n", 123 | "\n", 124 | "ax[1].barh(top_countries_2020_2021['Country'], top_countries_2020_2021['Change_2020_2021']*100, color='coral')\n", 125 | "ax[1].set_title('Top 10 Countries with Highest Growth in Trade Value (2020-2021)')\n", 126 | "ax[1].set_xlabel('% Change')\n", 127 | "ax[1].invert_yaxis()\n", 128 | "\n", 129 | "plt.tight_layout()\n", 130 | "plt.show()\n", 131 | "# Save the created visualizations to PNG format\n", 132 | "\n", 133 | "# 1. Overall Trade Trend\n", 134 | "plt.figure(figsize=(14, 7))\n", 135 | "for year in [2019, 2020, 2021]:\n", 136 | " yearly_data = grouped_data[grouped_data['Year'] == year]\n", 137 | " plt.plot(yearly_data['Date'], yearly_data['Cumulative'], label=f'Year {year}')\n", 138 | "plt.title('Overall Trade Trend (2019-2021)')\n", 139 | "plt.xlabel('Date')\n", 140 | "plt.ylabel('Cumulative Trade Value')\n", 141 | "plt.xticks(yearly_data['Date'][::30], rotation=45)\n", 142 | "plt.legend()\n", 143 | "plt.tight_layout()\n", 144 | "plt.savefig(\"/mnt/data/overall_trade_trend.png\")\n", 145 | "\n", 146 | "# 2. Exports vs. Imports\n", 147 | "plt.figure(figsize=(14, 7))\n", 148 | "for year in [2019, 2020, 2021]:\n", 149 | " for direction in ['Exports', 'Imports']:\n", 150 | " subset_data = grouped_direction[(grouped_direction['Year'] == year) & (grouped_direction['Direction'] == direction)]\n", 151 | " plt.plot(subset_data['Date'], subset_data['Cumulative'], label=f'{direction} {year}')\n", 152 | "plt.title('Exports vs. Imports (2019-2021)')\n", 153 | "plt.xlabel('Date')\n", 154 | "plt.ylabel('Cumulative Trade Value')\n", 155 | "plt.xticks(subset_data['Date'][::30], rotation=45)\n", 156 | "plt.legend()\n", 157 | "plt.tight_layout()\n", 158 | "plt.savefig(\"/mnt/data/exports_vs_imports.png\")\n", 159 | "\n", 160 | "# 3. Top Commodities Affected\n", 161 | "fig, ax = plt.subplots(2, 1, figsize=(14, 14))\n", 162 | "ax[0].barh(top_commodities_2019_2020['Commodity'], top_commodities_2019_2020['Change_2019_2020']*100, color='skyblue')\n", 163 | "ax[0].set_title('Top 10 Commodities with Highest Growth in Trade Value (2019-2020)')\n", 164 | "ax[0].set_xlabel('% Change')\n", 165 | "ax[0].invert_yaxis()\n", 166 | "ax[1].barh(top_commodities_2020_2021['Commodity'], top_commodities_2020_2021['Change_2020_2021']*100, color='coral')\n", 167 | "ax[1].set_title('Top 10 Commodities with Highest Growth in Trade Value (2020-2021)')\n", 168 | "ax[1].set_xlabel('% Change')\n", 169 | "ax[1].invert_yaxis()\n", 170 | "plt.tight_layout()\n", 171 | "plt.savefig(\"/mnt/data/top_commodities_affected.png\")\n", 172 | "\n", 173 | "# 4. Transport Mode Analysis\n", 174 | "fig, ax = plt.subplots(2, 1, figsize=(14, 14))\n", 175 | "ax[0].barh(transport_data[transport_data['Year'] == 2020]['Transport_Mode'], transport_data[transport_data['Year'] == 2020]['Change_2019_2020']*100, color='skyblue')\n", 176 | "ax[0].set_title('Change in Trade Value by Transport Mode (2019-2020)')\n", 177 | "ax[0].set_xlabel('% Change')\n", 178 | "ax[0].invert_yaxis()\n", 179 | "ax[1].barh(transport_data[transport_data['Year'] == 2021]['Transport_Mode'], transport_data[transport_data['Year'] == 2021]['Change_2020_2021']*100, color='coral')\n", 180 | "ax[1].set_title('Change in Trade Value by Transport Mode (2020-2021)')\n", 181 | "ax[1].set_xlabel('% Change')\n", 182 | "ax[1].invert_yaxis()\n", 183 | "plt.tight_layout()\n", 184 | "plt.savefig(\"/mnt/data/transport_mode_analysis.png\")\n", 185 | "\n", 186 | "# 5. Country Analysis\n", 187 | "fig, ax = plt.subplots(2, 1, figsize=(14, 14))\n", 188 | "ax[0].barh(top_countries_2019_2020['Country'], top_countries_2019_2020['Change_2019_2020']*100, color='skyblue')\n", 189 | "ax[0].set_title('Top 10 Countries with Highest Growth in Trade Value (2019-2020)')\n", 190 | "ax[0].set_xlabel('% Change')\n", 191 | "ax[0].invert_yaxis()\n", 192 | "ax[1].barh(top_countries_2020_2021['Country'], top_countries_2020_2021['Change_2020_2021']*100, color='coral')\n", 193 | "ax[1].set_title('Top 10 Countries with Highest Growth in Trade Value (2020-2021)')\n", 194 | "ax[1].set_xlabel('% Change')\n", 195 | "ax[1].invert_yaxis()\n", 196 | "plt.tight_layout()\n", 197 | "plt.savefig(\"/mnt/data/country_analysis.png\")\n", 198 | "\n", 199 | "# List of saved PNG files\n", 200 | "saved_files = [\n", 201 | " \"/mnt/data/overall_trade_trend.png\",\n", 202 | " \"/mnt/data/exports_vs_imports.png\",\n", 203 | " \"/mnt/data/top_commodities_affected.png\",\n", 204 | " \"/mnt/data/transport_mode_analysis.png\",\n", 205 | " \"/mnt/data/country_analysis.png\"\n", 206 | "]\n", 207 | "\n", 208 | "saved_files\n", 209 | "# Save the analysis to a Jupyter notebook (.ipynb) format\n", 210 | "notebook_path = \"/mnt/data/covid_19_trade_impact_analysis.ipynb\"\n", 211 | "\n", 212 | "# Save the current session as a Jupyter notebook\n", 213 | "import nbformat\n", 214 | "from IPython.display import display, Javascript\n", 215 | "\n", 216 | "def notebook_save(notebook_path):\n", 217 | " notebook_name = 'analysis'\n", 218 | " script = f'''\n", 219 | " require([\"base/js/namespace\"],function(Jupyter) {{\n", 220 | " Jupyter.notebook.save_checkpoint();\n", 221 | " Jupyter.notebook.to_notebook_path(\"{notebook_name}\");\n", 222 | " }});\n", 223 | " '''\n", 224 | " display(Javascript(script))\n", 225 | " return notebook_name + '.ipynb'\n", 226 | "\n", 227 | "# Save the notebook\n", 228 | "notebook_save(notebook_path)\n", 229 | "\n", 230 | "notebook_path\n", 231 | "# Save the current session as a Jupyter notebook\n", 232 | "import io\n", 233 | "import nbformat\n", 234 | "\n", 235 | "# Capture current IPython session commands\n", 236 | "history = _ih\n", 237 | "\n", 238 | "notebook_content = nbformat.v4.new_notebook()\n", 239 | "notebook_content.cells.append(nbformat.v4.new_code_cell('\\n'.join(history)))\n", 240 | "\n", 241 | "# Write to a .ipynb file\n", 242 | "with io.open(notebook_path, 'wt', encoding='utf-8') as f:\n", 243 | " nbformat.write(notebook_content, f)\n", 244 | "\n", 245 | "notebook_path" 246 | ] 247 | } 248 | ], 249 | "metadata": {}, 250 | "nbformat": 4, 251 | "nbformat_minor": 5 252 | } 253 | -------------------------------------------------------------------------------- /exports_vs_imports.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/farhansadeed/Python-COVID-19-Trade-Impact-Data-Analysis/682cc7c78e29feb4666fe9f4aa716460ec28e356/exports_vs_imports.png -------------------------------------------------------------------------------- /overall_trade_trend.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/farhansadeed/Python-COVID-19-Trade-Impact-Data-Analysis/682cc7c78e29feb4666fe9f4aa716460ec28e356/overall_trade_trend.png -------------------------------------------------------------------------------- /top_commodities_affected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/farhansadeed/Python-COVID-19-Trade-Impact-Data-Analysis/682cc7c78e29feb4666fe9f4aa716460ec28e356/top_commodities_affected.png -------------------------------------------------------------------------------- /transport_mode_analysis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/farhansadeed/Python-COVID-19-Trade-Impact-Data-Analysis/682cc7c78e29feb4666fe9f4aa716460ec28e356/transport_mode_analysis.png --------------------------------------------------------------------------------