iterrows changes dtype of columns
See original GitHub issueIn [105]: df = pd.DataFrame([[1, 1.0]], columns=['x', 'y'])
In [112]: row = next(df.iterrows())[1]
In [113]: row
Out[113]:
x 1
y 1
Name: 0, dtype: float64
In [114]: row['x'].dtype
Out[114]: dtype('float64')
In [115]: df['x'].dtype
Out[115]: dtype('int64')
Issue Analytics
- State:
- Created 10 years ago
- Comments:10 (9 by maintainers)
Top Results From Across the Web
Pandas iterrows change the type of columns to float. How to ...
Any idea of a pythonic and elegant way of casting it back to the original type? Note that I have multiple column types....
Read more >pandas.DataFrame.iterrows — pandas 1.5.2 documentation
Because iterrows returns a Series for each row, it does not preserve dtypes across the rows (dtypes are preserved across columns for DataFrames)....
Read more >[Solved]-Pandas iterrows change the type of columns to float ...
Coding example for the question Pandas iterrows change the type of columns to float. How to cast it back to original type?-Pandas,Python.
Read more >How to iterate over rows in Pandas: Most efficient options
iterrows () returns a row index as well as the row itself. Additionally, to improve readability, if you don't care about the index...
Read more >Pandas Iterate Over Columns of DataFrame
Like any other data structure, Pandas DataFrame also has a way to iterate (loop through) over columns and access elements of each column....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
this is by definition correct, dtypes are maintained only in the columns
the dtype is the lowest common denomincator of the row dtypes, which in this case is float
closed by #3569