iterrows turns some columns from int64 to float64
See original GitHub issue>>> import pandas as pd
>>> pd.version.version
'0.15.2'
>>> df = pd.DataFrame({u'A': {123.0: 2.0}, u'B': {123.0: 1}})
>>> df
A B
123 2 1
>>> df['B'].dtype
dtype('int64')
>>> type(df.iterrows().next()[1]['B'])
<type 'numpy.float64'>
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to stop Pandas DataFrame from converting int to float for ...
I am trying to figure out what I am doing wrong that makes the columns become floats in the first place. What is...
Read more >pandas.DataFrame.iterrows — pandas 1.5.2 documentation
Iterate over (column name, Series) pairs. Notes. Because iterrows returns a Series for each row, it does not preserve dtypes across the rows...
Read more >How to Convert Integers to Floats in Pandas DataFrame?
Example 1: Converting one column from int to float using DataFrame.astype() ... the data type of column 'Weight' from 'int64' to 'float64'.
Read more >How to iterate over DataFrame rows (and should you?)
It also turns out that question has the most copied answer with a code ... If the DataFrame is large, only some columns...
Read more >Python Pandas String To Integer And ... - Nbshare Notebooks
Ok our studentname column is type 'object' and studentid is int64. Convert Integer To Str Using astype() method of Python Pandas Dataframe.
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
Sorry for reopening, is there a way of iterating over rows and keeping dtype?
Because people do complain about it being slow 😃 And also quite some people use loops for things that are really not necessary, and even more complex to do with a loop (eg adding a number to all elements, I’ve seen this a lot when teaching pandas to beginners). But you’re right, in certain cases, and if you know what you’re doing, nothing wrong with it.