"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"totalImports.head(10).plot(kind='barh')"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"activity": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The UK exports to 107 countries.\n",
"The 5 biggest importers from the UK are:\n"
]
},
{
"data": {
"text/plain": [
"Partner\n",
"Ireland 128155891\n",
"Netherlands 18018603\n",
"China 14111163\n",
"Germany 10828464\n",
"China, Hong Kong SAR 9482458\n",
"Name: Trade Value (US$), dtype: int64"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"exports = milk[milk[FLOW] == 'Exports']\n",
"grouped = exports.groupby([PARTNER])\n",
"print('The UK exports to', len(grouped), 'countries.')\n",
"print('The 5 biggest importers from the UK are:')\n",
"grouped[VALUE].aggregate(sum).sort_values(ascending=False,inplace=False).head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Regular importers\n",
"\n",
"Given that there are two commodities, the third question, 'Which are the regular customers, i.e. which countries buy milk from the UK every month?', is meant in the sense that a regular customer imports both commodities every month. This means that if the exports dataframe is grouped by country, each group has exactly ten rows (two commodities bought each of the five months). To see the countries, only the first month of one commodity has to be listed, as by definition it's the same countries every month and for the other commodity."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"activity": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
"
| Period | Partner | Trade Flow | Milk and cream | Trade Value (US$) |
---|
268 | 201501 | Belgium | Exports | processed | 142610 |
---|
271 | 201501 | China | Exports | processed | 1013141 |
---|
275 | 201501 | Cyprus | Exports | processed | 6625 |
---|
280 | 201501 | Denmark | Exports | processed | 107883 |
---|
284 | 201501 | France | Exports | processed | 178262 |
---|
287 | 201501 | Germany | Exports | processed | 2588380 |
---|
292 | 201501 | China, Hong Kong SAR | Exports | processed | 1110086 |
---|
294 | 201501 | Hungary | Exports | processed | 2119 |
---|
298 | 201501 | Ireland | Exports | processed | 4020981 |
---|
300 | 201501 | Italy | Exports | processed | 23267 |
---|
311 | 201501 | Malta | Exports | processed | 1403 |
---|
314 | 201501 | Netherlands | Exports | processed | 3788929 |
---|
317 | 201501 | Poland | Exports | processed | 10145 |
---|
319 | 201501 | Portugal | Exports | processed | 3165 |
---|
327 | 201501 | Spain | Exports | processed | 10107 |
---|
329 | 201501 | Sweden | Exports | processed | 1739 |
---|
332 | 201501 | United Arab Emirates | Exports | processed | 417480 |
---|
\n",
"
"
],
"text/plain": [
" Period Partner Trade Flow Milk and cream Trade Value (US$)\n",
"268 201501 Belgium Exports processed 142610\n",
"271 201501 China Exports processed 1013141\n",
"275 201501 Cyprus Exports processed 6625\n",
"280 201501 Denmark Exports processed 107883\n",
"284 201501 France Exports processed 178262\n",
"287 201501 Germany Exports processed 2588380\n",
"292 201501 China, Hong Kong SAR Exports processed 1110086\n",
"294 201501 Hungary Exports processed 2119\n",
"298 201501 Ireland Exports processed 4020981\n",
"300 201501 Italy Exports processed 23267\n",
"311 201501 Malta Exports processed 1403\n",
"314 201501 Netherlands Exports processed 3788929\n",
"317 201501 Poland Exports processed 10145\n",
"319 201501 Portugal Exports processed 3165\n",
"327 201501 Spain Exports processed 10107\n",
"329 201501 Sweden Exports processed 1739\n",
"332 201501 United Arab Emirates Exports processed 417480"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def buysEveryMonth(group):\n",
" return len(group) == 10\n",
"\n",
"grouped = exports.groupby([PARTNER])\n",
"regular = grouped.filter(buysEveryMonth)\n",
"regular[(regular[MONTH] == 201501) & (regular[COMMODITY] == 'processed')]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Just over 75% of the total UK exports are due to these regular customers."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"activity": false
},
"outputs": [
{
"data": {
"text/plain": [
"0.7583526396315317"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"regular[VALUE].sum() / exports[VALUE].sum()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Bi-directional trade\n",
"\n",
"To address the fourth question, \n",
"'Which countries does the UK both import from and export to?', a pivot table is used to list the total export and import value for each country. "
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"activity": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
"
Trade Flow | Exports | Imports |
---|
Partner | | |
---|
Algeria | 8087885.0 | NaN |
---|
Angola | 2416129.0 | NaN |
---|
Antigua and Barbuda | 22218.0 | NaN |
---|
Areas, nes | 51205.0 | NaN |
---|
Australia | 81644.0 | NaN |
---|
\n",
"
"
],
"text/plain": [
"Trade Flow Exports Imports\n",
"Partner \n",
"Algeria 8087885.0 NaN\n",
"Angola 2416129.0 NaN\n",
"Antigua and Barbuda 22218.0 NaN\n",
"Areas, nes 51205.0 NaN\n",
"Australia 81644.0 NaN"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"countries = pivot_table(milk, index=[PARTNER], columns=[FLOW], \n",
" values=VALUE, aggfunc=sum)\n",
"countries.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Removing the rows with a missing value will result in only those countries with bi-directional trade flow with the UK."
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"activity": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
"
Trade Flow | Exports | Imports |
---|
Partner | | |
---|
Austria | 56279.0 | 780.0 |
---|
Belgium | 7209121.0 | 14325697.0 |
---|
Czech Rep. | 2590.0 | 486889.0 |
---|
Denmark | 335068.0 | 13681759.0 |
---|
France | 9381762.0 | 28314091.0 |
---|
Germany | 10828464.0 | 21899123.0 |
---|
Hungary | 71378.0 | 4762.0 |
---|
Ireland | 128155891.0 | 46263897.0 |
---|
Italy | 173689.0 | 321635.0 |
---|
Latvia | 567.0 | 870.0 |
---|
Lithuania | 1172.0 | 318407.0 |
---|
Netherlands | 18018603.0 | 17658912.0 |
---|
Poland | 106659.0 | 4933917.0 |
---|
Portugal | 25855.0 | 308654.0 |
---|
Romania | 36.0 | 975996.0 |
---|
Slovakia | 65.0 | 39990.0 |
---|
Spain | 1229172.0 | 4910615.0 |
---|
Sweden | 34972.0 | 1962413.0 |
---|
United Arab Emirates | 1590593.0 | 27225.0 |
---|
United States of America | 548910.0 | 46044.0 |
---|
\n",
"
"
],
"text/plain": [
"Trade Flow Exports Imports\n",
"Partner \n",
"Austria 56279.0 780.0\n",
"Belgium 7209121.0 14325697.0\n",
"Czech Rep. 2590.0 486889.0\n",
"Denmark 335068.0 13681759.0\n",
"France 9381762.0 28314091.0\n",
"Germany 10828464.0 21899123.0\n",
"Hungary 71378.0 4762.0\n",
"Ireland 128155891.0 46263897.0\n",
"Italy 173689.0 321635.0\n",
"Latvia 567.0 870.0\n",
"Lithuania 1172.0 318407.0\n",
"Netherlands 18018603.0 17658912.0\n",
"Poland 106659.0 4933917.0\n",
"Portugal 25855.0 308654.0\n",
"Romania 36.0 975996.0\n",
"Slovakia 65.0 39990.0\n",
"Spain 1229172.0 4910615.0\n",
"Sweden 34972.0 1962413.0\n",
"United Arab Emirates 1590593.0 27225.0\n",
"United States of America 548910.0 46044.0"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"countries.dropna()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Conclusions\n",
"\n",
"The milk and cream trade of the UK from January to May 2015 was analysed in terms of which countries the UK mostly depends on for income (exports) and goods (imports). Over the period, the UK had a trade surplus of over 100 million US dollars.\n",
"\n",
"Ireland is the main partner, but it imported from the UK almost the triple in value than it exported to the UK. \n",
"\n",
"The UK exported to over 100 countries during the period, but only imported from 21 countries, the main ones (top five by trade value) being geographically close. China and Hong Kong are the main importers that are not also main exporters. \n",
"\n",
"The UK is heavily dependent on its regular customers, the 16 countries that buy all types of milk and cream every month. They contribute three quarters of the total export value.\n",
"\n",
"The UK has bi-directional trade (i.e. both exports and imports) with 20 countries, although for some the trade value (in US dollars) is suspiciously low, which raises questions about the data's accuracy."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}