<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="VerticalStudentView" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@vertical+block@09412f6ef7c542128988d465ad3e5b67" data-request-token="b6d7c8ae881c11efa860837f534d2eba" data-graded="False" data-has-score="False">
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@b45089d845a74ccd82fb4991a2f09331">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@b45089d845a74ccd82fb4991a2f09331" data-request-token="b6d7c8ae881c11efa860837f534d2eba" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<p style="text-align: left;">This tutorial explores further concepts in Numpy such as categorical data, advanced indexing and dealing with Not-a-Number (NaN) data.</p>
<p style="text-align: left;">Follow the instructions below to download the tutorial and open it in the Sandbox.</p>
<section id="Download-the-tutorial-notebook" style="box-sizing: border-box; color: #000000;">
<h2 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 24px; color: #336699; text-align: left;">Download the tutorial notebook</h2>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px; text-align: left;"><a class="reference external" href="/assets/courseware/v1/38aca23d0de6ee7f7c20240e93e6bf4b/asset-v1:digitalearthafrica+DEA101+2021+type@asset+block/04_download-cleaning_data.ipynb" style="box-sizing: border-box; color: #3091d1; text-decoration-line: none; cursor: pointer; outline: 0px;" target="[object Object]">Download the Python basics 4 tutorial notebook</a></p>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px; text-align: left;">To view this notebook on the Sandbox, you will need to first download it to your computer, then upload it to the Sandbox. Ensure you have followed the set-up prerequisities listed in <a href="/courses/course-v1:digitalearthafrica+DEA101+2021/jump_to_id/9c210d02e6fe484a8ce67c67a1e9c2fa" target="[object Object]">Python basics 1: Jupyter, </a>and then follow these instructions:</p>
<ol class="arabic simple" style="box-sizing: border-box; margin-top: 0px; margin-bottom: 24px; padding-left: 0px; list-style-position: initial; list-style-image: initial; line-height: 24px; text-align: left;">
<li style="text-align: left; box-sizing: border-box; list-style: decimal; margin-left: 24px;">
<p style="text-align: left; box-sizing: border-box; line-height: 24px; margin: 0px; font-size: 16px;">Download the notebook by clicking the link above.</p>
</li>
<li style="text-align: left; box-sizing: border-box; list-style: decimal; margin-left: 24px;">
<p style="text-align: left; box-sizing: border-box; line-height: 24px; margin: 0px; font-size: 16px;">On the Sandbox, open the <strong style="box-sizing: border-box;">Training</strong> folder.</p>
</li>
<li style="text-align: left; box-sizing: border-box; list-style: decimal; margin-left: 24px;">
<p style="text-align: left; box-sizing: border-box; line-height: 24px; margin: 0px; font-size: 16px;">Click the <strong style="box-sizing: border-box;">Upload Files</strong> button as shown below.</p>
</li>
</ol>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px; text-align: left;"><img alt="Upload button." class="no-scaled-link" src="https://learn.digitalearthafrica.org/asset-v1:digitalearthafrica+DEA101+2021+type@asset+block@05_solution_uploadbutton.png" style="box-sizing: border-box; border: 0px; vertical-align: middle; width: 400px;" /></p>
<ol class="arabic simple" start="4" style="box-sizing: border-box; margin-top: 0px; margin-bottom: 24px; padding-left: 0px; list-style-position: initial; list-style-image: initial; line-height: 24px; text-align: left;">
<li style="text-align: left; box-sizing: border-box; list-style: decimal; margin-left: 24px;">
<p style="text-align: left; box-sizing: border-box; line-height: 24px; margin: 0px; font-size: 16px;">Select the downloaded notebook using the file browser. Click <strong style="box-sizing: border-box;">OK</strong>.</p>
</li>
<li style="text-align: left; box-sizing: border-box; list-style: decimal; margin-left: 24px;">
<p style="text-align: left; box-sizing: border-box; line-height: 24px; margin: 0px; font-size: 16px;">The solution notebook will appear in the <strong style="box-sizing: border-box;">Training</strong> folder. Double-click to open it.</p>
</li>
</ol>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px; text-align: left;">You can now use the tutorial notebook as an interactive version of this webpage.</p>
<div class="admonition note" style="box-sizing: border-box; -webkit-font-smoothing: antialiased; padding: 12px; line-height: 24px; margin-bottom: 24px; background: #e7f2fa;">
<p class="admonition-title" style="box-sizing: border-box; line-height: 1; margin: -12px -12px 12px; font-size: inherit; font-family: inherit; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: bold; font-stretch: normal; text-rendering: auto; -webkit-font-smoothing: antialiased; color: #ffffff; background: #6ab0de; padding: 6px 12px; text-align: left;">Note</p>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px; font-size: 16px; text-align: left;">The tutorial notebook should look like the text and code below. However, the tutorial notebook outputs are blank (i.e. no results showing after code cells). Follow the instructions in the notebook to run the cells in the tutorial notebook. Refer to this page to check your outputs look similar.</p>
</div>
</section>
</div>
</div>
</div>
<script type="text/javascript">
(function (require) {
require(['/static/js/dateutil_factory.be68acdff619.js?raw'], function () {
require(['js/dateutil_factory'], function (DateUtilFactory) {
DateUtilFactory.transform('.localized-datetime');
});
});
}).call(this, require || RequireJS.require);
</script>
<script>
function emit_event(message) {
parent.postMessage(message, '*');
}
</script>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="VerticalStudentView" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@vertical+block@c8a8c150c345418ca1d496ceaf1c3ebb" data-request-token="b6d7c8ae881c11efa860837f534d2eba" data-graded="False" data-has-score="False">
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@44c8fa1bec1e4c10b36b1c54b420223a">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@44c8fa1bec1e4c10b36b1c54b420223a" data-request-token="b6d7c8ae881c11efa860837f534d2eba" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<p style="text-align: left;">We will introduce a numpy structure called a <strong style="box-sizing: border-box;">dictionary</strong>. This will be useful for the next lesson on <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">xarray</span></code>.</p>
<p style="text-align: left;"></p>
</div>
</div>
<div class="vert vert-1" data-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@fb529acb7c0e4422a3064858d7878495">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@fb529acb7c0e4422a3064858d7878495" data-request-token="b6d7c8ae881c11efa860837f534d2eba" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<h3>Keys and values</h3>
<p>A dictionary represents a mapping between <strong style="box-sizing: border-box;">keys</strong> and <strong style="box-sizing: border-box;">values</strong>. The keys and values are Python objects of any type. We declare a dictionary using curly braces <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">{}</span></code>. Inside we specify the key then its associated value, with the keys and values separated by a colon <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">:</span></code>. Commas <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">,</span></code> are used to separate elements in the dictionary.</p>
<div class="highlight-python notranslate" style="box-sizing: border-box; border: 1px solid rgb(225, 228, 229); overflow-x: auto; margin: 1px 0px 24px; color: rgb(0, 0, 0); font-family: Arial, sans-serif;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow-x: auto; margin: 0px; padding: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 12px; overflow: auto;"><span style="box-sizing: border-box;"></span><span class="n" style="box-sizing: border-box;">dictionary_name</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="p" style="box-sizing: border-box;">{</span><span class="n" style="box-sizing: border-box;">key1</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">value1</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">key2</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">value2</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">key3</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">value3</span><span class="p" style="box-sizing: border-box;">}</span>
</pre>
</div>
</div>
<p>For example:</p>
<div class="nbinput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-top: 5px; padding-bottom: 5px; color: rgb(0, 0, 0); font-family: Arial, sans-serif;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[ ]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="n" style="box-sizing: border-box;">d</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="p" style="box-sizing: border-box;">{</span><span class="mi" style="box-sizing: border-box; color: #666666;">1</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s1" style="box-sizing: border-box; color: #ba2121;">'one'</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="mi" style="box-sizing: border-box; color: #666666;">2</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s1" style="box-sizing: border-box; color: #ba2121;">'two'</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="mi" style="box-sizing: border-box; color: #666666;">3</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s1" style="box-sizing: border-box; color: #ba2121;">'apple'</span><span class="p" style="box-sizing: border-box;">}</span>
</pre>
</div>
</div>
</div>
<p>In the above dictionary <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">d</span></code>, we have three <strong style="box-sizing: border-box;">keys</strong> <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">1</span></code>, <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">2</span></code>, <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">3</span></code>, and their respective <strong style="box-sizing: border-box;">values</strong> <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">'one'</span></code>, <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">'two'</span></code> and <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">'apple'</span></code>.</p>
<p>We can look up elements in a dictionary using the <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">[</span> <span class="pre" style="box-sizing: border-box;">key_name</span> <span class="pre" style="box-sizing: border-box;">]</span></code> to address the value stored under a key. The syntax looks like:</p>
<div class="highlight-python notranslate" style="box-sizing: border-box; border: 1px solid #e1e4e5; overflow-x: auto; margin: 1px 0px 24px; color: #000000; font-family: Arial, sans-serif;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow-x: auto; margin: 0px; padding: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 12px; overflow: auto;"><span style="box-sizing: border-box;"></span><span class="n" style="box-sizing: border-box;">dictionary_name</span><span class="p" style="box-sizing: border-box;">[</span><span class="n" style="box-sizing: border-box;">key_name</span><span class="p" style="box-sizing: border-box;">]</span>
</pre>
</div>
</div>
<p>In our example dictionary <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">d</span></code> above, we can call upon the value associated with the key name <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">1</span></code> like so:</p>
<div class="highlight-python notranslate" style="box-sizing: border-box; border: 1px solid #e1e4e5; overflow-x: auto; margin: 1px 0px 24px; color: #000000; font-family: Arial, sans-serif;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow-x: auto; margin: 0px; padding: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 12px; overflow: auto;"><span style="box-sizing: border-box;"></span><span class="n" style="box-sizing: border-box;">d</span><span class="p" style="box-sizing: border-box;">[</span><span class="mi" style="box-sizing: border-box; color: #666666;">1</span><span class="p" style="box-sizing: border-box;">]</span>
</pre>
</div>
</div>
<div class="nbinput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-top: 5px; padding-bottom: 5px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[ ]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="nb" style="box-sizing: border-box; color: #008000;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">d</span><span class="p" style="box-sizing: border-box;">[</span><span class="mi" style="box-sizing: border-box; color: #666666;">1</span><span class="p" style="box-sizing: border-box;">],</span> <span class="s2" style="box-sizing: border-box; color: #ba2121;">" + "</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">d</span><span class="p" style="box-sizing: border-box;">[</span><span class="mi" style="box-sizing: border-box; color: #666666;">2</span><span class="p" style="box-sizing: border-box;">],</span> <span class="s2" style="box-sizing: border-box; color: #ba2121;">" = "</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">d</span><span class="p" style="box-sizing: border-box;">[</span><span class="mi" style="box-sizing: border-box; color: #666666;">3</span><span class="p" style="box-sizing: border-box;">])</span>
</pre>
</div>
</div>
</div>
<p>Elements in a dictionary can be modified or new elements added by using the <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">dictionary_name[key_name]</span> <span class="pre" style="box-sizing: border-box;">=</span> <span class="pre" style="box-sizing: border-box;">value</span></code> syntax.</p>
<div class="nbinput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-top: 5px; padding-bottom: 5px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[ ]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="n" style="box-sizing: border-box;">d</span><span class="p" style="box-sizing: border-box;">[</span><span class="mi" style="box-sizing: border-box; color: #666666;">3</span><span class="p" style="box-sizing: border-box;">]</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="s1" style="box-sizing: border-box; color: #ba2121;">'three'</span>
<span class="n" style="box-sizing: border-box;">d</span><span class="p" style="box-sizing: border-box;">[</span><span class="mi" style="box-sizing: border-box; color: #666666;">4</span><span class="p" style="box-sizing: border-box;">]</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="s1" style="box-sizing: border-box; color: #ba2121;">'four'</span>
<span class="nb" style="box-sizing: border-box; color: #008000;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">d</span><span class="p" style="box-sizing: border-box;">[</span><span class="mi" style="box-sizing: border-box; color: #666666;">1</span><span class="p" style="box-sizing: border-box;">],</span> <span class="s2" style="box-sizing: border-box; color: #ba2121;">" + "</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">d</span><span class="p" style="box-sizing: border-box;">[</span><span class="mi" style="box-sizing: border-box; color: #666666;">2</span><span class="p" style="box-sizing: border-box;">],</span> <span class="s2" style="box-sizing: border-box; color: #ba2121;">" = "</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">d</span><span class="p" style="box-sizing: border-box;">[</span><span class="mi" style="box-sizing: border-box; color: #666666;">3</span><span class="p" style="box-sizing: border-box;">])</span>
</pre>
</div>
</div>
</div>
<p>Again, the dictionary name, key name, and value must be specified.</p>
<p></p>
</div>
</div>
<div class="vert vert-2" data-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@aa0d92defa2041f2a6bdd28a7eb1a910">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@aa0d92defa2041f2a6bdd28a7eb1a910" data-request-token="b6d7c8ae881c11efa860837f534d2eba" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<h3>Data classification with dictionaries</h3>
<p>Dictionaries are useful for data analysis (including satellite data analysis) because they make it easy to assign <strong style="box-sizing: border-box;">categorical values</strong> to our dataset. Remote sensing can be used to create classification products that use categorical values. These products do not contain continuous values. They use discrete values to represent different classes individual pixels can belong to.</p>
<p>As an example, the following cells simulate a very simple image containing three different land cover types. Value <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">1</span></code> represents area covered with grass, <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">2</span></code> croplands and <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">3</span></code> city.</p>
<p>First, we import the libraries we want to use.</p>
<div class="nbinput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-top: 5px; padding-bottom: 5px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[4]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="o" style="box-sizing: border-box; color: #666666;">%</span><span class="k" style="box-sizing: border-box; color: #008000; font-weight: bold;">matplotlib</span> inline
<span class="kn" style="box-sizing: border-box; color: #008000; font-weight: bold;">import</span> <span class="nn" style="box-sizing: border-box; color: #0000ff; font-weight: bold;">numpy</span> <span class="k" style="box-sizing: border-box; color: #008000; font-weight: bold;">as</span> <span class="nn" style="box-sizing: border-box; color: #0000ff; font-weight: bold;">np</span>
<span class="kn" style="box-sizing: border-box; color: #008000; font-weight: bold;">from</span> <span class="nn" style="box-sizing: border-box; color: #0000ff; font-weight: bold;">matplotlib</span> <span class="kn" style="box-sizing: border-box; color: #008000; font-weight: bold;">import</span> <span class="n" style="box-sizing: border-box;">pyplot</span> <span class="k" style="box-sizing: border-box; color: #008000; font-weight: bold;">as</span> <span class="n" style="box-sizing: border-box;">plt</span>
<span class="kn" style="box-sizing: border-box; color: #008000; font-weight: bold;">from</span> <span class="nn" style="box-sizing: border-box; color: #0000ff; font-weight: bold;">matplotlib</span> <span class="kn" style="box-sizing: border-box; color: #008000; font-weight: bold;">import</span> <span class="n" style="box-sizing: border-box;">colors</span>
</pre>
</div>
</div>
</div>
<p>We will now create a 2-dimensional 100 pixel x 100 pixel numpy array where every value is <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">1</span></code>. This is done using the <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">numpy.ones</span></code> function. Then, we use array indexing to assign part of the area to have the value <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">2</span></code>, and another part to have the value <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">3</span></code>.</p>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; padding-top: 5px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[5]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># grass = 1</span>
<span class="n" style="box-sizing: border-box;">area</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="n" style="box-sizing: border-box;">np</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">ones</span><span class="p" style="box-sizing: border-box;">((</span><span class="mi" style="box-sizing: border-box; color: #666666;">100</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">100</span><span class="p" style="box-sizing: border-box;">))</span>
<span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># crops = 2</span>
<span class="n" style="box-sizing: border-box;">area</span><span class="p" style="box-sizing: border-box;">[</span><span class="mi" style="box-sizing: border-box; color: #666666;">10</span><span class="p" style="box-sizing: border-box;">:</span><span class="mi" style="box-sizing: border-box; color: #666666;">60</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">20</span><span class="p" style="box-sizing: border-box;">:</span><span class="mi" style="box-sizing: border-box; color: #666666;">50</span><span class="p" style="box-sizing: border-box;">]</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="mi" style="box-sizing: border-box; color: #666666;">2</span>
<span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># city = 3</span>
<span class="n" style="box-sizing: border-box;">area</span><span class="p" style="box-sizing: border-box;">[</span><span class="mi" style="box-sizing: border-box; color: #666666;">70</span><span class="p" style="box-sizing: border-box;">:</span><span class="mi" style="box-sizing: border-box; color: #666666;">90</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">60</span><span class="p" style="box-sizing: border-box;">:</span><span class="mi" style="box-sizing: border-box; color: #666666;">80</span><span class="p" style="box-sizing: border-box;">]</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="mi" style="box-sizing: border-box; color: #666666;">3</span>
<span class="n" style="box-sizing: border-box;">area</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">shape</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">area</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">dtype</span>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[5]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;">((100, 100), dtype('float64'))
</pre>
</div>
</div>
</div>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: -19px 0px 0px; width: 696.469px; padding-top: 5px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[6]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="n" style="box-sizing: border-box;">area</span>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[6]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;">array([[1., 1., 1., ..., 1., 1., 1.],
[1., 1., 1., ..., 1., 1., 1.],
[1., 1., 1., ..., 1., 1., 1.],
...,
[1., 1., 1., ..., 1., 1., 1.],
[1., 1., 1., ..., 1., 1., 1.],
[1., 1., 1., ..., 1., 1., 1.]])
</pre>
</div>
</div>
</div>
<p>We now have a matrix filled with 1s, 2s and 3s. At this point, there is no association between the numbers and the different types of ground cover.</p>
<p>If we want to show what the area looks like according to the grass/crops/city designation, we might want to give each of the classifications a colour.</p>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; padding-top: 5px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[7]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># We map the values to colours</span>
<span class="n" style="box-sizing: border-box;">index</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="p" style="box-sizing: border-box;">{</span><span class="mi" style="box-sizing: border-box; color: #666666;">1</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s1" style="box-sizing: border-box; color: #ba2121;">'green'</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">2</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s1" style="box-sizing: border-box; color: #ba2121;">'yellow'</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">3</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s1" style="box-sizing: border-box; color: #ba2121;">'grey'</span><span class="p" style="box-sizing: border-box;">}</span>
<span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Create a discrete colour map</span>
<span class="n" style="box-sizing: border-box;">cmap</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="n" style="box-sizing: border-box;">colors</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">ListedColormap</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">index</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">values</span><span class="p" style="box-sizing: border-box;">())</span>
<span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Plot</span>
<span class="n" style="box-sizing: border-box;">plt</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">imshow</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">area</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">cmap</span><span class="o" style="box-sizing: border-box; color: #666666;">=</span><span class="n" style="box-sizing: border-box;">cmap</span><span class="p" style="box-sizing: border-box;">)</span>
</pre>
</div>
</div>
</div>
<div class="nboutput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[7]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;"><matplotlib.image.AxesImage at 0x7fe7b5487f98>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt empty docutils container" style="box-sizing: border-box; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;"></div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;"><img alt="../_images/python_basics_04_cleaning_data_21_1.png" src="https://learn.digitalearthafrica.org/asset-v1:digitalearthafrica+DEA101+2021+type@asset+block@python_basics_04_cleaning_data_21_1.png" style="box-sizing: border-box; border: 0px; vertical-align: middle; padding: 5px; margin: 0px;" /></div>
</div>
<p>In the case above, every pixel had a value of either <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">1</span></code>, <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">2</span></code> or <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">3</span></code>. What happens if our dataset is incomplete and there is no data in some places?</p>
<p></p>
</div>
</div>
<div class="vert vert-3" data-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@02ab35f043bf4daa88372bf67c21310f">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@02ab35f043bf4daa88372bf67c21310f" data-request-token="b6d7c8ae881c11efa860837f534d2eba" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<h3>Missing data</h3>
<p>This is a common problem in real-life datasets. Real datasets can be incomplete and may be missing data at certain times or places. To deal with this, we use the special value known as <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">NaN</span></code>, which stands for <strong style="box-sizing: border-box;">Not a Number</strong>.</p>
<p><code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">NaNs</span></code> are designated by the numpy <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">np.nan</span></code> function.</p>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; padding-top: 5px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[8]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="n" style="box-sizing: border-box;">arr</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="n" style="box-sizing: border-box;">np</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">array</span><span class="p" style="box-sizing: border-box;">([</span><span class="mi" style="box-sizing: border-box; color: #666666;">1</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">2</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">3</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">4</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">5</span><span class="p" style="box-sizing: border-box;">,</span><span class="n" style="box-sizing: border-box;">np</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">nan</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">7</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">8</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">9</span><span class="p" style="box-sizing: border-box;">],</span> <span class="n" style="box-sizing: border-box;">dtype</span><span class="o" style="box-sizing: border-box; color: #666666;">=</span><span class="n" style="box-sizing: border-box;">np</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">float32</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="n" style="box-sizing: border-box;">arr</span>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[8]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;">array([ 1., 2., 3., 4., 5., nan, 7., 8., 9.], dtype=float32)
</pre>
</div>
</div>
</div>
<p>To compute statistics on arrays containing NaN values, numpy has special versions of common functions such as <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">mean</span></code>, standard deviation <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">std</span></code>, and <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">sum</span></code> that ignore the <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">NaN</span></code> values. For example, the next cell shows the difference between using the usual <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">mean</span></code> function and the <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">nanmean</span></code> function.</p>
<p>The <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">mean</span></code> function cannot handle <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">NaN</span></code> values so it will return <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">nan</span></code>. The <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">nanmean</span></code> function does not include <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">NaN</span></code> values in the calculation, and therefore returns a number value.</p>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; padding-top: 5px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[9]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="nb" style="box-sizing: border-box; color: #008000;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">np</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">mean</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">arr</span><span class="p" style="box-sizing: border-box;">))</span>
<span class="nb" style="box-sizing: border-box; color: #008000;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">np</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">nanmean</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">arr</span><span class="p" style="box-sizing: border-box;">))</span>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt empty docutils container" style="box-sizing: border-box; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;"></div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;">nan
4.875
</pre>
</div>
</div>
</div>
<p></p>
<p></p>
<p></p>
<p>Note that <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">NaN</span></code> is generally not used as a key in dictionary key-value entries because there are different ways of expressing <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">NaN</span></code> in Python and they are not always equivalent. However, it is still possible to visualise data with <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">NaNs</span></code>; there will be gaps in the image where there is no data.</p>
</div>
</div>
</div>
<script type="text/javascript">
(function (require) {
require(['/static/js/dateutil_factory.be68acdff619.js?raw'], function () {
require(['js/dateutil_factory'], function (DateUtilFactory) {
DateUtilFactory.transform('.localized-datetime');
});
});
}).call(this, require || RequireJS.require);
</script>
<script>
function emit_event(message) {
parent.postMessage(message, '*');
}
</script>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="VerticalStudentView" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@vertical+block@2d01a21a54fd47d89936425610777481" data-request-token="b6d7c8ae881c11efa860837f534d2eba" data-graded="False" data-has-score="False">
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@14739648bb1c4d0bb2a3ff359a8a0529">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@14739648bb1c4d0bb2a3ff359a8a0529" data-request-token="b6d7c8ae881c11efa860837f534d2eba" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<section id="Exercises" style="box-sizing: border-box;">
<section id="4.1-The-harvesting-season-has-arrived-and-our-cropping-lands-have-changed-colour-to-brown.-Can-you:" style="box-sizing: border-box;">
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699; text-align: left;">4.1 The harvesting season has arrived and our cropping lands have changed colour to brown. Can you:<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/04_cleaning_data.html#4.1-The-harvesting-season-has-arrived-and-our-cropping-lands-have-changed-colour-to-brown.-Can-you:" title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h3>
<section id="4.1.1-Modify-the-yellow-area-to-contain-the-new-value-4?" style="box-sizing: border-box;">
<h4 style="box-sizing: border-box; font-size: 18.4px; color: #336699;">4.1.1 Modify the yellow area to contain the new value <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 13.8px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">4</span></code>?<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/04_cleaning_data.html#4.1.1-Modify-the-yellow-area-to-contain-the-new-value-4?" title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h4>
</section>
<section id="4.1.2-Add-a-new-entry-to-the-index-dictionary-mapping-number-4-to-the-value-brown." style="box-sizing: border-box;">
<h4 style="box-sizing: border-box; font-size: 18.4px; color: #336699;">4.1.2 Add a new entry to the <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 13.8px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">index</span></code> dictionary mapping number <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 13.8px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">4</span></code> to the value <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 13.8px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">brown</span></code>.<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/04_cleaning_data.html#4.1.2-Add-a-new-entry-to-the-index-dictionary-mapping-number-4-to-the-value-brown." title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h4>
</section>
<section id="4.1.3-Plot-the-area." style="box-sizing: border-box;">
<h4 style="box-sizing: border-box; font-size: 18.4px; color: #336699;">4.1.3 Plot the area.<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/04_cleaning_data.html#4.1.3-Plot-the-area." title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h4>
<div class="nbinput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-top: 5px; padding-bottom: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 16px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[ ]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 16px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># 4.1.1 Modify the yellow area to hold the value 4</span>
</pre>
</div>
</div>
</div>
<div class="nbinput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: -19px 0px 19px; width: 696.469px; padding-top: 5px; padding-bottom: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 16px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[ ]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 16px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># 4.1.2 Add a new key-value pair to index that maps 4 to 'brown'</span>
</pre>
</div>
</div>
</div>
<div class="nbinput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: -19px 0px 19px; width: 696.469px; padding-top: 5px; padding-bottom: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 16px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[ ]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 16px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># 4.1.3 Copy the cmap definition and re-run it to add the new colour</span>
<span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Plot the area</span>
</pre>
</div>
</div>
</div>
<div style="box-sizing: border-box;">
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px; text-align: left;"><strong style="box-sizing: border-box;">Hint:</strong> If you want to plot the new area, you have to redefine <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">cmap</span></code> so the new value is assigned a colour in the colour map. Copy and paste the <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">cmap</span> <span class="pre" style="box-sizing: border-box;">=</span> <span class="pre" style="box-sizing: border-box;">...</span></code> line from the original plot.</p>
</div>
</section>
</section>
<section id="4.2-Set-area[20:40,-80:95]-=-np.nan.-Plot-the-area-now." style="box-sizing: border-box;">
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699;">4.2 Set <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">area[20:40,</span> <span class="pre" style="box-sizing: border-box;">80:95]</span> <span class="pre" style="box-sizing: border-box;">=</span> <span class="pre" style="box-sizing: border-box;">np.nan</span></code>. Plot the area now.<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/04_cleaning_data.html#4.2-Set-area[20:40,-80:95]-=-np.nan.-Plot-the-area-now." title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h3>
<div class="nbinput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-top: 5px; padding-bottom: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 16px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[ ]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 16px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Set the nan area</span>
</pre>
</div>
</div>
</div>
<div class="nbinput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: -19px 0px 19px; width: 696.469px; padding-top: 5px; padding-bottom: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 16px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[ ]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 16px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Plot the entire area</span>
</pre>
</div>
</div>
</div>
</section>
<section id="4.3-Find-the-median-of-the-area-array-from-4.2-using-np.nanmedian.-Does-this-match-your-visual-interpretation?-How-does-this-compare-to-using-np.median?" style="box-sizing: border-box;">
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699; text-align: left;">4.3 Find the median of the <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">area</span></code> array from 4.2 using <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">np.nanmedian</span></code>. Does this match your visual interpretation? How does this compare to using <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">np.median</span></code>?<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/04_cleaning_data.html#4.3-Find-the-median-of-the-area-array-from-4.2-using-np.nanmedian.-Does-this-match-your-visual-interpretation?-How-does-this-compare-to-using-np.median?" title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h3>
<div class="nbinput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-top: 5px; padding-bottom: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none; text-align: left;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 16px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[ ]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; text-align: left;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 16px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Use np.nanmedian to find the median of the area</span>
</pre>
</div>
</div>
</div>
</section>
</section>
</div>
</div>
</div>
<script type="text/javascript">
(function (require) {
require(['/static/js/dateutil_factory.be68acdff619.js?raw'], function () {
require(['js/dateutil_factory'], function (DateUtilFactory) {
DateUtilFactory.transform('.localized-datetime');
});
});
}).call(this, require || RequireJS.require);
</script>
<script>
function emit_event(message) {
parent.postMessage(message, '*');
}
</script>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="VerticalStudentView" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@vertical+block@ea0e93b20f354ff4bca7f6b0a24cdcc3" data-request-token="b6d7c8ae881c11efa860837f534d2eba" data-graded="False" data-has-score="False">
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@80a23b34dcbb43f889bfe4b8c9f97a04">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@80a23b34dcbb43f889bfe4b8c9f97a04" data-request-token="b6d7c8ae881c11efa860837f534d2eba" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<p style="text-align: left;"><span>Two key Python capabilities have been introduced in this section. We can organise our data using the dictionary syntax, and understand incomplete datasets that may use </span><code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">NaN</span></code><span> values to show blanks. The next lesson provides a guide to xarray, a Python package that builds on these concepts to make multi-dimensional data easier to load and use.</span></p>
</div>
</div>
</div>
<script type="text/javascript">
(function (require) {
require(['/static/js/dateutil_factory.be68acdff619.js?raw'], function () {
require(['js/dateutil_factory'], function (DateUtilFactory) {
DateUtilFactory.transform('.localized-datetime');
});
});
}).call(this, require || RequireJS.require);
</script>
<script>
function emit_event(message) {
parent.postMessage(message, '*');
}
</script>
</div>