w3resource

Pandas Series: items() function

Lazily iterate over tuples in Pandas

The items() function is used to lazily iterate over (index, value) tuples.

This method returns an iterable tuple (index, value). This is convenient if you want to create a lazy iterator.

Syntax:

Series.items(self)

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

Example :

Python-Pandas Code:

import numpy as np
import pandas as pd
s = pd.Series(['P', 'Q', 'R'])
for index, value in s.items():
    print("Index : {}, Value : {}".format(index, value))

Output:

Index : 0, Value : P
Index : 1, Value : Q
Index : 2, Value : R

Previous: Access a group of rows and columns in Pandas
Next: Get item and drop from frame



Follow us on Facebook and Twitter for latest update.