Casting full DataFrame.

df = df.astype(str).astype(float)

For single column. IDs is the name of the column.

df["IDs"] = df.IDs.astype(str).astype(float)

Test implementation

from pprint import pprint
import bson
df = pd.DataFrame()
y = []
for i in range(1,6):
    i = i *2/3.5
    y.append(bson.decimal128.Decimal128(str(i)))
pprint(y)
df["D128"] = y
df["D128"] = df.D128.astype(str).astype(float)
print("\n", df)

Output:

[Decimal128('0.5714285714285714'),
 Decimal128('1.1428571428571428'),
 Decimal128('1.7142857142857142'),
 Decimal128('2.2857142857142856'),
 Decimal128('2.857142857142857')]

        D128
0  0.571429
1  1.142857
2  1.714286
3  2.285714
4  2.857143
Answer from Srce Cde on Stack Overflow
🌐
Beepscore
beepscore.com › website › 2018 › 10 › 12 › using-pandas-with-python-decimal.html
Using Pandas with Python Decimal for accurate currency arithmetic
These examples show how to use Decimal type in Python and Pandas to maintain more accuracy than float.Pandas can use Decimal, but requires some care to creat...
🌐
GitHub
github.com › pandas-dev › pandas › issues › 26731
.astype() and Decimal · Issue #26731 · pandas-dev/pandas
June 8, 2019 - Begin from 0.24.0 next code raise exception import decimal import pandas as pd ser = pd.Series([1, 2]) ser.astype(decimal.Decimal) Traceback Traceback (most recent call last): File " ", line ...
Author   shadchin
Discussions

