To modify the float output do this:

df= pd.DataFrame(range(5), columns=['a'])
df.a = df.a.astype(float)
df

Out[33]:

          a
0 0.0000000
1 1.0000000
2 2.0000000
3 3.0000000
4 4.0000000

pd.options.display.float_format = '{:,.0f}'.format
df

Out[35]:

   a
0  0
1  1
2  2
3  3
4  4
Answer from EdChum on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ convert-floats-to-integers-in-a-pandas-dataframe
Convert Floats to Integers in a Pandas DataFrame - GeeksforGeeks
July 15, 2025 - In this example, the code begins by importing the NumPy module as 'np.' It then displays the data types of DataFrame 'df.' After that, it converts the 'Field_2' column from float to int using NumPy's int64 data type and displays the updated data types.
Discussions

Pandas. Convert float to integer only if it is a round number.
I can't promise this is the best answer, but could be worth considering anyway. I would convert the data to strings: >>> stringify = lambda i: f'{i}' if i % 1 else f'{i:.0f}' >>> df.cost = df.cost.apply(stringify, axis=1) Then write to a file. This will ensure the data is written to a file in the format you want it. Proof: >>> cost = [1.5, 1.0, 2.6, 4.0] >>> list(map(stringify, cost)) ['1.5', '1', '2.6', '4'] However, note that if you subsequently open it in a "smart" viewer like Excel that tries to auto-detect data types, there's no guarantee it will remain in that format. More on reddit.com
๐ŸŒ r/learnpython
7
1
April 12, 2021
python - pandas rounding when converting float to integer - Stack Overflow
I've got a pandas DataFrame with a float (on decimal) index which I use to look up values (similar to a dictionary). As floats are not exactly the value they are supposed to be multiplied everythin... More on stackoverflow.com
๐ŸŒ stackoverflow.com
What are possible causes of pandas converting an INT to Float?
If a datatype is not defined, pandas tries to infer the datatype. When pulling data from .csv or excel files, I think numeric values are almost always assumed to be floating point. My understanding is, when operating on two numeric values of different types, the output is the highest precision data type. So for example, when operating on a float and an integer, floats are higher precision and thus the output is a float and not an int. Likely what is happening in your code is you are importing from some other source that does not explicitly define the datatypes and they are being inferred as floating point values. This precision is cascaded through as the highest precision datatype. When you instantiate a dataframe, you can pass in a dtype keyword to indicate the datatypes of each column. Additionally, you can use the astype method to change it after the fact. For example: a = pd.DataFrame({'float': [1.,2.,3.,4.,5.], 'integer': [1,2,3,4,5]}) print(a) float integer 0 1.0 1 1 2.0 2 2 3.0 3 3 4.0 4 4 5.0 5 a['float'] = a['float'].astype(int) a['integer'] = a['integer'].astype(float) print(a) float integer 0 1 1.0 1 2 2.0 2 3 3.0 3 4 4.0 4 5 5.0 a = a.astype(int) print(a) float integer 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 a = a.astype(float) print(a) float integer 0 1.0 1.0 1 2.0 2.0 2 3.0 3.0 3 4.0 4.0 4 5.0 5.0 More on reddit.com
๐ŸŒ r/learnpython
4
1
March 30, 2021
Pandas - convert float value to minutes and seconds in CSV
look into using the apply method on a series. you can define a function to do this across the Series https://pandas.pydata.org/docs/reference/api/pandas.Series.apply.html More on reddit.com
๐ŸŒ r/learnpython
11
3
December 26, 2021
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ pandas โ€บ pandas convert float to integer in dataframe
Pandas Convert Float to Integer in DataFrame - Spark By {Examples}
November 22, 2024 - Use pandas DataFrame.astype() function to convert float to int (integer), you can apply this on a specific column. Below example converts Fee column to int32 from float64.
๐ŸŒ
Medium
medium.com โ€บ @amit25173 โ€บ pandas-float-to-int-a-practical-guide-a288ab2fe3d9
Pandas Float to Int: A Practical Guide | by Amit Yadav | Medium
March 6, 2025 - This might surprise you: You can shrink memory usage significantly just by converting int64 to a smaller integer type! Letโ€™s see this in action. ... Letโ€™s start by creating a large dataset and checking its memory usage. ... import pandas as pd import numpy as np # Creating a large DataFrame with float values df = pd.DataFrame({'A': np.random.uniform(1, 100, 1_000_000)}) # 1 Million rows # Checking initial memory usage print("Memory usage before conversion:") print(df.memory_usage(deep=True))
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ pandas. convert float to integer only if it is a round number.
r/learnpython on Reddit: Pandas. Convert float to integer only if it is a round number.
April 12, 2021 -

