question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

iterrows changes dtype of columns

See original GitHub issue
In [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:closed
  • Created 10 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
jrebackcommented, May 10, 2013

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

0reactions
jrebackcommented, May 11, 2013

closed by #3569

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found