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 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:closed
  • Created 8 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
iosonofabiocommented, Sep 16, 2015

Sorry for reopening, is there a way of iterating over rows and keeping dtype?

0reactions
jorisvandenbosschecommented, Sep 16, 2015

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.

Read more comments on GitHub >

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

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