I have been trying to automate a task which i've been doing in Excel but have come up against a little stumbling block that I'm not sure of the best solution to resolve.

I have a dataframe, with a number of columns where the values are all floats. When processing the sheet in Excel to xml, all of the float values get exported as whole numbers, but the Pandas export currently has them as floats with a trailing decimal.

So for example I may have a df column:

sample = {"cost":[1.5, 1.0, 2.6, 4.0}

and I want this to output as

cost
1.5
1
2.6
4

i.e not having 1.0 and 4.0.

I tried,

df["cost"] = df["cost"].apply(lambda x: int(x) if x % 1 == 0 else x)

but this still just output float values. As a test, I tried changing the else conditional to a string

df["cost"] = df["cost"].apply(lambda x: int(x) if x % 1 == 0 else "test")

This correctly updated the round numbers to the desired integer, and converted the floats to "test". so I am not sure why my original solution doesn't work. I also tried else float(x) but this left every result as a float.

Is a lambda solution the best way to go about updating this, or would Pandas have something more suitable built in?

What am I doing wrong in the way I have tried this?

Any help greatly appreciated!

๐ŸŒ
Saturn Cloud
saturncloud.io โ€บ blog โ€บ how-to-read-rows-and-convert-float-to-integer-in-pandas
How to Read Rows and Convert Float to Integer in Pandas | Saturn Cloud Blog
December 6, 2023 - In this article, we will explore how to read rows and convert float to integer in Pandas, a popular data manipulation library in Python.
๐ŸŒ
Statology
statology.org โ€บ home โ€บ how to convert floats to integers in pandas
How to Convert Floats to Integers in Pandas
June 1, 2022 - The following code shows how to convert multiple columns in a DataFrame from a float to an integer: import pandas as pd #create DataFrame df = pd.DataFrame({'player': ['A', 'B', 'C', 'D', 'E'], 'points': [25.2, 27.0, 14.5, 17.6, 20.7], 'assists': [5.1, 7.7, 10.3, 8.6, 9.5]}) #convert 'points' and 'assists' columns to integer df[['points', 'assists']] = df[['points', 'assists']].astype(int) #view data types for each column df.dtypes player object points int32 assists int32 dtype: object
Find elsewhere
๐ŸŒ
Pandas
pandas.pydata.org โ€บ docs โ€บ reference โ€บ api โ€บ pandas.to_numeric.html
pandas.to_numeric โ€” pandas 3.0.1 documentation - PyData |
>>> s = pd.Series(["1.0", "2", -3]) >>> pd.to_numeric(s) 0 1.0 1 2.0 2 -3.0 dtype: float64 >>> pd.to_numeric(s, downcast="float") 0 1.0 1 2.0 2 -3.0 dtype: float32 >>> pd.to_numeric(s, downcast="signed") 0 1 1 2 2 -3 dtype: int8 >>> s = pd.Series(["apple", "1.0", "2", -3]) >>> pd.to_numeric(s, errors="coerce") 0 NaN 1 1.0 2 2.0 3 -3.0 dtype: float64 ยท Downcasting of nullable integer and floating dtypes is supported:
๐ŸŒ
Python Guides
pythonguides.com โ€บ convert-floats-to-integer-in-pandas
How To Convert Float To Int In Pandas
May 26, 2025 - Let me show you how to convert a float to an int in Python Pandas. The simplest way to convert float values to integers in Pandas is to use the astype() method in Python.
๐ŸŒ
Appdividend
appdividend.com โ€บ converting-floats-to-integers-in-a-pandas-dataframe
How to Convert Floats to Integers in a Pandas DataFrame
September 7, 2025 - In this code, we first replaced the NaN value with 0 (here, you can choose whichever value you want based on your requirements) and then converted the column into an integer. Sometimes, if your floating-point numbers are very large, using the standard int type might lead to overflow errors or unexpected results. You can use the np.int64 type to prevent any unexpected error. import pandas as pd import numpy as np df = pd.DataFrame({'float_col': [2**31 - 0.5, 2**32 + 0.5]}) df['int_col_good'] = df['float_col'].astype(np.int64) print(df['int_col_good'].dtype) # int64
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ python pandas โ€บ how to convert float to int in pandas dataframe
How to Convert a Float to an Integer in Pandas DataFrame | Delft Stack
February 2, 2024 - This tutorial demonstrates how to convert a float to an integer in a Pandas DataFrame by using astype(int) and to_numeric() methods.
๐ŸŒ
W3docs
w3docs.com โ€บ python
Convert floats to ints in Pandas?
import pandas as pd df = pd.DataFrame({'col': [1.5, 2.6, 3.7, 4.8]}) print(df) # Output: # col # 0 1.5 # 1 2.6 # 2 3.7 # 3 4.8 ... Note that when converting float values to integers, the decimal part of the float will be truncated (not rounded).
๐ŸŒ
Finxter
blog.finxter.com โ€บ 5-best-ways-to-convert-float-to-integer-in-a-pandas-dataframe
5 Best Ways to Convert Float to Integer in a Pandas DataFrame โ€“ Be on the Right Side of Change
It can be used to transform float columns into integers, effectively truncating the decimal part and keeping only the whole number. ... import pandas as pd # Create a DataFrame with float values df = pd.DataFrame({'float_column': [1.2, 2.5, 3.8]}) # Convert the float column to integers df['float_column'] = df['float_column'].astype(int) print(df)
๐ŸŒ
w3resource
w3resource.com โ€บ python-exercises โ€บ pandas โ€บ python-pandas-data-frame-exercise-51.php
Pandas: Convert the datatype of a given column(floats to ints) - w3resource
September 6, 2025 - import pandas as pd import numpy as np exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael', 'Matthew', 'Laura', 'Kevin', 'Jonas'], 'score': [12.5, 9.1, 16.5, 12.77, 9.21, 20.22, 14.5, 11.34, 8.8, 19.13], 'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1], 'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']} df = pd.DataFrame(exam_data) print("Original DataFrame:") print(df) print("\nData types of the columns of the said DataFrame:") print(df.dtypes) print("\nNow change the Data type of 'score' column from float to int:") df.score = df.score.astype(int) print(df) print("\nData types of the columns of the DataFrame now:") print(df.dtypes)
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ pandas โ€บ pandas convert column to int in dataframe
Pandas Convert Column to Int in DataFrame - Spark By {Examples}
June 26, 2025 - You can also use DataFrame.apply() method to convert Fee column from string to integer in pandas. As you see in this example we are using numpy.int64. Before going to use numpy functions we need to import numpy module. import numpy as np # Convert "Fee" from float to int # Using DataFrame.apply(np.int64) df["Fee"] = df["Fee"].apply(np.int64) print(df.dtypes)
๐ŸŒ
Pandas
pandas.pydata.org โ€บ docs โ€บ reference โ€บ api โ€บ pandas.DataFrame.convert_dtypes.html
pandas.DataFrame.convert_dtypes โ€” pandas 3.0.1 documentation
By default, convert_dtypes will attempt to convert a Series (or each Series in a DataFrame) to dtypes that support pd.NA. By using the options convert_string, convert_integer, convert_boolean and convert_floating, it is possible to turn off individual conversions to StringDtype, the integer extension types, BooleanDtype or floating extension types, respectively.
๐ŸŒ
sqlpey
sqlpey.com โ€บ python โ€บ top-10-methods-to-convert-floats-to-ints-in-pandas
Top 10 Methods to Convert Floats to Ints in Pandas - sqlpey
December 5, 2024 - import pandas as pd import numpy as np ## Creating a random DataFrame with floats df = pd.DataFrame(np.random.rand(3, 4), columns=list("ABCD")) print("Original DataFrame:\n", df) ## Convert all columns to integers df[list("ABCD")] = df[list("ABCD")].astype(int) print("Converted DataFrame:\n", df)
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ what are possible causes of pandas converting an int to float?
r/learnpython on Reddit: What are possible causes of pandas converting an INT to Float?
March 30, 2021 -

I don't use float at all in my program and randomly I'm getting an (easy to fix) bug that an input requires Int and float was provided. Here is some recent code, but this isnt the first time something like this happened. I'm looking for a general reasoning rather than this particular reasoning.

        x=df.loc[((df['FROM2'] > 599) & (df['FROM2'] < 700) & (df['y']==True))]
        z=pd.concat([z, x])

then later in the code...

    a= pd.merge(a, z, how = 'outer', indicator = True)
    a= a.loc[a['_merge'] == 'left_only'].copy()
    a.drop(columns = '_merge', inplace = True)