Skip to content

DOC: document non-preservation of dtypes across rows with iterrows #3569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion doc/source/basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,6 @@ containing the data in each row:
...: print '%s\n%s' % (row_index, row)
...:


For instance, a contrived way to transpose the dataframe would be:

.. ipython:: python
Expand All @@ -847,6 +846,18 @@ For instance, a contrived way to transpose the dataframe would be:
df2_t = DataFrame(dict((idx,values) for idx, values in df2.iterrows()))
print df2_t

.. note::

``iterrows`` does **not** preserve dtypes across the rows (dtypes are
preserved across columns for DataFrames). For example,

.. ipython:: python

df = DataFrame([[1, 1.0]], columns=['x', 'y'])
row = next(df.iterrows())[1]
print row['x'].dtype
print df['x'].dtype

itertuples
~~~~~~~~~~

Expand Down
20 changes: 19 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,25 @@ def iteritems(self):

def iterrows(self):
"""
Iterate over rows of DataFrame as (index, Series) pairs
Iterate over rows of DataFrame as (index, Series) pairs.

Notes
-----

* ``iterrows`` does **not** preserve dtypes across the rows (dtypes
are preserved across columns for DataFrames). For example,

>>> df = DataFrame([[1, 1.0]], columns=['x', 'y'])
>>> row = next(df.iterrows())[1]
>>> print row['x'].dtype
float64
>>> print df['x'].dtype
int64

Returns
-------
it : generator
A generator that iterates over the rows of the frame.
"""
columns = self.columns
for k, v in izip(self.index, self.values):
Expand Down