Pandas Tutorial Pandas References

Pandas Series - iteritems() function



The Pandas Series iteritems() function is used to iterate over the (index, value) tuples of a series, returning an iterable tuple (index, value).

Syntax

Series.iteritems()

Parameters

No parameter is required.

Return Value

Returns an iterable of tuples containing the (index, value) pairs from a Series.

Example: iteritems() example

The example below demonstrates the usage of iteritems() function.

import pandas as pd
import numpy as np

x = pd.Series([10, 20, 30, 5, 7, 9])

print("The Series contains:")
print(x,"\n")

for index, value in x.iteritems():
    print(f"Index : {index}, Value : {value}")

The output of the above code will be:

The Series contains:
0    10
1    20
2    30
3     5
4     7
5     9
dtype: int64 

Index : 0, Value : 10
Index : 1, Value : 20
Index : 2, Value : 30
Index : 3, Value : 5
Index : 4, Value : 7
Index : 5, Value : 9

❮ Pandas Series - Functions