Python Pandas - Return the int position of the largest value in the Index

PythonPandasServer Side ProgrammingProgramming

<p>To return the int position of the largest value in the Index, use the <strong>index.argmax()</strong> method.</p><p>At first, import the required libraries &minus;</p><pre class="just-code notranslate language-python3" data-lang="python3">import pandas as pd</pre><p>Creating the index &minus;</p><pre class="just-code notranslate language-python3" data-lang="python3">index = pd.Index([15, 25, 55, 10, 100, 70, 35, 40, 55]) </pre><p>Display the index &minus;</p><pre class="just-code notranslate language-python3" data-lang="python3">print(&quot;Pandas Index... &quot;,index)</pre><p>Get the int position of the largest value in the Index &minus;</p><pre class="just-code notranslate language-python3" data-lang="python3">print(&quot; Get the int position of the largest value in the Index... &quot;,index.argmax()) </pre><h2>Example</h2><p>Following is the code &minus;</p><pre class="demo-code notranslate language-python3" data-lang="python3">import pandas as pd # Creating the index index = pd.Index([15, 25, 55, 10, 100, 70, 35, 40, 55]) # Display the index print(&quot;Pandas Index... &quot;,index) # Return a tuple of the shape of the underlying data print(&quot; A tuple of the shape of underlying data... &quot;,index.shape) # Return the number of elements in the Index print(&quot; Number of elements in the index... &quot;,index.size) # The int position of the largest value in the Index print(&quot; Get the int position of the largest value in the Index... &quot;,index.argmax()) </pre><h2>Output</h2><p>This will produce the following code &minus;</p><pre class="result notranslate">Pandas Index... Int64Index([15, 25, 55, 10, 100, 70, 35, 40, 55], dtype=&#39;int64&#39;) A tuple of the shape of underlying data... (9,) Number of elements in the index... 9 Get the int position of the largest value in the Index... 4</pre>
raja
Updated on 13-Oct-2021 11:28:05

Advertisements