python - pandas read_csv column dtype is set to decimal but converts to string - Stack Overflow
I am using pandas (v0.18.1) to import the following data from a file called 'test.csv': a,b,c,d 1,1,1,1.0 I have set the dtype to 'decimal.Decimal' for columns 'c' and 'd' but instead they return as More on stackoverflow.com
🌐 stackoverflow.com
February 11, 2017
Different precision calling .astype(str) on float numbers
Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more - pandas-dev/pandas More on github.com
🌐 github.com
18
October 12, 2015
python - Set decimal precision of a pandas dataframe column with a datatype of Decimal - Stack Overflow
I have a pandas dataframe with two columns, col 1 with text in it and col 2 with decimal values. Key Value A 1.2089 B 5.6718 B 7.3084 I use the '.apply' function to set the data type of the value c... More on stackoverflow.com
🌐 stackoverflow.com
python - Convert floats to ints in Pandas? - Stack Overflow
I've been working with data imported from a CSV. Pandas changed some columns to float, so now the numbers in these columns get displayed as floating points! However, I need them to be displayed as More on stackoverflow.com
🌐 stackoverflow.com
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.to_numeric.html
pandas.to_numeric — pandas 3.0.2 documentation - PyData |
DataFrame.astype · Cast argument to a specified dtype. to_datetime · Convert argument to datetime. to_timedelta · Convert argument to timedelta. numpy.ndarray.astype · Cast a numpy array to a specified type. DataFrame.convert_dtypes · Convert dtypes. Examples · Take separate series and convert to numeric, coercing when told to ·
🌐
Saturn Cloud
saturncloud.io › blog › how-to-set-decimal-precision-of-a-pandas-dataframe-column-with-decimal-datatype
How to Set Decimal Precision of a Pandas Dataframe Column with Decimal Datatype | Saturn Cloud Blog
January 4, 2024 - To set the decimal precision of a Pandas dataframe column with a Decimal datatype, you can use the round() method. The round() method rounds the Decimal object to the specified number of decimal places and returns a new Decimal object.
🌐
GitHub
github.com › pandas-dev › pandas › issues › 11302
Different precision calling .astype(str) on float numbers
October 12, 2015 - import pandas as pd pd.DataFrame([1.12345678901234567890]).astype(str) 0 0 1.12345678901 · With pandas 0.17: import pandas as pd pd.DataFrame([1.12345678901234567890]).astype(str) 0 0 1.1234567890123457 · I read the 0.17 release log but couldn't figure out why that is.
Author   marcomayer
🌐
Note.nkmk.me
note.nkmk.me › home › python › pandas
pandas: Round, floor, and ceil for DataFrame and Series | note.nkmk.me
January 15, 2024 - The default is decimals=0, rounding to zero decimal places, but the data type remains float. To convert to an integer (int), use the astype() method. pandas: How to use astype() to cast dtype of DataFrame
Find elsewhere
🌐
Anaconda
engineering.anaconda.com › home › blog › decimals type for pandas
Decimals type for pandas - Anaconda Engineering Blog
September 10, 2025 - Some time ago I had a go at implementing a “decimals” extension type for pandas. This was following stumbling upon parquet data of that type, which pandas could not read: pyarrow would error and fastparquet would convert to floats. The decimal type, with known, fixed precision, is very important in real-world applications such as finance, where exact equality of fractional values is required.
🌐
Pandasdataframe
pandasdataframe.com › pandas-astype-decimal.html
Pandas astype decimal-Pandas Dataframe
Pandas is a powerful Python library used for data manipulation and analysis. One of its core functionalities is the ability to change the data type of series within a DataFrame. This is particularly useful when dealing with numerical data that requires high precision, such as financial data. In this article, we will explore how to use the astype method to convert data types to decimal.Decimal, which can offer more precision than floating-point representation.
🌐
Lightrun
lightrun.com › answers › pandas-dev-pandas-astype-and-decimal
.astype() and Decimal
Source code: Lib/decimal.py The decimal module provides support for fast correctly rounded decimal floating point arithmetic. It offers several advantages ...Read more > ... Use pandas DataFrame.astype() function to convert column to int (integer), ...
🌐
Medium
medium.com › @heyamit10 › understanding-pandas-astype-with-examples-f1b21ad17e69
Understanding pandas astype() with Examples | by Hey Amit | Medium
March 6, 2025 - This is where astype() truly shines because data isn’t always clean, tidy, or in the format you expect. You’ll often need to tweak it, and that’s exactly what we’ll do here. ... Imagine you’ve got a DataFrame with mixed data types — some numbers stored as integers, others as strings. Instead of converting each column one by one (which is tedious), you can handle them all at once using a dictionary. ... import pandas as pd # Sample DataFrame with mixed data types data = {'A': [1, 2, 3], 'B': ['4', '5', '6']} df = pd.DataFrame(data) # Convert column A to float and B to integer df = df.astype({'A': 'float', 'B': 'int'}) # Check the new data types print(df.dtypes)
🌐
GitHub
github.com › pandas-dev › pandas › issues › 21551
to_numeric not correctly converting decimal type to float · Issue #21551 · pandas-dev/pandas
June 20, 2018 - Code Sample, a copy-pastable example if possible import pandas as pd import decimal # Set up date data = {'line': [1,2,3,4], 'decimal': [12345678.1, 12345678.01, 12345678.001, 12345678.0001], 'original': [12345678.1, 12345678.01, 1234567...
Author   MikeWoodward
🌐
Reddit
reddit.com › r/learnpython › is it possible to get a more specific dtype from pandas? decimal shows up as object, but will still throw errors specific to the decimal type.
r/learnpython on Reddit: Is it possible to get a more specific dtype from pandas? Decimal shows up as object, but will still throw errors specific to the Decimal type.
January 17, 2023 -

For some reason, some of the columns are being loaded as a Decimal rather than as a float - not my team, apparently can't be changed.

Is there a way to identify which columns are Decimal? df[col].dtype just returns "O" which makes it impossible to distinguish from objects using this method.

🌐
Code-examples
code-examples.net › en › q › 4c0812d › pandas-astype-float-for-decimal-columns-handling-object-dtypes
python - Pandas astype(float) for Decimal Columns: Handling Object Dtypes
# For a pure Decimal column, astype(float) is simpler. You've got a table with time intervals, each defined by a 'from' and 'to' timestamp. The goal is to see if these periods are continuous python dataframe pandas