Skip to content

Commit d9dc1cb

Browse files
committed
Merge pull request #3569 from cpcloud/iterrows-doc-3566
DOC: document non-preservation of dtypes across rows with iterrows
2 parents 60e8e51 + fe208a6 commit d9dc1cb

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

doc/source/basics.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,6 @@ containing the data in each row:
835835
...: print '%s\n%s' % (row_index, row)
836836
...:
837837

838-
839838
For instance, a contrived way to transpose the dataframe would be:
840839

841840
.. ipython:: python
@@ -847,6 +846,18 @@ For instance, a contrived way to transpose the dataframe would be:
847846
df2_t = DataFrame(dict((idx,values) for idx, values in df2.iterrows()))
848847
print df2_t
849848
849+
.. note::
850+
851+
``iterrows`` does **not** preserve dtypes across the rows (dtypes are
852+
preserved across columns for DataFrames). For example,
853+
854+
.. ipython:: python
855+
856+
df = DataFrame([[1, 1.0]], columns=['x', 'y'])
857+
row = next(df.iterrows())[1]
858+
print row['x'].dtype
859+
print df['x'].dtype
860+
850861
itertuples
851862
~~~~~~~~~~
852863

pandas/core/frame.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,25 @@ def iteritems(self):
772772

773773
def iterrows(self):
774774
"""
775-
Iterate over rows of DataFrame as (index, Series) pairs
775+
Iterate over rows of DataFrame as (index, Series) pairs.
776+
777+
Notes
778+
-----
779+
780+
* ``iterrows`` does **not** preserve dtypes across the rows (dtypes
781+
are preserved across columns for DataFrames). For example,
782+
783+
>>> df = DataFrame([[1, 1.0]], columns=['x', 'y'])
784+
>>> row = next(df.iterrows())[1]
785+
>>> print row['x'].dtype
786+
float64
787+
>>> print df['x'].dtype
788+
int64
789+
790+
Returns
791+
-------
792+
it : generator
793+
A generator that iterates over the rows of the frame.
776794
"""
777795
columns = self.columns
778796
for k, v in izip(self.index, self.values):

0 commit comments

Comments
 (0)