{"id":6585,"date":"2025-01-10T09:42:32","date_gmt":"2025-01-10T09:42:32","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=6585"},"modified":"2025-01-10T09:42:35","modified_gmt":"2025-01-10T09:42:35","slug":"how-to-iterate-over-rows-in-pandas-dataframe","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/","title":{"rendered":"How to Iterate Over Rows in Pandas DataFrame"},"content":{"rendered":"\n<p>Pandas is a powerful Python library that allows you to easily store and analyze data in a tabular manner, as rows and columns. They are called dataframes, and allow you to easily access, modify, manipulate and filter data. Sometimes, Python developers need to loop through the rows in Pandas dataframe. There are several ways to do this. In this article, we will learn how to iterate over rows in Pandas dataframe.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/#How_to_Iterate_Over_Rows_in_Pandas_DataFrame\" >How to Iterate Over Rows in Pandas DataFrame<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/#1_Using_iterrows\" >1. Using iterrows()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/#2_Using_itertuples\" >2. Using itertuples()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/#3_Using_apply\" >3. Using apply()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/#4_Using_indexes\" >4. Using indexes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/#5_Using_List_Comprehension\" >5. Using List Comprehension<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/#FAQ\" >FAQ<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Iterate_Over_Rows_in_Pandas_DataFrame\"><\/span>How to Iterate Over Rows in Pandas DataFrame<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are the common ways to iterate over dataframe rows. Let us say you have the following pandas dataframe.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import pandas as pd<br>data = {'ID':[1, 2, 3],'Name':['John','Jim', 'Joe'],'Marks':[92,95,94]}<br>df=pd.DataFrame(data)<br>print(df)<\/pre>\n\n\n\n<p>Here is the output you will see.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">   ID  Name  Marks<br>0   1  John     92<br>1   2   Jim     95<br>2   3   Joe     94<\/pre>\n\n\n\n<p>In the above dataframe, we have stored 3 rows, one for each student. Each row has 3 columns of data for ID, Name and Marks.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Using_iterrows\"><\/span>1. Using iterrows()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Let us say you want to calculate the total marks obtained by the 3 students. For this purpose, you will need to iterate over all rows in the table. Each dataframe object supports iterrrows() function that allows you to easily iterate over rows. It returns an iterator to the dataframe, which does not occupy much memory. In each iteration, it returns an index and content object. Here is an example to use iterrows() function to calculate total marks.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">total_marks=0<br><br>for index, row in df.iterrows():<br>    total_marks+=row['Marks']<br>    <br>print(total_marks)  <\/pre>\n\n\n\n<p>In the above code, we first define total_marks variable to store the total sum. Then we create a for loop, that retrieves both index and row content in each iteration. In each iteration, we add the value of marks column to total_marks variable. Lastly, we display the total marks. Please note, you need to extract both index as well as row content in for loop, even if you do not use the index anywhere later. Otherwise, it will give an error. Here is an example to show it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">total_marks=0<br><br><strong>for row in df.iterrows():<\/strong><br>    total_marks+=row['Marks']<br>    <br>print(total_marks) <\/pre>\n\n\n\n<p>Here is the error message.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ERROR!<br>Traceback (most recent call last):<br>  File \"&lt;main.py>\", line 8, in &lt;module><br>TypeError: tuple indices must be integers or slices, not str<\/pre>\n\n\n\n<p>Although iterrows() is easy to use and returns an iterator, it is somehow very slow for large dataframes. It is suitable for small dataframes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Using_itertuples\"><\/span>2. Using itertuples()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>For large dataframes, you can use itertuples() function. It is faster than using iterrows() since it returns a named tuple instead of series content. Named tuples are faster and lightweight than series. Also it returns only the row instead of index and row as in case of iterrows(). It is also available by default for each dataframe. Here is how to use it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">total_marks=0<br><br>for row in df.itertuples():<br>    total_marks+=row.Marks<br>    <br>print(total_marks) <\/pre>\n\n\n\n<p>In the above code, we loop through the result of itertuples(). In each iteration, we add the Marks attribute of the row to total marks. Please note, in this case, we only retrieve the row, instead of index and row in iterrows(). Also, we need to mention the column names as attribute names using dot(.) notation. For example, using row[&#8216;Marks&#8217;] will give an error.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">total_marks=0<br><br>for row in df.itertuples():<br><strong>    total_marks+=row['Marks']<\/strong><br>    <br>print(total_marks) <\/pre>\n\n\n\n<p>Here is the error.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ERROR!<br>Traceback (most recent call last):<br>  File \"&lt;main.py>\", line 8, in &lt;module><br>TypeError: tuple indices must be integers or slices, not str<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Using_apply\"><\/span>3. Using apply()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The apply() function is used to apply a function on every row or column of dataframe. It is vectorized operation and much faster than other looping methods. It is faster than using iterrows or itertuples. It is very useful for performing row-wise or column-wise operations, without explicitly iterating over rows. So it is super useful while working with large datasets. Here is a simple example to add 2 marks to each student&#8217;s marks using apply().<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def add_marks(row):<br>    return row['Marks']+2<br><br># Apply function row-wise<br>result = df.apply(add_marks, axis=1)<br>for res in result:<br>    print(res)<\/pre>\n\n\n\n<p>In the above code, we first define an add_marks() function that accepts a row input and adds 2 marks to the value of its Marks attribute.<\/p>\n\n\n\n<p>Then we call apply() function on our data frame. In that, we pass two arguments &#8211; add_marks function object and axis argument. We set axis argument value to 1, to apply function row-wise. We store the result in a variable and loop through it to display the updated marks. Here is the output.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">94<br>97<br>96<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Using_indexes\"><\/span>4. Using indexes<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can also use index-based iterative functions such as iloc[] or loc[]. iloc[] allows you to access rows using indexes and loc[] allows you to access rows using labels. It is slower than other methods but allows you to precisely access and modify the row you want. Here is a simple example to loop through the rows of dataframe and display each row&#8217;s values.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">for i in range(len(df)):<br>    print(f\"Row {i}: {df.iloc[i]}\")    <\/pre>\n\n\n\n<p>Here is the output.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Row 0: ID          1<br>Name     John<br>Marks      92<br>Name: 0, dtype: object<br>Row 1: ID         2<br>Name     Jim<br>Marks     95<br>Name: 1, dtype: object<br>Row 2: ID         3<br>Name     Joe<br>Marks     94<br>Name: 2, dtype: object<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_Using_List_Comprehension\"><\/span>5. Using List Comprehension<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>List comprehension is one of the fastest ways to iterate over rows of dataframe. It is easy to understand, versatile and faster than most of the other solutions to loop over dataframe items. Here is a simple example to quickly iterate every row in dataframe. In each iteration, we extract the value of Marks column and store it in results list. Lastly, we call sum() function on this list.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">result = [x for x in df['Marks']]<br>print(sum(result))<\/pre>\n\n\n\n<p>Here is the output.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">281<\/pre>\n\n\n\n<p>You can easily modify the above code to iterate over multiple columns and in each iteration, store the column values in a tuple and add it to result list.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">result = [(x,y) for x,y in zip(df['Name'],df['Marks'])]<br>print(result)<\/pre>\n\n\n\n<p>Here is the output.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[('John', 92), ('Jim', 95), ('Joe', 94)]<\/pre>\n\n\n\n<p>In the above code, we use separate loop variables for each column. You can also use a single variable to to fetch the entire row. Here is an example to illustrate it. Here we use column indexes starting from 0, 1, .. to access different column values for each row.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">result = [(row[0],row[1]) for row in zip(df['Name'],df['Marks'])]<br>print(result)<\/pre>\n\n\n\n<p>Here is its result.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[('John', 92), ('Jim', 95), ('Joe', 94)]<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we have learnt several simple ways to easily iterate over rows in pandas dataframe. If you are beginner developer working with small datasets, use iterrows(). If you are working with large dataframes, use itertuples(). If you are reasonably experienced, then you can use apply() function or list comprehensions, both of which are faster than using iterrows() or itertuples(). Also, they are versatile and work well with large dataframes too.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"FAQ\"><\/span>FAQ<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>1. Which is the fastest method to iterate over Pandas dataframe?<\/p>\n\n\n\n<p>Using itertuples() is one of the fastest methods to iterate over Pandas dataframe. They work well even for large dataframes. If vectorization functions are available then they may be even faster in many use cases.<\/p>\n\n\n\n<p>Also read:<\/p>\n\n\n\n<p><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-dictionaries-using-for-loops\/\">How to Iterate Over Dictionaries Using For Loop<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-find-index-of-given-item-in-list-in-python\/\">How to Find Index of Given Item in Python List<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-flatten-list-of-lists-in-python\/\">How to Flatten List of Lists in Python<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you may need to loop through rows in Pandas Dataframe. Here is how to iterate over rows in Pandas dataframe.<\/p>\n","protected":false},"author":1,"featured_media":6614,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[301],"tags":[373],"class_list":["post-6585","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-iterate-rows"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Iterate Over Rows in Pandas DataFrame - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Sometimes you may need to loop through rows in Pandas Dataframe. Here is how to iterate over rows in Pandas dataframe.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Iterate Over Rows in Pandas DataFrame - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Sometimes you may need to loop through rows in Pandas Dataframe. Here is how to iterate over rows in Pandas dataframe.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/\" \/>\n<meta property=\"og:site_name\" content=\"Ubiq BI\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ubiqbi\" \/>\n<meta property=\"article:published_time\" content=\"2025-01-10T09:42:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-10T09:42:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/iterate-over-pandas-dataframe.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"269\" \/>\n\t<meta property=\"og:image:height\" content=\"202\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sreeram Sreenivasan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:site\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sreeram Sreenivasan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-iterate-over-rows-in-pandas-dataframe\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-iterate-over-rows-in-pandas-dataframe\\\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Iterate Over Rows in Pandas DataFrame\",\"datePublished\":\"2025-01-10T09:42:32+00:00\",\"dateModified\":\"2025-01-10T09:42:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-iterate-over-rows-in-pandas-dataframe\\\/\"},\"wordCount\":1000,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-iterate-over-rows-in-pandas-dataframe\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/01\\\/iterate-over-pandas-dataframe.jpg?fit=269%2C202&ssl=1\",\"keywords\":[\"iterate rows\"],\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-iterate-over-rows-in-pandas-dataframe\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-iterate-over-rows-in-pandas-dataframe\\\/\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-iterate-over-rows-in-pandas-dataframe\\\/\",\"name\":\"How to Iterate Over Rows in Pandas DataFrame - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-iterate-over-rows-in-pandas-dataframe\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-iterate-over-rows-in-pandas-dataframe\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/01\\\/iterate-over-pandas-dataframe.jpg?fit=269%2C202&ssl=1\",\"datePublished\":\"2025-01-10T09:42:32+00:00\",\"dateModified\":\"2025-01-10T09:42:35+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Sometimes you may need to loop through rows in Pandas Dataframe. Here is how to iterate over rows in Pandas dataframe.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-iterate-over-rows-in-pandas-dataframe\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-iterate-over-rows-in-pandas-dataframe\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-iterate-over-rows-in-pandas-dataframe\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/01\\\/iterate-over-pandas-dataframe.jpg?fit=269%2C202&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/01\\\/iterate-over-pandas-dataframe.jpg?fit=269%2C202&ssl=1\",\"width\":269,\"height\":202,\"caption\":\"iterate over pandas dataframe\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-iterate-over-rows-in-pandas-dataframe\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Iterate Over Rows in Pandas DataFrame\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\",\"name\":\"Ubiq BI\",\"description\":\"Build dashboards &amp; reports in minutes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\",\"name\":\"Sreeram Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"caption\":\"Sreeram Sreenivasan\"},\"description\":\"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/sreeram-sreenivasan\\\/\"],\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/author\\\/wordpress\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Iterate Over Rows in Pandas DataFrame - Ubiq BI","description":"Sometimes you may need to loop through rows in Pandas Dataframe. Here is how to iterate over rows in Pandas dataframe.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/","og_locale":"en_US","og_type":"article","og_title":"How to Iterate Over Rows in Pandas DataFrame - Ubiq BI","og_description":"Sometimes you may need to loop through rows in Pandas Dataframe. Here is how to iterate over rows in Pandas dataframe.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2025-01-10T09:42:32+00:00","article_modified_time":"2025-01-10T09:42:35+00:00","og_image":[{"width":269,"height":202,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/iterate-over-pandas-dataframe.jpg","type":"image\/jpeg"}],"author":"Sreeram Sreenivasan","twitter_card":"summary_large_image","twitter_creator":"@UbiqBI","twitter_site":"@UbiqBI","twitter_misc":{"Written by":"Sreeram Sreenivasan","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Iterate Over Rows in Pandas DataFrame","datePublished":"2025-01-10T09:42:32+00:00","dateModified":"2025-01-10T09:42:35+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/"},"wordCount":1000,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/iterate-over-pandas-dataframe.jpg?fit=269%2C202&ssl=1","keywords":["iterate rows"],"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/","name":"How to Iterate Over Rows in Pandas DataFrame - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/iterate-over-pandas-dataframe.jpg?fit=269%2C202&ssl=1","datePublished":"2025-01-10T09:42:32+00:00","dateModified":"2025-01-10T09:42:35+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Sometimes you may need to loop through rows in Pandas Dataframe. Here is how to iterate over rows in Pandas dataframe.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/iterate-over-pandas-dataframe.jpg?fit=269%2C202&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/iterate-over-pandas-dataframe.jpg?fit=269%2C202&ssl=1","width":269,"height":202,"caption":"iterate over pandas dataframe"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-iterate-over-rows-in-pandas-dataframe\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Iterate Over Rows in Pandas DataFrame"}]},{"@type":"WebSite","@id":"https:\/\/ubiq.co\/tech-blog\/#website","url":"https:\/\/ubiq.co\/tech-blog\/","name":"Ubiq BI","description":"Build dashboards &amp; reports in minutes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc","name":"Sreeram Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","caption":"Sreeram Sreenivasan"},"description":"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.","sameAs":["https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/"],"url":"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/01\/iterate-over-pandas-dataframe.jpg?fit=269%2C202&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-1Id","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/6585","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/comments?post=6585"}],"version-history":[{"count":28,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/6585\/revisions"}],"predecessor-version":[{"id":6613,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/6585\/revisions\/6613"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/6614"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=6585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=6585"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=6585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}