<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by GIS-ish on Medium]]></title>
        <description><![CDATA[Stories by GIS-ish on Medium]]></description>
        <link>https://medium.com/@gis-ish?source=rss-e36684b36d1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*paLaGGK5ZMqLXc8UzLEi9w.jpeg</url>
            <title>Stories by GIS-ish on Medium</title>
            <link>https://medium.com/@gis-ish?source=rss-e36684b36d1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 16:40:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gis-ish/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Exporting One Shape File to Multiple Shape Files Using Python]]></title>
            <link>https://medium.com/@gis-ish/exporting-one-shape-file-to-multiple-shape-files-using-python-eb503f127a46?source=rss-e36684b36d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb503f127a46</guid>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[gis]]></category>
            <category><![CDATA[spatial-analysis]]></category>
            <category><![CDATA[geopandas]]></category>
            <dc:creator><![CDATA[GIS-ish]]></dc:creator>
            <pubDate>Wed, 14 Dec 2022 15:45:48 GMT</pubDate>
            <atom:updated>2022-12-14T15:52:47.811Z</atom:updated>
            <content:encoded><![CDATA[<h4>Automating with python</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9-FJKe8dOzXs1Nsx" /><figcaption>Photo by <a href="https://unsplash.com/@hiteshchoudhary?utm_source=medium&amp;utm_medium=referral">Hitesh Choudhary</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This is a fairly simple process, but I couldn’t find the code to do it anywhere. So I wrote one for the future. If there is a simpler way, then do let me know.</p><p>If you have a single shape file containing multiple polygons (in this example it’s India with all the states) and want to write each polygon into a new shape file then this code is simple and useful.</p><p>First we can import the modules required.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/16fea1d8b03c64092357e464150d7fe9/href">https://medium.com/media/16fea1d8b03c64092357e464150d7fe9/href</a></iframe><p>Pathlib is a simpler module to read the files in python compared to the os module.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1dad31c89f735ab7b10e27533826dea/href">https://medium.com/media/d1dad31c89f735ab7b10e27533826dea/href</a></iframe><p>The shape file is read using the geopandas module. The first 5 rows of the data is viewed by opening it’s attribute table, as well as the shape file is plotted.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38415cef46607e3555357e71291bfb7e/href">https://medium.com/media/38415cef46607e3555357e71291bfb7e/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*S6LgjfSAIZ7gf1i22OYZCQ.jpeg" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3675de075535dd74803c891b293629d/href">https://medium.com/media/b3675de075535dd74803c891b293629d/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/218/1*xElI90eKqtev7QmaYJz2kg.jpeg" /></figure><p>Now each new file will need a new name which I extracted as the states name from the available column of state names.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4721e9735d915149f2c0d990d292312a/href">https://medium.com/media/4721e9735d915149f2c0d990d292312a/href</a></iframe><pre>Andaman &amp; Nicobar<br>Andhra Pradesh<br>Arunachal Pradesh<br>Assam<br>Bihar<br>Chandigarh<br>Chhattisgarh<br>Dadra &amp; Nagar Haveli &amp; Daman &amp; Diu<br>Delhi<br>Disputed (Madhya Pradesh &amp; Gujarat)<br>Disputed (Madhya Pradesh &amp; Rajasthan)<br>Disputed (Rajathan &amp; Gujarat)<br>Disputed (West Bengal , Bihar &amp; Jharkhand)<br>Goa<br>Gujarat<br>Haryana<br>Himachal Pradesh<br>Jammu And Kashmir<br>Jharkhand<br>Karnataka<br>Kerala<br>Ladakh<br>Lakshadweep<br>Madhya Pradesh<br>Maharashtra<br>Manipur<br>Meghalaya<br>Mizoram<br>Nagaland<br>Odisha<br>Puducherry<br>Punjab<br>Rajasthan<br>Sikkim<br>Tamil Nadu<br>Telangana<br>Tripura<br>Uttarakhand<br>Uttar Pradesh<br>West Bengal</pre><p>Finally we can simply iterate over each row, read each row as a state and write into another file having the name of it’s state.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cfc074125467a39bbbc0f4c2b5c37aec/href">https://medium.com/media/cfc074125467a39bbbc0f4c2b5c37aec/href</a></iframe><h4>Reference</h4><ul><li><a href="https://stackoverflow.com/questions/49323439/plot-the-geometry-of-one-row-of-a-geodataframe">stackoverflow</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb503f127a46" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Urban Area Detection Using Landsat Images]]></title>
            <link>https://medium.com/@gis-ish/urban-area-detection-using-landsat-images-c952c7616ca4?source=rss-e36684b36d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/c952c7616ca4</guid>
            <category><![CDATA[gis]]></category>
            <category><![CDATA[landsat8]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[urban-planning]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[GIS-ish]]></dc:creator>
            <pubDate>Sat, 03 Dec 2022 07:34:46 GMT</pubDate>
            <atom:updated>2022-12-03T07:34:46.398Z</atom:updated>
            <content:encoded><![CDATA[<h4>Identifying urban areas from Landsat image using built up index</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/981/1*Sdi9HiI6xAFwgZ8k_D70bw.jpeg" /></figure><p>I have done this project as a part of my course work for “<a href="https://courses.spatialthoughts.com/python-foundation.html">Python Foundation for Spatial Analysis</a>” conducted by the <a href="https://spatialthoughts.com/">Spatial Thoughts</a> organization.</p><p>For this study the data used is <strong>Landsat 8–9 OLI/TIRS Collection 2 Level 2</strong>.</p><p>The Landsat image has the date of occurrence as<strong> 26 August 2017</strong>, which is taken as <strong>20170524</strong> . To identify the urban area different indexes are used. In this case the index used are <strong>NDBI</strong>,<strong>NDVI </strong>and <strong>BU</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa0f6783a715dd147371ba1c3cfb0cb4/href">https://medium.com/media/fa0f6783a715dd147371ba1c3cfb0cb4/href</a></iframe><p>The Landsat data to be used is opened from it’s path. The data used contains two scenes to complete the area. Different scenes are defined based on their path and row, In this case;</p><ul><li><strong>Path: 025 • Row: 039</strong></li><li><strong>Path: 025 • Row: 040</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ac3e3448e44d14b4aa749a807766549/href">https://medium.com/media/8ac3e3448e44d14b4aa749a807766549/href</a></iframe><p>The <strong>merge </strong>function is defined to merge the different scenes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9cde5f4b31eedb81869702b2df490588/href">https://medium.com/media/9cde5f4b31eedb81869702b2df490588/href</a></iframe><p>The different bands containing two scenes are merged into one image. To check the image the merged band 4 are plotted.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd776a72720dd1405d8502d4b4bb10e7/href">https://medium.com/media/bd776a72720dd1405d8502d4b4bb10e7/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*ZyiO_Dd50qRFnPA3W9hJyA.jpeg" /></figure><p>The merged bands are saved and opened to stack the data one over the other.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c966c0be41fee10a1bb78801fa8153d/href">https://medium.com/media/4c966c0be41fee10a1bb78801fa8153d/href</a></iframe><p>The <strong>glob </strong>function is used to group the similar bands together.</p><p>This is done to stack the data together, which is needed for the index calculation. The extent of study area is read using a shape file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93976d243f46d1f35e5b8223b2eb390d/href">https://medium.com/media/93976d243f46d1f35e5b8223b2eb390d/href</a></iframe><p><em>[‘urban\\outputs\\band4.tif’, ‘urban\\outputs\\band5.tif’, ‘urban\\outputs\\band6.tif’]</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af51a9991146fb223a5cacbd36d9417e/href">https://medium.com/media/af51a9991146fb223a5cacbd36d9417e/href</a></iframe><p>To cut the Landsat data up to the extent of the Area of Interest, the projection of both data is checked. And the area of interest is projected to the <strong>coordinate system</strong> of the Landsat data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12688745b7371d5b0e35bbb6446f1f00/href">https://medium.com/media/12688745b7371d5b0e35bbb6446f1f00/href</a></iframe><p>Two functions are defined to read the different bands of data. Both of them are clubbed together, one through another.</p><ul><li>The <strong>open_clean_band</strong> function is used clip the given bands to the area of interest.</li><li>The <strong>process_bands </strong>function is defined to stack all the clipped bands together one over the other.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8d8c35b9e9819daf957d83c3f112beed/href">https://medium.com/media/8d8c35b9e9819daf957d83c3f112beed/href</a></iframe><p>The Landsat data is stacked using the predefined functions. The stack contains.</p><ul><li><strong>band_clip[0] = Band 4</strong></li><li><strong>band_clip[1] = band 5</strong></li><li><strong>band_clip[2] = Band 6</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de7bba74c8b428e97d90b7794a8be3c2/href">https://medium.com/media/de7bba74c8b428e97d90b7794a8be3c2/href</a></iframe><p><em>I’m stacking your data now.</em></p><p>The stacked data with bands 4, 5 and 6 are plotted into a composite image to observe.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/664ec6b96f1d84a4d9cb9bb5ba96f9e2/href">https://medium.com/media/664ec6b96f1d84a4d9cb9bb5ba96f9e2/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*QAJ9HNYHvKRQRrOMgJSimA.jpeg" /></figure><h4><strong>Normal Difference Built-up Index(NDBI)</strong></h4><p>This index highlights urban areas where there is typically a higher reflectance in the shortwave-infrared (SWIR) region, compared to the near-infrared (NIR) region.</p><p>NDBI = (SWIR — NIR) / (SWIR + NIR)</p><p>For Landsat 8 data, NDBI = (Band 6 — Band 5) / (Band 6 + Band 5)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be60cd893fbffde92b9b96bbcc7e46fc/href">https://medium.com/media/be60cd893fbffde92b9b96bbcc7e46fc/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*xcY_aDjyzXK3yIN3-LFnGQ.jpeg" /></figure><h4><strong>Normalized Difference Vegetation Index (NDVI)</strong></h4><p>Normalized Difference Vegetation Index (NDVI) quantifies vegetation by measuring the difference between near-infrared (which vegetation strongly reflects) and red light (which vegetation absorbs)</p><p>NDVI = (NIR — Red) / (NIR + Red)</p><p>For Landsat 8 data, NDVI = (Band 5 — Band 4) / (Band 5 + Band 4)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b643285e3f0fc4af9e6e8421da8bae35/href">https://medium.com/media/b643285e3f0fc4af9e6e8421da8bae35/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*055jNdCDN_shY6elqemHKQ.jpeg" /></figure><h4><strong>Built-up Index (BU)</strong></h4><p>There are lots of indexes for the analysis of built-up area.</p><p>The build-up areas and bare soil reflects more SWIR than NIR. Water body doesn’t reflect on Infrared spectrum.</p><p>Build-up Index is the index for analysis of urban pattern using NDBI and NDVI. Built-up index is the binary image with only higher positive value indicates built-up and barren thus, allows BU to map the built-up area automatically.</p><p>BU = NDBI — NDVI</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4739e2f453620b30fa62e71e8abceba/href">https://medium.com/media/e4739e2f453620b30fa62e71e8abceba/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*hzz86Sy9tt0x-v44glRdfg.jpeg" /></figure><p>The Built up index is reclassified manually to identify the built up area. four classes are created and values are identified from multiple iterations.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba188cf9decfe487d3f61c7044f155cc/href">https://medium.com/media/ba188cf9decfe487d3f61c7044f155cc/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*Pok4A1BeTrfAtBO6zwf5kQ.jpeg" /></figure><p>The built up area is identified from the Landsat image.</p><h4><strong>Reference</strong></h4><ul><li><a href="https://www.tandfonline.com/doi/abs/10.1080/01431160304987">Use of normalized difference built-up index in automatically mapping urban areas from TM imagery</a></li><li><a href="https://www.earthdatascience.org/courses/use-data-open-source-python/multispectral-remote-sensing/">Earthdatascience</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c952c7616ca4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pandas — Select data]]></title>
            <link>https://medium.com/@gis-ish/pandas-select-data-ca66d96049dd?source=rss-e36684b36d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca66d96049dd</guid>
            <category><![CDATA[pandas-dataframe]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[GIS-ish]]></dc:creator>
            <pubDate>Mon, 10 Oct 2022 10:02:14 GMT</pubDate>
            <atom:updated>2022-10-10T10:02:14.807Z</atom:updated>
            <content:encoded><![CDATA[<h3>Pandas — Select data</h3><p>There are different methods to select data from a dataframe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2TSqiowTzxo-_BOw3hLpSQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@ffstop?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Fotis Fotopoulos</a> on <a href="https://unsplash.com/s/photos/python?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>When you have a large amount of data you need to seperate the necessary subset of data. There are different methods to select data from a dataframe. We can select specific rows, columns or individual values.</p><h4>Basic</h4><p>The most basic method of selecting data is passing a the column or a list of columns through<strong> “[]” </strong>to select columns in that order. If a column is not contained in the DataFrame, an exception will be raised.</p><p>If we use the name of column to select data. For a single column to be selected we can pass that through the syntax.</p><pre>data[&quot;AOD_500nm&quot;]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*bJWW4O1lmBGYw1TPivqSSg.jpeg" /></figure><p>But for multiple columns, the names of columns have to be passed as a list itself.</p><pre>data1 = data[[&quot;AOD_500nm&quot;,&#39;Precipitable_Water(cm)&#39;, &#39;380-500_Angstrom_Exponent&#39;,&#39;NUM_DAYS[AOD_500nm]&#39;,&#39;Latitude(degrees)&#39;, &#39;Longitude(degrees)&#39;, &#39;Elevation(meters)&#39;]]</pre><pre>data1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/1*RgfNZK3GHscFSO1W1LDynw.jpeg" /></figure><p>In this basic method we can also slice data. But it will only slice the rows. You can select the specific columns [0:11] and even decide to skip the odd ones in between.</p><pre>data2 = data[0:11:2]</pre><pre>data2</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*4pV73yDEP70rnvJZ8DUJqQ.jpeg" /></figure><h4>loc()</h4><p>For selection the pandas <a href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.loc.html"><strong>loc()</strong></a> function can be used in two ways.</p><ul><li>To select using label/index.</li><li>To select using a conditional statement.</li></ul><p>The arguments for loc() are row selector and column selector. This function can be used to select one row or slice of row by calling the index of the row. To print the single row neatly add a bracket again.</p><pre>data.loc[7]<br>data.loc[[5]]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*7iAvrL_z70CXNnAGtZBySQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*6Y5I5geHjGY0y_E0FMeVQw.jpeg" /></figure><pre>data.loc[0:5]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*9sy2oS3WBUhmy8j6v-72yQ.jpeg" /></figure><p>To select specific columns we have to set the row selector first then set the columns selector. Single column can be called separately, but multiple column needs to be called as a list. The specific rows can be sliced according to the need as the row selector.</p><pre>data.loc[:,[&#39;Month&#39;,&#39;AOD_1020nm&#39;]]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*MHUImtPE88lJ7S2aOiiBqw.jpeg" /></figure><pre>data.loc[2:10,[&#39;Month&#39;,&#39;AOD_1020nm&#39;]]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/221/1*YjcmvUrR7R2XagPtDMDl2w.jpeg" /></figure><p>Now the selection of columns using conditional statements is one of the most common use of loc() function. This is also called filtering of data.</p><p>In most use cases, you will make selections based on the values of different columns in your data set. if we use the condition of only one column.</p><pre>data.loc[data[&#39;AOD_500nm&#39;] &lt; 0.38]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*uiDY_Xu2u4JocqvEV3ub0g.jpeg" /></figure><p>In the case of multiple conditions the “AND” (|) and “OR” (&amp;) operators are used for selection.</p><pre>data.loc[(data[&#39;AOD_500nm&#39;] &lt; 0.42) &amp; (data[&#39;NUM_DAYS[AOD_500nm]&#39;] &gt; 20)]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*c1bNXmY6a8URi2pgQozh-g.jpeg" /></figure><h4>iloc()</h4><p>Similarly <a href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.iloc.html"><strong>iloc()</strong></a> is used for purely integer-location based indexing for selection by position.</p><pre>data.iloc[0:5:, 0:2]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/219/1*wgxsHMPUALLBiYkq9pEcGQ.jpeg" /></figure><h4>at()</h4><p>To access a single value in a dataframe <a href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.at.html"><strong>at()</strong></a> function is used. this function is similar to loc() function, it can use labels and column names for selecting data. Similar to iloc(), iat() function selects data based on position indexes.</p><pre>data.at[5,&#39;AOD_500nm&#39;]</pre><pre>0.582412</pre><p>For more information, please have a look at the sites linked below.</p><ul><li><a href="https://sparkbyexamples.com/pandas/pandas-select-columns-by-name-or-index/">sparkbyexample</a></li><li><a href="https://www.shanelynn.ie/pandas-iloc-loc-select-rows-and-columns-dataframe/#:~:text=Selections%20using%20the%20loc%20method,index%20values%20of%20any%20rows.">shanelynn</a></li><li><a href="https://pandas.pydata.org/docs/user_guide/indexing.html#selection-by-label">pandas documentation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca66d96049dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pandas — Missing data]]></title>
            <link>https://medium.com/@gis-ish/pandas-missing-data-8d3becc687fa?source=rss-e36684b36d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d3becc687fa</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[pandas-tutorial]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[missing-values]]></category>
            <dc:creator><![CDATA[GIS-ish]]></dc:creator>
            <pubDate>Fri, 07 Oct 2022 05:19:34 GMT</pubDate>
            <atom:updated>2022-10-10T09:00:29.196Z</atom:updated>
            <content:encoded><![CDATA[<h3>Pandas — Missing data</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2TSqiowTzxo-_BOw3hLpSQ.jpeg" /></figure><p>Real world data will have values missing in different columns or rows, thus we have to clean our data before proceeding to any analysis. Cleaning our data is one of the important initial step.</p><p>In a dataframe missing data can occur when no information is provided for one or more items or for a whole unit. Missing Data can also refer to as NA(Not Available) values in pandas. Let look in to all the methods we use to clean our data from NaN values.</p><ul><li><strong>isna(), notna(), isnull(), notnull()</strong></li></ul><p>First we have to identify the missing values in our data for this we have different functions like isna(), notna(), isnull(), notnull(). These functions help in checking whether a value is NaN or not.</p><p>These function takes a scalar or array-like object and indicates whether values are missing.</p><p>isna() and isnull() return a boolean mask where <strong>True </strong>is set for missing values (NaN) with <strong>False </strong>for non-missing values. I researched the difference between both these function and found that they are identical ( Shocking! I know). The best explanation was <a href="https://datascience.stackexchange.com/questions/37878/difference-between-isna-and-isnull-in-pandas">here</a>.</p><pre>data.isna()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*-kN3QJPQH4FVY4JzVCHCgA.jpeg" /></figure><p>The reverse of this is done by isnull() and notnull() they return a boolean mask where <strong>False </strong>is set for missing values (NaN) with <strong>True </strong>for non-missing values.</p><pre>data.notnull()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/1*N4bdMUxGhkXyTrKkqnO7Rw.jpeg" /></figure><p>After finding the missing values we need to clean them. Pandas objects are equipped with various data manipulation methods for dealing with missing data.</p><h4><a href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.dropna.html"><strong>dropna()</strong></a></h4><p>This function is used to remove NA values. Lets look into all the arguments of the fuinction.</p><pre>data.dropna(axis=1, thresh=200,inplace=True)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/939/1*acBSewaIPPWtlRXXA3lvrg.jpeg" /></figure><pre>data.dropna(axis=0,thresh=10, inplace=True)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*6EUEIaAT2Ur92CWvEGyZ3w.jpeg" /></figure><p>To choose whether we need to delete the rows or columns containing the Na values we use<strong> axis.</strong> only one can be deleted at a time.</p><ul><li>If axis is set as “0” or ‘index’ the functions Drop rows which contain missing values.</li><li>If axis is set as “1” or ‘column’ the functions Drop columns which contain missing values.</li></ul><p>To determine the condition in which to delete the row or column we use <strong>how</strong> argument.</p><ul><li>When how is set to ‘any’, drop that row or column if any NA values are present.</li><li>When how is set to ‘all’ , drop that row or column if all values are NA.</li></ul><p>In the cases where we cannot choose any or all we use <strong>thresh </strong>argument. Here we set an integer value as we require that many non-NA values. Cannot be combined with how.</p><p>If we need to delete the rows for some specific column of missing values then we use <strong>subset </strong>argument. Labels along other axis to consider, e.g. if you are dropping rows these would be a list of columns to include.</p><p>Now the last argument <strong>inplace </strong>is to decide if we should change the parent dataframe or create new one.</p><ul><li>If inplace is set to True then the dataframe will be permanently changes</li><li>If inplace is set to False then the change will not be made on the parent dataframe</li></ul><p>dropna() can also be used for selecting a slice data and finding missing values for only one column. In this case the data has to be stored into a new dataframe as the original data is sliced in the process.</p><pre>data2 = data1[[&#39;AOD_1640nm&#39;, &#39;AOD_1020nm&#39;, &#39;AOD_865nm&#39;]].dropna(subset=&quot;AOD_1020nm&quot;)</pre><pre>data2</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*DDdbTxTjaWnodEKZsFNp9Q.jpeg" /></figure><p>For more information, please have a look at the sites linked below.</p><ul><li>g<a href="https://www.geeksforgeeks.org/working-with-missing-data-in-pandas/#:~:text=In%20order%20to%20check%20missing,null%20values%20in%20a%20series.">eeksforgeeks</a></li><li><a href="https://www.tutorialspoint.com/python_pandas/python_pandas_missing_data.htm">tutorialspoint</a></li><li><a href="https://pandas.pydata.org/docs/user_guide/missing_data.html">Pandas documentation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d3becc687fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pandas — Checking Data]]></title>
            <link>https://medium.com/@gis-ish/pandas-checking-data-6675796a1f0e?source=rss-e36684b36d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/6675796a1f0e</guid>
            <category><![CDATA[pandas-dataframe]]></category>
            <category><![CDATA[dataframes]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[data-analysis]]></category>
            <dc:creator><![CDATA[GIS-ish]]></dc:creator>
            <pubDate>Mon, 03 Oct 2022 08:40:20 GMT</pubDate>
            <atom:updated>2022-10-03T08:40:20.760Z</atom:updated>
            <content:encoded><![CDATA[<h3>Pandas — Checking Data</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2TSqiowTzxo-_BOw3hLpSQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@ffstop?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Fotis Fotopoulos</a> on <a href="https://unsplash.com/s/photos/python?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>In pandas every change we made in the data has to be checked. For this there are different functions. Let’s look briefly into them.</p><p>There are different methods that can be used to get the idea of how the data looks like. After reading in the data, it is always good to check that everything went well. For checking any output we can use the <strong>print()</strong> function. The challenge is that large data files might not nicely print on screen using the <strong>print() </strong>function.</p><pre>print(data)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*nYGcGM2PJHcL6rj4iZ9a6w.jpeg" /></figure><p>To display the data more neatly just calling the <strong>data </strong>is enough.</p><pre>data</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*wKIo1ug4Fo4HbyMsfL-rTg.jpeg" /></figure><p>This still includes the entire data, but the columns will be concatenated to show some of the columns in the display. To change this we can set the display option to display the complete columns. Similarly we can do it for rows.</p><pre>pd.set_option(‘display.max_columns’, 112)</pre><ul><li><a href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.head.html"><strong>head()</strong></a></li></ul><p>Compared to previous cases it might be better to look at only the top 5–10 lines of the file rather than loading the entire thing.</p><p>In this we can use <strong>data.head()</strong> to quickly check the contents of the dataframe. This function returns the first n rows for the object based on position. It is useful for quickly testing if your object has the right type of data in it.</p><pre>data.head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*wN3tc8CBuIx-LlC07iJC4g.jpeg" /></figure><ul><li><strong>tail()</strong></li></ul><p>We can also check the last rows of the data using <strong>data.tail(). </strong>It is useful for quickly verifying data, for example, after sorting or appending rows. If n is larger than the number of rows, this function returns all rows.</p><pre>data.tail()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*Jg5f8nDP5cNYdv6E9CpylQ.jpeg" /></figure><ul><li><a href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.shape.html"><strong>shape</strong></a></li></ul><p>This return a tuple representing the rows and columns of the DataFrame. There is no empty parenthesis needed in the case of <strong>shape </strong>because it’s a data attribute, while <strong>head() </strong>was a method attribute.</p><p>The simplest explanation I found is that, a data attribute describes an object whilst a method attribute acts on an object and changes it.</p><pre>data.shape</pre><pre>(264, 112)</pre><ul><li><a href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.info.html"><strong>info()</strong></a></li></ul><p>This method prints information about a DataFrame including the index dtype and columns, non-null values and memory usage.</p><pre>data.info()</pre><pre>&lt;class &#39;pandas.core.frame.DataFrame&#39;&gt;<br>Index: 264 entries, 2001-JAN to 2022-DEC<br>Columns: 112 entries, AOD_1640nm to Elevation(meters)<br>dtypes: float64(38), int64(73), object(1) <br>memory usage: 233.1+ KB</pre><ul><li><strong>size</strong></li></ul><p>This attribute return the number of rows if Series. Otherwise return the number of rows times number of columns if DataFrame.</p><pre>data.size</pre><pre>29568</pre><ul><li><strong>describe()</strong></li></ul><p>This method gives a descriptive statistics including those that summarize the central tendency, dispersion and shape of a dataset’s distribution, excluding NaN values.</p><pre>data.describe()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*wGGPUPdpE49ebvnf1ZV-eg.jpeg" /></figure><p>These are the methods you need to be familiar with for checking the data while analysis.</p><p>For more information, please have a look at the sites linked below.</p><ul><li><a href="https://www.youtube.com/watch?v=N6hyN6BW6ao&amp;list=PL-osiE80TeTsWmV9i9c58mdDCSskIFdDS&amp;index=12">Corey Schafer</a></li><li><a href="https://pandas.pydata.org/docs/reference/frame.html">Pandas documentation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6675796a1f0e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pandas — Read]]></title>
            <link>https://medium.com/@gis-ish/pandas-read-f38a98d9af5?source=rss-e36684b36d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/f38a98d9af5</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[pandas-tutorial]]></category>
            <category><![CDATA[pandas-dataframe]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[csv]]></category>
            <dc:creator><![CDATA[GIS-ish]]></dc:creator>
            <pubDate>Sat, 01 Oct 2022 09:34:51 GMT</pubDate>
            <atom:updated>2022-10-01T13:10:34.589Z</atom:updated>
            <content:encoded><![CDATA[<h3>Pandas — Read</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2TSqiowTzxo-_BOw3hLpSQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@ffstop?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Fotis Fotopoulos</a> on <a href="https://unsplash.com/s/photos/python?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Pandas is an open-source package for data analysis in Python. It is built on the <em>numpy</em> library and written in languages like <em>Python</em>, <em>Cython</em>, and <em>C</em>. Exploring data using pandas is the most basic skill needed for any data analysis using python.</p><p>In pandas, we can import data from various file formats like <em>JSON, SQL, Microsoft Excel,</em> etc. For any data analysis in python pandas is an essential. It is the most downloaded python package. Let’s go through all the necessary methods and functions in panda. I am only going through the uses in a tabulated data.</p><p>Every module need to be imported first.</p><pre>import pandas as pd</pre><p>I am using AERONET level 2 monthly data of Kanpur station downloaded from AERONET site for this practice.</p><p><strong>Reading data</strong></p><p>Data can be provided in many different formats (CSV, TSV, JSON, HTML, SAS, etc.) reading them is the first step to the data analysis.</p><p>To read a comma-separated values(csv) data file, and store the contents of that file into a variable called data we use the pandas.read_csv() function:</p><p><strong>read_csv()</strong> is used to read a csv file into DataFrame, commonly used variables are “df” and “data”. All the arguments to be used in read_csv is explained in detail <a href="https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html"><strong>here</strong></a><strong>.</strong></p><pre>fp = r&#39;data\Kanpur.csv&#39;</pre><pre>data = pd.read_csv(fp,sep=&#39;,&#39;,index_col= &quot;Month&quot;, skiprows=6, na_values=[-999.0,-999])</pre><p><strong>Some common arguments that we need to know for reading files are:</strong></p><ul><li><strong>fp — file path</strong></li></ul><p>If the file to be used is in the same location as the python file then only relative location is needed to be given as the file path(fp), if the csv is in another location pass in the full location to the file path.</p><p>In some cases the location can be called without the ‘‘r(raw strings)’’ in the beginning, but the r present will provide an escape sequence and it will properly read every file path, so it is always safer to put an ‘‘r’’ before the file path.</p><ul><li><strong>sep</strong></li></ul><p>This parameter is used to indicate that we are dealing with a comma-delimited text file. Comma is also the default value for the sep-parameter. Depending on your operating system and the input data, you might need to specify other separators such as ‘‘tab’’ and “;”.</p><ul><li><strong>skiprows</strong></li></ul><p>This is to indicate the line numbers to skip (0-indexed) or number of lines to skip (int) at the start of the file.</p><ul><li><strong>index_col</strong></li></ul><p>Used to set the index value of the data. Column(s) to use as the row labels of the DataFrame, either given as string name or column index. “index_col = False” can be used to force pandas to <em>not</em> use the first column as the index.</p><ul><li><strong>usecols</strong></li></ul><p>This is used when only a subset of the columns is needed for the analysis. Columns are called either by positional (i.e. integer indices into the document columns) or strings that correspond to column names provided either by the user in names or inferred from the document header row(s).</p><ul><li><strong>na_values</strong></li></ul><p>This is used to recognize the common null values or no value available. Identifying the null values before hand helps to make analysis better. If dict passed, specific per-column NA values.</p><p>The output is shown as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/969/1*7b58Go1Gv1yDUydqGIci8Q.jpeg" /></figure><p>In the similar way we can read different formats of data using these I/O methods, look deeper into these methods <a href="https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html"><strong>here</strong></a>.</p><p>For more information, please have a look at the sites linked below.</p><ul><li><a href="https://www.youtube.com/watch?v=N6hyN6BW6ao&amp;list=PL-osiE80TeTsWmV9i9c58mdDCSskIFdDS&amp;index=11">Corey Schafer</a></li><li><a href="https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html">Pandas documentation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f38a98d9af5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An insight into Georeferencer tool — QGIS]]></title>
            <link>https://medium.com/@gis-ish/an-insight-into-georeferencer-tool-qgis-e588e9fbf32a?source=rss-e36684b36d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/e588e9fbf32a</guid>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[qgis]]></category>
            <category><![CDATA[georeferencing]]></category>
            <category><![CDATA[gis]]></category>
            <category><![CDATA[spatial-analysis]]></category>
            <dc:creator><![CDATA[GIS-ish]]></dc:creator>
            <pubDate>Wed, 21 Sep 2022 12:42:06 GMT</pubDate>
            <atom:updated>2022-10-02T06:42:24.276Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>An insight into Georeferencer tool — QGIS</strong></h3><p>For GIS projects any image used must have a coordinate system defined. Only then the image can be used for different spatial analysis techniques. Georeferencing is done to associate any aerial or satellite images to the real world coordinates. Georeferencing may be applied to any kind of object or structure that can be related to a geographical location, such as points of interest, roads, places, bridges, or buildings.</p><p>Qgis is a free and open source cross platform desktop geographic information system (GIS) application that support viewing, editing, printing, and analysis of geospatial data. Georeferencer tool in QGIS is an effortless method to georeference images. This tool was added in Qgis version 3.22 before it, a Georeferencer plugin was required for this procedure.</p><p>Some applications of the Georeferencer tool are:</p><p>· To combine maps with different projection systems.</p><p>· To compare data from images produced at different points in time.</p><p>· To create map using images from different spatial extents.</p><p>· To give context to surveying results using already available topographic maps.</p><p>· To relate a satellite image to its geographic coordinate system.</p><p>Usually georeferencing can be done if the coordinates of Ground Control Points (GCP) are known. Control points are locations that can be accurately identified on the raster dataset and in real-world coordinates. There are two cases in identifying control points.</p><p>In the case 1 the coordinates are obtained by doing field surveys — collecting coordinates with a GPS device for few easily identifiable features in the image or map or the coordinates from the markings on the map image itself. Using these sample coordinates or GCPs, the image is warped and made to fit within the chosen coordinate system.</p><p>In case 2 you may not have the coordinates printed on your map, or you are trying to georeference an image. In that case, you can use another georeferenced data source as your input. In this tutorial we will be discussing the case 1.</p><p>Let’s look into the procedure of georeferencer tool step by step:</p><ol><li>Open QGIS and click on Raster ‣ Georeferencer to open the tool.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*ixytFxyW1zziYBmvUbGSuQ.png" /></figure><p>2. The georeferencer window has two sections. The top section where the image will be displayed and the bottom section where a table showing your GCP values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*lmBv7kmheL6Vd5LMjjD6nA.png" /></figure><p>The icons of the georeferencer tool is described in the table below:</p><p>3. Open the image we need to georeference in the tool. Open File ‣ Open Raster. Browse to the image location and click Open.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*FmCkXTmwSbtp7GG17Gxmyg.png" /></figure><p>4. The image will be loaded on the top section of the window. Now we need to find the GCPs on this map. In the image we can see the coordinate grid with markings. These are Latitude and Longitude grid lines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*zaRzA2TA1vzqVDpQtFfWMg.png" /></figure><p>5. Before adding GCPs the transformation settings for the georeferencing process need to be defined. Open the transformation settings dialog box. Several options need to be defined for the georeferenced output raster.</p><p>In this case we choose transformation type as <strong>Polynomial 2</strong> and the Resampling method as the <strong>Nearest Neighbor</strong>. Click the Select <strong>CRS button</strong> next to Target SRS (Spatial Reference System).</p><p>The polynomial algorithms 2 uses general 2nd degree polynomials. This allows them to account for the curvature or other systematic warping of the image, for instance photographed maps with curved edges. At least 6 GCPs are required in this method.</p><p>The type of resampling you choose will likely depend on your input data and the ultimate objective of the exercise. Nearest Neighbor doesn’t change the statistics of the raster, which is why it is commonly used.</p><p>See <strong>QGIS Documentation</strong> to learn more about different transformation types and resampling method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/1*XPa_YycEXI9dumJ_ON2FNg.png" /></figure><p>6. In the map image, the coordinates are in Latitude/Longitude. We can choose <strong>WGS 84</strong> as an appropriate CRS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*XzvVeok71mRnjU02xPQ5cQ.png" /></figure><p>7. Name your output raster as <strong>maharastra_modified.tif</strong>. Choose <strong>LZW</strong> as the Compression. Check the <strong>Save GCP points</strong> to store the points as separate file for future purpose. And check the <strong>Load in QGIS when done</strong> option. Click OK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*0ojtMo4hwmq478NvqXvjdA.png" /></figure><p>8. Start adding the Ground Control Points by clicking the <strong>Add point</strong> button. Now place the cross-hair at the intersections of the grid lines and left-click, this will serve as the <em>ground-truth </em>in our case. As the grid lines are labeled, we can determine the X and Y coordinates of the points using them. In the pop-up window, enter the coordinates. Remember that X=longitude and Y=latitude. Click OK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*U3jaypcWgoL0Pf0P1Xrl_A.png" /></figure><p>9. The GCP table now has a row with details of your first GCP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*YdGUNMj053kBjW3XWye93A.png" /></figure><p>10. Add more GCPs covering the entire image. The more points you have, the more accurate your image is registered to the target coordinates. As we discussed before the polynomial 2 transformation requires 6 GCPs. Once you have added the minimum number of points required for the transform, you will notice that the GCPs now have a non-zero dX, dY and Residual error values.</p><p>If a particular GCP has unusually high error values that usually signifies a human-error in entering the coordinate values. So you can delete that GCP and capture it again. You can also edit the coordinate values in the GCP Table by clicking the cell in either Dest. X or Dest. Y columns.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*FYAuIOeAVjhuVF5c4jJ90A.png" /></figure><p>11. After the required to GCPs are defined click the <strong>Start Georeferencing</strong> button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*zViahAEhk-YYb5XZ4hF_jg.png" /></figure><p>12. When the georeferencing is completed, the georeferenced layer is loaded in QGIS. Also, you will notice the Project CRS in the bottom right is set to EPSG: 4326 as described in Transformation Settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*QK7mSB3m5IjbN2bL9jBRJw.png" /></figure><p>13. Verify the georeferenced layer by choosing any base map from QuickMapServices plugin. I am choosing OSM Standard as the base map.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*a1wGLdn7-I6dlufL3yiuVA.png" /></figure><p>On the Open layer styling panel icon and select Transparency tab and change the transparency to <strong>70 %</strong>. To improve the visualization of the image go to symbology tab, change the Blending mode to <strong>Darken </strong>and <strong>Gamma</strong> to <strong>0.10.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/1*BPVopymdaLWDmQut7iUE3w.png" /></figure><p>Now the georeferenced image will be overlayed with the base map outline. This was a brief overview of the georeferencer tool in QGIS. Try different cases to become familiar with the tool.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e588e9fbf32a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python- Nested loop]]></title>
            <link>https://medium.com/@gis-ish/python-nested-loop-1bbbd1e010ac?source=rss-e36684b36d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/1bbbd1e010ac</guid>
            <category><![CDATA[nested-loop]]></category>
            <category><![CDATA[technical-writing]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[GIS-ish]]></dc:creator>
            <pubDate>Thu, 15 Sep 2022 09:39:24 GMT</pubDate>
            <atom:updated>2022-09-15T09:39:24.566Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KLKGeOtE1gMzJqv1uhfLRg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@domenicoloia?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Domenico Loia</a> on <a href="https://unsplash.com/s/photos/computer?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>This was one of the reasons to start writing this blog. Forcing myself to learn, the nested loop was one of the extra exercises in my lesson that I gave up on. So let’s try to learn.</p><p>Nested loops can be used to create patterns in python. In this we will make a US flag(which was my exercise for <a href="https://geo-python-site.readthedocs.io/en/latest/index.html">GeoPython</a> course).</p><p>Python programming language allows to use one loop inside another loop. The outer loop can contain more than one inner loop. There is no limitation on the chaining of loops.</p><p>Nested loops are typically used for working with multidimensional data structures, such as printing two-dimensional arrays, and iterating a list that contains a nested list.</p><ul><li><strong>Multiplication table</strong></li></ul><p>To print the multiplication table, we use a nested loop.</p><p>In the outer loop to call the first 5 numbers the range has to start from 1 and end in 6. So total number of iteration of the outer loop is 5.</p><p>In the inner loop is for each iteration of the outer loop, the inner loop will execute it ten times. In each iteration of an inner loop, we calculated the multiplication of two numbers. Thus we get the multiplication table up to 5.</p><p>Here the print function is used with a parameter called <strong>end, </strong>the value of this parameter is ‘\n’, i.e. the new line character. This will print each multiplication table in a single line.</p><pre>for i in range(1, 6):<br>   for j in range(1, 11):<br>      print(i * j, end= &quot; &quot;)<br>   print()</pre><pre>1 2 3 4 5 6 7 8 9 10  <br>2 4 6 8 10 12 14 16 18 20  <br>3 6 9 12 15 18 21 24 27 30  <br>4 8 12 16 20 24 28 32 36 40  <br>5 10 15 20 25 30 35 40 45 50</pre><ul><li><strong>Print pattern</strong></li></ul><p>In this program, the outer loop is the number of rows print.</p><p>Next, the inner loop is the total number of columns in each row.</p><p>For each iteration of the outer loop, the columns count gets incremented by 1.</p><p>In each iteration of an inner loop, for the first 3 rows the condition will vary from the remaining 2 rows.</p><p>The first 3 rows will print<strong> star</strong> up to the 7th column then it will print the line.</p><pre>line = &quot;-&quot;<br>star = &quot;*&quot;<br>flag =&#39;&#39;</pre><pre>for x in range(5):<br>   for i in range(19):<br>      if x &lt; 3:<br>         if i &lt; 7:<br>            flag = flag + star<br>         else:<br>            flag = flag + line<br>      else:<br>            flag = flag + line<br>      flag = flag + &quot;\n&quot;</pre><pre>print(flag)</pre><pre>*******------------ <br>*******------------ <br>*******------------ <br>------------------- <br>-------------------</pre><p>For more information, please have a look at the sites linked below.</p><ul><li><a href="https://www.toppr.com/guides/computer-science/introduction-to-python/conditional-constructs-and-looping/nested-loops/">toppr</a></li><li><a href="https://pynative.com/python-nested-loops/#:~:text=Loop%20in%20Python%3F-,What%20is%20a%20Nested%20Loop%20in%20Python%3F,while%20loop%20and%20vice%20versa.">pynative</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1bbbd1e010ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python — while loop]]></title>
            <link>https://medium.com/@gis-ish/python-while-loop-a22cd2a26ba6?source=rss-e36684b36d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/a22cd2a26ba6</guid>
            <category><![CDATA[while-loop]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[GIS-ish]]></dc:creator>
            <pubDate>Wed, 14 Sep 2022 08:17:24 GMT</pubDate>
            <atom:updated>2022-09-14T08:17:24.747Z</atom:updated>
            <content:encoded><![CDATA[<h3>Python — while loop</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JOoga42iuLkWxj_tKIzYYg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@jstrippa?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">James Harrison</a> on <a href="https://unsplash.com/s/photos/programming?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Another method for looping through a number of sequence is the while loop. The ‘while’ loop executes the set of statements as long as the condition is true. When the condition becomes false the program moves to the next line outside of the loop.</p><p>We generally use this loop when we don’t know the number of times to iterate beforehand.</p><p>Now we are going to count up to 4 and print “ Good bye ! ”</p><pre>count = 0</pre><pre>while (count &lt; 4):</pre><pre>   print(&#39;The count is:&#39;, count)</pre><pre>   count = count + 1</pre><pre>print(&quot;Good bye!&quot;)</pre><pre>The count is: 0 <br>The count is: 1 <br>The count is: 2 <br>The count is: 3 <br>Good bye!</pre><ul><li>while + else</li></ul><p>We can do this with the else statement. The else part is executed if the condition in the while loop evaluates to False.</p><pre>count = 0</pre><pre>while (count &lt; 4):</pre><pre>   print(&#39;The count is:&#39;, count)</pre><pre>   count = count + 1</pre><pre>else:</pre><pre>   print(&#39;Good bye!&#39;)</pre><pre>The count is: 0 <br>The count is: 1 <br>The count is: 2 <br>The count is: 3 <br>Good bye!</pre><p>On the fifth iteration, the condition in while becomes False. Hence, the else part is executed.</p><p>For more information, please have a look at the sites linked below.</p><ul><li><a href="https://www.programiz.com/python-programming/while-loop">programiz</a></li><li><a href="https://realpython.com/python-while-loop/">realpython</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a22cd2a26ba6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python — For loop]]></title>
            <link>https://medium.com/@gis-ish/python-for-loop-85b33290c1de?source=rss-e36684b36d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/85b33290c1de</guid>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[GIS-ish]]></dc:creator>
            <pubDate>Tue, 30 Aug 2022 08:52:42 GMT</pubDate>
            <atom:updated>2022-08-30T08:55:20.570Z</atom:updated>
            <content:encoded><![CDATA[<h3>Python — For loop</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JOoga42iuLkWxj_tKIzYYg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@jstrippa?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">James Harrison</a> on <a href="https://unsplash.com/s/photos/programming?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Using a loop we can perform calculations on each item. Since bulk processing is the main goal of python repeating processes on loops is constantly needed. Now let’s look through the loop.</p><p>The for loop in Python is used to iterate over a sequence (list, tuple, string) or other iterable objects.</p><pre>Cities = [&#39;Bombay&#39;,&#39;Delhi&#39;,&#39;Calcutta&#39;,&#39;Pune&#39;,&#39;Kochi&#39;,&#39;Ahmedabad&#39;]</pre><pre>States = [&#39;Karnataka&#39;, &#39;Delhi&#39;, &#39;West Bengal&#39;,&#39;Maharashtra&#39;,&#39;Kerala&#39;, &#39;Gujarat&#39;]</pre><p>States = [‘Karnataka’, ‘Delhi’, ‘West Bengal’,’Maharashtra’,’Kerala’, ‘Gujarat’]</p><ul><li><strong>Syntax of “for loop”</strong></li></ul><p>- x is the variable used in the syntax, it can be any name or letter you like.</p><p>- The statement of the for loop must end with a :</p><p>- To end any loop just change the indentation to normal</p><pre>for x in Cities:<br>    print(x)</pre><pre>Bombay <br>Delhi <br>Calcutta <br>Pune <br>Kochi <br>Ahmedabad</pre><ul><li><strong>range() function</strong></li></ul><p>To perform an iteration over a sequence of whole numbers we use range() function.</p><p>In simple form range(4) function prints number from 0–3.</p><p>We can also define the start, stop and step size as range(start, stop,step_size). step_size defaults to 1 if not provided.</p><pre>for no in range(4):<br>    print(no)<br>print(&quot;/&quot;)<br>for no in range(1,6,2):<br>    print(no)</pre><pre>0 <br>1 <br>2 <br>3 <br>/ <br>1<br>3 <br>5</pre><ul><li><strong>Iterate over a list using indexing</strong></li></ul><p>range() function can be combined with the len() function to iterate through a sequence using indexing.</p><p>A for loop can have an optional else block as well. The else part is executed if the items in the sequence used in for loop exhausts.</p><pre>for i in range(len(Cities)):<br>    print(f&quot;Metro cities of India: {i+1} - {Cities[i]}&quot;)<br>else:<br>    print(&quot;No items left&quot;)</pre><pre>Metro cities of India: 1 - Bombay <br>Metro cities of India: 2 - Delhi <br>Metro cities of India: 3 - Calcutta <br>Metro cities of India: 4 - Pune <br>Metro cities of India: 5 - Kochi <br>Metro cities of India: 6 - Ahmedabad <br>No items left</pre><p>The body of a loop can contain many statements</p><pre>sum = 0</pre><pre>for i in range(10):<br>    sum = sum+i<br>    mean = sum/len(range(10))<br>    print(f&#39;The sum is {sum}. And mean is {mean}&#39;)</pre><pre>The sum is 45. And mean is 4.5</pre><p><strong>break</strong></p><p>The break keyword can be used to stop a for loop. In such cases, the else part is ignored.</p><pre>for no in range(4):<br>    print(no)<br>    break</pre><pre>0</pre><p>For more information, please have a look at the sites linked below.</p><ul><li><a href="https://geo-python-site.readthedocs.io/en/latest/notebooks/L3/for-loops.html">geo python</a></li><li><a href="http://swcarpentry.github.io/python-novice-gapminder/12-for-loops/index.html">swcarpentry</a></li><li><a href="https://www.programiz.com/python-programming/for-loop">programiz</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85b33290c1de" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>