While working with dataframes, many a times we encounter a need to go through each and every items, one-by-one i.e. iterate over the items. Simplest way is to use a for loop for the purpose.
So this recipe is a short example on how to iterate over a Pandas Series. Let's get started.
import pandas as pd
Let's pause and look at these imports. Pandas is generally used for data manipulation and analysis.
Let us create a simple dataset of grades and with index as the person who scored that grade.
for a,b in df.items(): print('index:',a,'Grade:',b)
Now we will be using a for loop and items function to access each element of our pandas series. Basically, our series for now contains index and grade and hence we use element a and b to access each.
Once we run the above code snippet, we will see:
Scroll down to the ipython notebook below to see the output.