File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -835,7 +835,6 @@ containing the data in each row:
835
835
...: print '%s\n %s' % (row_index, row)
836
836
...:
837
837
838
-
839
838
For instance, a contrived way to transpose the dataframe would be:
840
839
841
840
.. ipython :: python
@@ -847,6 +846,18 @@ For instance, a contrived way to transpose the dataframe would be:
847
846
df2_t = DataFrame(dict ((idx,values) for idx, values in df2.iterrows()))
848
847
print df2_t
849
848
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
+
850
861
itertuples
851
862
~~~~~~~~~~
852
863
Original file line number Diff line number Diff line change @@ -772,7 +772,25 @@ def iteritems(self):
772
772
773
773
def iterrows (self ):
774
774
"""
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.
776
794
"""
777
795
columns = self .columns
778
796
for k , v in izip (self .index , self .values ):
You can’t perform that action at this time.
0 commit comments