pandas 1.4.2

NotesYieldsBackRef
iterrows(self) -> 'Iterable[tuple[Hashable, Series]]'

Notes

  1. Because iterrows returns a Series for each row, it does not preserve dtypes across the rows (dtypes are preserved across columns for DataFrames). For example,

    >>> df = pd.DataFrame([[1, 1.5]], columns=['int', 'float'])
    >>> row = next(df.iterrows())[1]
    >>> row
    int      1.0
    float    1.5
    Name: 0, dtype: float64
    >>> print(row['int'].dtype)
    float64
    >>> print(df['int'].dtype)
    int64

    To preserve dtypes while iterating over the rows, it is better to use itertuples which returns namedtuples of the values and which is generally faster than iterrows .

  2. You should never modify something you are iterating over. This is not guaranteed to work in all cases. Depending on the data types, the iterator returns a copy and not a view, and writing to it will have no effect.

Iterate over DataFrame rows as (index, Series) pairs.

Yields

index : label or tuple of label

The index of the row. A tuple for a MultiIndex .

data : Series

The data of the row as a Series.

See Also

DataFrame.items

Iterate over (column name, Series) pairs.

DataFrame.itertuples

Iterate over DataFrame rows as namedtuples of the values.

Examples

See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.frame.DataFrame.iteritems pandas.core.frame.DataFrame.items pandas.core.series.Series.items pandas.core.frame.DataFrame.itertuples pandas.core.series.Series.iteritems

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/frame.py#1279
type: <class 'function'>
Commit: