Iterate DataFrame in Python

Posted on Updated on

In recent time, data analytics is the most demanding area in IT. Panda is a library which is commonly used for analytic using Python programming language. In Panda, Series and DataFrame are the data structures that we commonly use and because of these data structures, Panda is so popular. In this article, we will be discussing different ways to iterate DataFrame.

1) Iterate DataFrame row by row using iterrows()

iterrows() method returns a Series for each row along with index. The iterator returns a copy and not a view and writing to it will have no effect. So, one shouldn’t modify while iterating the DataFrame using iterrow(). Below are the examples to demonstrate how to iterate DataFrame using iterrow() method.

Output

2) Iterate DataFrame row by row using itertuples()

Iterate over DataFrame rows as namedtuples, with index values as first element of the tuple. Below example demonstrate iteration of DataFrame using itertuples().

Output

Stay tuned for more updates and tutorials !!!

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.