{ "cells": [ { "cell_type": "markdown", "id": "444a77e7-8a6f-44c1-bdac-b7f1e0b052e8", "metadata": { "tags": [] }, "source": [ "# Exploring MRIOs with Pymrio" ] }, { "cell_type": "markdown", "id": "c9b420ca", "metadata": { "lines_to_next_cell": 2 }, "source": [ "The first step when working with a new MRIO data set is to familiarize yourself with the data.\n", "This notebook shows how to use the `pymrio` package to explore the data.\n", "We use the test data set that is included in the `pymrio` package.\n", "This is a completely artificial, very small MRIO.\n", "It is not meant to be realistic, but it is useful for developing, testing and learning." ] }, { "cell_type": "markdown", "id": "1f9dcc7c", "metadata": {}, "source": [ "First we import the required packages:" ] }, { "cell_type": "code", "execution_count": 1, "id": "7a8d7b7a-1d21-4cea-b7bf-578ac1b40679", "metadata": { "tags": [] }, "outputs": [], "source": [ "import pymrio" ] }, { "cell_type": "markdown", "id": "b9eb1d0e", "metadata": {}, "source": [ "We can now load the test data set with the `load_test` function. We can call\n", "the MRIO whatever we want, here we use mrio." ] }, { "cell_type": "code", "execution_count": 2, "id": "5ac4addd-0a85-4b49-8f95-48bc25a24366", "metadata": {}, "outputs": [], "source": [ "mrio = pymrio.load_test()" ] }, { "cell_type": "markdown", "id": "15c7a08a", "metadata": {}, "source": [ "We can get some first information about the MRIO by printing it." ] }, { "cell_type": "code", "execution_count": 3, "id": "f7b1fe2a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "IO System with parameters: Z, Y, unit, population, meta, factor_inputs, emissions\n" ] } ], "source": [ "print(mrio)" ] }, { "cell_type": "markdown", "id": "86c1ad8d", "metadata": {}, "source": [ "This tells us what the MRIO data we just loaded contains.\n", "We find a Z and Y matrix, some unit information and two satellite accounts, factor_inputs and emissions." ] }, { "cell_type": "markdown", "id": "af4d7568", "metadata": {}, "source": [ "To get more specific data we can ask pymrio for regions, sectors, products, etc." ] }, { "cell_type": "code", "execution_count": 4, "id": "a6f3769d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'testmrio'" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mrio.name" ] }, { "cell_type": "code", "execution_count": 5, "id": "e3a373a2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['reg1', 'reg2', 'reg3', 'reg4', 'reg5', 'reg6'], dtype='object', name='region')" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mrio.get_regions()" ] }, { "cell_type": "code", "execution_count": 6, "id": "def4d60f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['food', 'mining', 'manufactoring', 'electricity', 'construction',\n", " 'trade', 'transport', 'other'],\n", " dtype='object', name='sector')" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mrio.get_sectors()" ] }, { "cell_type": "code", "execution_count": 7, "id": "a228d193", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['Final consumption expenditure by households',\n", " 'Final consumption expenditure by non-profit organisations serving households (NPISH)',\n", " 'Final consumption expenditure by government',\n", " 'Gross fixed capital formation', 'Changes in inventories',\n", " 'Changes in valuables', 'Export'],\n", " dtype='object', name='category')" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mrio.get_Y_categories()" ] }, { "cell_type": "markdown", "id": "3f431792", "metadata": {}, "source": [ "The same methods can be used to explore one of the satellite accounts." ] }, { "cell_type": "code", "execution_count": 8, "id": "563d4c0d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Extension Emissions with parameters: name, F, F_Y, unit\n" ] } ], "source": [ "print(mrio.emissions)" ] }, { "cell_type": "code", "execution_count": 9, "id": "f7d086a5", "metadata": { "lines_to_next_cell": 0 }, "outputs": [ { "data": { "text/plain": [ "'Emissions'" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mrio.emissions.name" ] }, { "cell_type": "code", "execution_count": 10, "id": "fee8e893", "metadata": { "lines_to_next_cell": 2 }, "outputs": [ { "data": { "text/plain": [ "Index(['reg1', 'reg2', 'reg3', 'reg4', 'reg5', 'reg6'], dtype='object', name='region')" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mrio.emissions.get_regions()" ] }, { "cell_type": "markdown", "id": "f800f93f", "metadata": {}, "source": [ "The satellite accounts also have a special method to get index (rows) of the acccounts." ] }, { "cell_type": "code", "execution_count": 11, "id": "4cc4bb69", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "MultiIndex([('emission_type1', 'air'),\n", " ('emission_type2', 'water')],\n", " names=['stressor', 'compartment'])" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mrio.emissions.get_rows()" ] }, { "cell_type": "markdown", "id": "fef71c10", "metadata": {}, "source": [ "# Searching through the MRIO" ] }, { "cell_type": "markdown", "id": "b0df07b4", "metadata": {}, "source": [ "Several methods are available to search through the whole MRIO.\n", "These generally accept [regular expressions](https://docs.python.org/3/howto/regex.html) as search terms." ] }, { "cell_type": "markdown", "id": "02772cf2", "metadata": { "lines_to_next_cell": 2 }, "source": [ "The most general method is 'find'. This can be used for a quick overview where a specific term appears in the MRIO." ] }, { "cell_type": "code", "execution_count": 12, "id": "dfc77ea0", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'emissions_index': MultiIndex([('emission_type1', 'air')],\n", " names=['stressor', 'compartment'])}" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mrio.find(\"air\")" ] }, { "cell_type": "code", "execution_count": 13, "id": "995844ae", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'index': MultiIndex([('reg1', 'trade'),\n", " ('reg2', 'trade'),\n", " ('reg3', 'trade'),\n", " ('reg4', 'trade'),\n", " ('reg5', 'trade'),\n", " ('reg6', 'trade')],\n", " names=['region', 'sector']),\n", " 'sectors': Index(['trade'], dtype='object', name='sector')}" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mrio.find(\"trade\")" ] }, { "cell_type": "markdown", "id": "c8479a2e", "metadata": {}, "source": [ "Not that 'find' (and all other search methods) a case sensitive.\n", "Do make a case insensitive search, add the regular expression flag `(?i)` to the search term." ] }, { "cell_type": "code", "execution_count": 14, "id": "3b8dbbbf", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{}" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mrio.find(\"value\")" ] }, { "cell_type": "code", "execution_count": 15, "id": "aef01ede", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'factor_inputs_index': Index(['Value Added'], dtype='object', name='inputtype')}" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mrio.find(\"(?i)value\")" ] }, { "cell_type": "markdown", "id": "03a5588b", "metadata": {}, "source": [ "## Specific search methods: contains, match, fullmatch," ] }, { "cell_type": "markdown", "id": "46181b25", "metadata": {}, "source": [ "The MRIO class also contains a set of specific regular expresion search methods, mirroring the 'contains', 'match' and 'fullmatch'\n", "methods of the pandas DataFrame str column type. See the pandas documentation for details, in short:\n", "\n", " - 'contains' looks for a match anywhere in the string\n", " - 'match' looks for a match at the beginning of the string\n", " - 'fullmatch' looks for a match of the whole string\n", "\n", "These methods are available for all index columns of the MRIO and have a similar signature:\n", "\n", " 1. As for 'find_all', the search term is case sensitive. To make it case insensitive, add the regular expression flag `(?i)` to the search term.\n", " 2. The search term can be passed to the keyword argument 'find_all' or as the first positional argument to search in all index levels.\n", " 3. Alternativels, the search term can be passed to the keyword argument with the level name to search only in that index level.\n", "\n", "The following examples show how to use these methods." ] }, { "cell_type": "code", "execution_count": 16, "id": "cbe771bd", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "MultiIndex([('reg1', 'trade'),\n", " ('reg2', 'trade'),\n", " ('reg3', 'trade'),\n", " ('reg4', 'trade'),\n", " ('reg5', 'trade'),\n", " ('reg6', 'trade')],\n", " names=['region', 'sector'])" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mrio.contains(find_all=\"ad\")\n", "mrio.contains(\"ad\") # find_all is the default argument" ] }, { "cell_type": "code", "execution_count": 17, "id": "2318254c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "MultiIndex([], names=['region', 'sector'])" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mrio.match(\"ad\")" ] }, { "cell_type": "code", "execution_count": 18, "id": "69e19357", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "MultiIndex([('reg1', 'trade'),\n", " ('reg2', 'trade'),\n", " ('reg3', 'trade'),\n", " ('reg4', 'trade'),\n", " ('reg5', 'trade'),\n", " ('reg6', 'trade')],\n", " names=['region', 'sector'])" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mrio.match(\"trad\")" ] }, { "cell_type": "code", "execution_count": 19, "id": "0b086ec6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "MultiIndex([], names=['region', 'sector'])" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mrio.fullmatch(\"trad\")" ] }, { "cell_type": "code", "execution_count": 20, "id": "b2c2a5ab", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "MultiIndex([('reg1', 'trade'),\n", " ('reg2', 'trade'),\n", " ('reg3', 'trade'),\n", " ('reg4', 'trade'),\n", " ('reg5', 'trade'),\n", " ('reg6', 'trade')],\n", " names=['region', 'sector'])" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mrio.fullmatch(\"trade\")" ] }, { "cell_type": "code", "execution_count": 21, "id": "c3ed13df", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "MultiIndex([('reg1', 'trade'),\n", " ('reg2', 'trade'),\n", " ('reg3', 'trade'),\n", " ('reg4', 'trade'),\n", " ('reg5', 'trade'),\n", " ('reg6', 'trade')],\n", " names=['region', 'sector'])" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mrio.fullmatch(\"(?i).*AD.*\")" ] }, { "cell_type": "markdown", "id": "f1b5f192", "metadata": {}, "source": [ "For the rest of the notebook, we will do the examples with the 'contains' method, but the same applies to the other methods." ] }, { "cell_type": "markdown", "id": "b639d0c6", "metadata": {}, "source": [ "To search only at one specific level, pass the search term to the keyword argument with the level name." ] }, { "cell_type": "code", "execution_count": 22, "id": "3c0c5b08", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "MultiIndex([], names=['region', 'sector'])" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mrio.contains(region=\"trade\")" ] }, { "cell_type": "code", "execution_count": 23, "id": "dd87e126", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "MultiIndex([('reg1', 'trade'),\n", " ('reg2', 'trade'),\n", " ('reg3', 'trade'),\n", " ('reg4', 'trade'),\n", " ('reg5', 'trade'),\n", " ('reg6', 'trade')],\n", " names=['region', 'sector'])" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mrio.contains(sector=\"trade\")" ] }, { "cell_type": "markdown", "id": "1fc31c91", "metadata": {}, "source": [ "And of course, the method are also available for the satellite accounts." ] }, { "cell_type": "code", "execution_count": 24, "id": "6da917bd", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "MultiIndex([('emission_type1', 'air')],\n", " names=['stressor', 'compartment'])" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mrio.emissions.contains(compartment=\"air\")" ] }, { "cell_type": "markdown", "id": "8085b788", "metadata": {}, "source": [ "Passing a non-existing level to the keyword argument is silently ignored." ] }, { "cell_type": "code", "execution_count": 25, "id": "813a6696", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index([], dtype='object')" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mrio.factor_inputs.contains(compartment=\"trade\")" ] }, { "cell_type": "markdown", "id": "3fbeecbc", "metadata": { "lines_to_next_cell": 0 }, "source": [ "This allows to search for terms that are only in some index levels.\n", "Logically, this is an 'or' search." ] }, { "cell_type": "code", "execution_count": 26, "id": "deaafbf6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['Value Added'], dtype='object', name='inputtype')" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mrio.factor_inputs.contains(compartment=\"air\", inputtype=\"Value\")" ] }, { "cell_type": "markdown", "id": "000501bc", "metadata": {}, "source": [ "But note, that if both levels exist, both must match (so it becomes a logical 'and')." ] }, { "cell_type": "code", "execution_count": 27, "id": "5cd44a79", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "MultiIndex([('emission_type1', 'air')],\n", " names=['stressor', 'compartment'])" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mrio.emissions.contains(stressor=\"emission\", compartment=\"air\")" ] }, { "cell_type": "markdown", "id": "089dd4ec", "metadata": {}, "source": [ "## Search through all extensions" ] }, { "cell_type": "markdown", "id": "4a8d87de", "metadata": {}, "source": [ "All three search methods are also available to loop through all extensions of the MRIO." ] }, { "cell_type": "code", "execution_count": 28, "id": "fd65dd57", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'Factor Inputs': Index([], dtype='object'),\n", " 'Emissions': MultiIndex([('emission_type1', 'air')],\n", " names=['stressor', 'compartment'])}" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mrio.extension_contains(stressor=\"emission\", compartment=\"air\")" ] }, { "cell_type": "markdown", "id": "ef43cd67", "metadata": {}, "source": [ "If only a subset of extensions should be searched, pass the extension names to the keyword argument 'extensions'." ] }, { "cell_type": "markdown", "id": "325f650b", "metadata": {}, "source": [ "## Generic search method for any dataframe index" ] }, { "cell_type": "markdown", "id": "4428a3fe", "metadata": {}, "source": [ "Internally, the class methods 'contains', 'match' and 'fullmatch' all the\n", "'index_contains', 'index_match' and 'index_fullmatch' methods of ioutil module.\n", "This function can be used to search through index of any pandas DataFrame." ] }, { "cell_type": "code", "execution_count": 29, "id": "0f293761", "metadata": {}, "outputs": [], "source": [ "df = mrio.Y" ] }, { "cell_type": "markdown", "id": "2ea109cf", "metadata": {}, "source": [ "Depending if a dataframe or an index is passed, the return is either the dataframe or the index." ] }, { "cell_type": "code", "execution_count": 30, "id": "013d7754", "metadata": {}, "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", " \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", "
regionreg1reg2...reg5reg6
categoryFinal consumption expenditure by householdsFinal consumption expenditure by non-profit organisations serving households (NPISH)Final consumption expenditure by governmentGross fixed capital formationChanges in inventoriesChanges in valuablesExportFinal consumption expenditure by householdsFinal consumption expenditure by non-profit organisations serving households (NPISH)Final consumption expenditure by government...Changes in inventoriesChanges in valuablesExportFinal consumption expenditure by householdsFinal consumption expenditure by non-profit organisations serving households (NPISH)Final consumption expenditure by governmentGross fixed capital formationChanges in inventoriesChanges in valuablesExport
regionsector
reg1trade769535.9300016.6389202.408807e+076.727345e+071230.218200216.21108008063.5238012.738233163.205380...204.3831701.684295e+00049782414.000.22493314.44566016739029.0012.1454650.0138880
reg2trade5678.267400.0754242.312962e+026.339521e+0235.6071573.1926940385664.01000178.5011408160.881200...358.2493202.271962e+01026592464.000.13974510.62396211775351.0020.5725340.0054330
reg3trade2753.860800.1115401.956911e+003.598675e+0223.3911200.00045502072.248900.0448111.242613...309.9842706.283278e+000114505.890.63009837.09554931317361.00212.7075100.0149290
reg4trade373.283930.0093823.585011e-012.514957e-020.0020160.0001440192.215390.0196660.537107...73.8597067.199126e-02040152651.000.25552317.25363414011134.004.0524440.0019350
reg5trade4287.406700.0389417.014679e+001.955479e+026.6756560.52401503633.687502.53631250.624916...9177.0818001.330591e+06060992225.000.82382334.20802627870911.0085.1915110.0089290
reg6trade4772.757500.1131122.321101e+012.417571e+0216.2670491.48881802031.496401.86449218.787893...91.0403192.122217e+000851864.0423.3713061966.030900131182.131549.4104000.2660330
\n", "

6 rows × 42 columns

\n", "
" ], "text/plain": [ "region reg1 \\\n", "category Final consumption expenditure by households \n", "region sector \n", "reg1 trade 769535.93000 \n", "reg2 trade 5678.26740 \n", "reg3 trade 2753.86080 \n", "reg4 trade 373.28393 \n", "reg5 trade 4287.40670 \n", "reg6 trade 4772.75750 \n", "\n", "region \\\n", "category Final consumption expenditure by non-profit organisations serving households (NPISH) \n", "region sector \n", "reg1 trade 16.638920 \n", "reg2 trade 0.075424 \n", "reg3 trade 0.111540 \n", "reg4 trade 0.009382 \n", "reg5 trade 0.038941 \n", "reg6 trade 0.113112 \n", "\n", "region \\\n", "category Final consumption expenditure by government \n", "region sector \n", "reg1 trade 2.408807e+07 \n", "reg2 trade 2.312962e+02 \n", "reg3 trade 1.956911e+00 \n", "reg4 trade 3.585011e-01 \n", "reg5 trade 7.014679e+00 \n", "reg6 trade 2.321101e+01 \n", "\n", "region \\\n", "category Gross fixed capital formation Changes in inventories \n", "region sector \n", "reg1 trade 6.727345e+07 1230.218200 \n", "reg2 trade 6.339521e+02 35.607157 \n", "reg3 trade 3.598675e+02 23.391120 \n", "reg4 trade 2.514957e-02 0.002016 \n", "reg5 trade 1.955479e+02 6.675656 \n", "reg6 trade 2.417571e+02 16.267049 \n", "\n", "region \\\n", "category Changes in valuables Export \n", "region sector \n", "reg1 trade 216.211080 0 \n", "reg2 trade 3.192694 0 \n", "reg3 trade 0.000455 0 \n", "reg4 trade 0.000144 0 \n", "reg5 trade 0.524015 0 \n", "reg6 trade 1.488818 0 \n", "\n", "region reg2 \\\n", "category Final consumption expenditure by households \n", "region sector \n", "reg1 trade 8063.52380 \n", "reg2 trade 385664.01000 \n", "reg3 trade 2072.24890 \n", "reg4 trade 192.21539 \n", "reg5 trade 3633.68750 \n", "reg6 trade 2031.49640 \n", "\n", "region \\\n", "category Final consumption expenditure by non-profit organisations serving households (NPISH) \n", "region sector \n", "reg1 trade 12.738233 \n", "reg2 trade 178.501140 \n", "reg3 trade 0.044811 \n", "reg4 trade 0.019666 \n", "reg5 trade 2.536312 \n", "reg6 trade 1.864492 \n", "\n", "region ... \\\n", "category Final consumption expenditure by government ... \n", "region sector ... \n", "reg1 trade 163.205380 ... \n", "reg2 trade 8160.881200 ... \n", "reg3 trade 1.242613 ... \n", "reg4 trade 0.537107 ... \n", "reg5 trade 50.624916 ... \n", "reg6 trade 18.787893 ... \n", "\n", "region reg5 \\\n", "category Changes in inventories Changes in valuables Export \n", "region sector \n", "reg1 trade 204.383170 1.684295e+00 0 \n", "reg2 trade 358.249320 2.271962e+01 0 \n", "reg3 trade 309.984270 6.283278e+00 0 \n", "reg4 trade 73.859706 7.199126e-02 0 \n", "reg5 trade 9177.081800 1.330591e+06 0 \n", "reg6 trade 91.040319 2.122217e+00 0 \n", "\n", "region reg6 \\\n", "category Final consumption expenditure by households \n", "region sector \n", "reg1 trade 49782414.00 \n", "reg2 trade 26592464.00 \n", "reg3 trade 114505.89 \n", "reg4 trade 40152651.00 \n", "reg5 trade 60992225.00 \n", "reg6 trade 851864.04 \n", "\n", "region \\\n", "category Final consumption expenditure by non-profit organisations serving households (NPISH) \n", "region sector \n", "reg1 trade 0.224933 \n", "reg2 trade 0.139745 \n", "reg3 trade 0.630098 \n", "reg4 trade 0.255523 \n", "reg5 trade 0.823823 \n", "reg6 trade 23.371306 \n", "\n", "region \\\n", "category Final consumption expenditure by government \n", "region sector \n", "reg1 trade 14.445660 \n", "reg2 trade 10.623962 \n", "reg3 trade 37.095549 \n", "reg4 trade 17.253634 \n", "reg5 trade 34.208026 \n", "reg6 trade 1966.030900 \n", "\n", "region \\\n", "category Gross fixed capital formation Changes in inventories \n", "region sector \n", "reg1 trade 16739029.00 12.145465 \n", "reg2 trade 11775351.00 20.572534 \n", "reg3 trade 31317361.00 212.707510 \n", "reg4 trade 14011134.00 4.052444 \n", "reg5 trade 27870911.00 85.191511 \n", "reg6 trade 131182.13 1549.410400 \n", "\n", "region \n", "category Changes in valuables Export \n", "region sector \n", "reg1 trade 0.013888 0 \n", "reg2 trade 0.005433 0 \n", "reg3 trade 0.014929 0 \n", "reg4 trade 0.001935 0 \n", "reg5 trade 0.008929 0 \n", "reg6 trade 0.266033 0 \n", "\n", "[6 rows x 42 columns]" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pymrio.index_contains(df, \"trade\")" ] }, { "cell_type": "code", "execution_count": 31, "id": "4e11c573", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "MultiIndex([('reg1', 'trade'),\n", " ('reg2', 'trade'),\n", " ('reg3', 'trade'),\n", " ('reg4', 'trade'),\n", " ('reg5', 'trade'),\n", " ('reg6', 'trade')],\n", " names=['region', 'sector'])" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pymrio.index_contains(df.index, \"trade\")" ] }, { "cell_type": "code", "execution_count": 32, "id": "c67973ed", "metadata": { "tags": [] }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
regionreg1reg2...reg5reg6
categoryFinal consumption expenditure by householdsFinal consumption expenditure by non-profit organisations serving households (NPISH)Final consumption expenditure by governmentGross fixed capital formationChanges in inventoriesChanges in valuablesExportFinal consumption expenditure by householdsFinal consumption expenditure by non-profit organisations serving households (NPISH)Final consumption expenditure by government...Changes in inventoriesChanges in valuablesExportFinal consumption expenditure by householdsFinal consumption expenditure by non-profit organisations serving households (NPISH)Final consumption expenditure by governmentGross fixed capital formationChanges in inventoriesChanges in valuablesExport
regionsector
reg2mining1.653997e+021.817989e-050.3348243.283238e+012.910648e+013.970468e-0501.091126e+032.7513121.544777e+01...0.0402170.00042006.127299e-010.0082120.0130611.167170e+01166.5395800.0000020
manufactoring9.928459e+074.187143e+001373.3702004.237878e+074.415752e+031.637658e+0203.210316e+05125.7291101.603833e+07...951.80921021.64128001.074192e+0762.8324886363.1928001.170497e+071060.3215000.1459030
reg4mining1.072728e+029.421644e-090.2098511.055704e+002.697312e+013.112643e-0902.940734e+020.0000011.061796e-01...45.3884570.00001507.705800e+040.3483672.3268589.917552e-0268.2668150.0007890
manufactoring4.086352e+071.170611e+00377.3228103.032655e+072.263532e+064.696135e+0101.510445e+077.5984401.285316e+02...1004.0742001.47620002.190604e+0794.2829106712.9728003.167496e+07825.2569400.0365100
\n", "

4 rows × 42 columns

\n", "
" ], "text/plain": [ "region reg1 \\\n", "category Final consumption expenditure by households \n", "region sector \n", "reg2 mining 1.653997e+02 \n", " manufactoring 9.928459e+07 \n", "reg4 mining 1.072728e+02 \n", " manufactoring 4.086352e+07 \n", "\n", "region \\\n", "category Final consumption expenditure by non-profit organisations serving households (NPISH) \n", "region sector \n", "reg2 mining 1.817989e-05 \n", " manufactoring 4.187143e+00 \n", "reg4 mining 9.421644e-09 \n", " manufactoring 1.170611e+00 \n", "\n", "region \\\n", "category Final consumption expenditure by government \n", "region sector \n", "reg2 mining 0.334824 \n", " manufactoring 1373.370200 \n", "reg4 mining 0.209851 \n", " manufactoring 377.322810 \n", "\n", "region \\\n", "category Gross fixed capital formation Changes in inventories \n", "region sector \n", "reg2 mining 3.283238e+01 2.910648e+01 \n", " manufactoring 4.237878e+07 4.415752e+03 \n", "reg4 mining 1.055704e+00 2.697312e+01 \n", " manufactoring 3.032655e+07 2.263532e+06 \n", "\n", "region \\\n", "category Changes in valuables Export \n", "region sector \n", "reg2 mining 3.970468e-05 0 \n", " manufactoring 1.637658e+02 0 \n", "reg4 mining 3.112643e-09 0 \n", " manufactoring 4.696135e+01 0 \n", "\n", "region reg2 \\\n", "category Final consumption expenditure by households \n", "region sector \n", "reg2 mining 1.091126e+03 \n", " manufactoring 3.210316e+05 \n", "reg4 mining 2.940734e+02 \n", " manufactoring 1.510445e+07 \n", "\n", "region \\\n", "category Final consumption expenditure by non-profit organisations serving households (NPISH) \n", "region sector \n", "reg2 mining 2.751312 \n", " manufactoring 125.729110 \n", "reg4 mining 0.000001 \n", " manufactoring 7.598440 \n", "\n", "region ... \\\n", "category Final consumption expenditure by government ... \n", "region sector ... \n", "reg2 mining 1.544777e+01 ... \n", " manufactoring 1.603833e+07 ... \n", "reg4 mining 1.061796e-01 ... \n", " manufactoring 1.285316e+02 ... \n", "\n", "region reg5 \\\n", "category Changes in inventories Changes in valuables Export \n", "region sector \n", "reg2 mining 0.040217 0.000420 0 \n", " manufactoring 951.809210 21.641280 0 \n", "reg4 mining 45.388457 0.000015 0 \n", " manufactoring 1004.074200 1.476200 0 \n", "\n", "region reg6 \\\n", "category Final consumption expenditure by households \n", "region sector \n", "reg2 mining 6.127299e-01 \n", " manufactoring 1.074192e+07 \n", "reg4 mining 7.705800e+04 \n", " manufactoring 2.190604e+07 \n", "\n", "region \\\n", "category Final consumption expenditure by non-profit organisations serving households (NPISH) \n", "region sector \n", "reg2 mining 0.008212 \n", " manufactoring 62.832488 \n", "reg4 mining 0.348367 \n", " manufactoring 94.282910 \n", "\n", "region \\\n", "category Final consumption expenditure by government \n", "region sector \n", "reg2 mining 0.013061 \n", " manufactoring 6363.192800 \n", "reg4 mining 2.326858 \n", " manufactoring 6712.972800 \n", "\n", "region \\\n", "category Gross fixed capital formation Changes in inventories \n", "region sector \n", "reg2 mining 1.167170e+01 166.539580 \n", " manufactoring 1.170497e+07 1060.321500 \n", "reg4 mining 9.917552e-02 68.266815 \n", " manufactoring 3.167496e+07 825.256940 \n", "\n", "region \n", "category Changes in valuables Export \n", "region sector \n", "reg2 mining 0.000002 0 \n", " manufactoring 0.145903 0 \n", "reg4 mining 0.000789 0 \n", " manufactoring 0.036510 0 \n", "\n", "[4 rows x 42 columns]" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pymrio.index_fullmatch(df, region=\"reg[2,4]\", sector=\"m.*\")" ] }, { "cell_type": "markdown", "id": "565292ba", "metadata": {}, "source": [ "All search methods can easily be combined with the extract methods to extract the data that was found.\n", "For more information on this, see the [extract_data](./extract_data.ipynb) notebook." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.20" } }, "nbformat": 4, "nbformat_minor": 5 }