What you see is just the default string representation with 6 decimal places. You can set you own display format option with

pd.options.display.float_format = '{:.10f}'.format

to show 10 places. Alternatively you can confirm the number if you look at the result of say df.loc[1,'lng'].

To set the option only temporarily you can use an option context:

with pd.option_context('display.float_format', '{:.10f}'.format):
    print(df)
Answer from Stef on Stack Overflow
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-convert-string-to-float
How to Convert String to Float in Python: Complete Guide with Examples | DigitalOcean
July 10, 2025 - Learn how to convert strings to floats in Python using float(). Includes syntax, examples, error handling tips, and real-world use cases for data parsing.
Discussions

python - Converting strings to floats in a DataFrame - Stack Overflow
How to covert a DataFrame column containing strings and NaN values to floats. And there is another column whose values are strings and floats; how to convert this entire column to floats. More on stackoverflow.com
๐ŸŒ stackoverflow.com
How I convert float to string in this case?
You shouldn't call your variable sum, as that's a name of a built in function: https://docs.python.org/3/library/functions.html#sum Your problem however, stems from trying to add a string to a float. Could you please tell me, what is Adam + 5? Well, you can't, because it makes no mathematical sense. You didn't save the string representation str(sum), so sum never changed to a string What your research found is f-strings and they are very easy to use. Try: print(f"the sum of the values is {sum}") Simply, put an f before a string starts, then any string that you want goes between " and ", while any variables or other values go between { and } More on reddit.com
๐ŸŒ r/learnpython
4
2
August 21, 2022
pandas - How to convert datatype:object to float64 in python? - Stack Overflow
I am going around in circles and tried so many different ways so I guess my core understanding is wrong. I would be grateful for help in understanding my encoding/decoding issues. I import the dat... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - Convert a string list to float32 efficiently - Stack Overflow
I have a 3000x300 matrix file (float). when I read and convert to float, I am getting float64, which is default in python. I tried numpy and map() to convert it to float32() but they both seem very More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
IONOS
ionos.com โ€บ digital guide โ€บ websites โ€บ web development โ€บ converting python strings to floats
How to convert Python strings to floats - IONOS
January 2, 2025 - You can then use NumPy to apply the function numpy.float64() to the string string_value to convert it into a 64-bit floating number. If, on the other hand, you want to convert a float into a string, you can use the str() function.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ convert-string-to-float-in-python
Convert String to Float in Python - GeeksforGeeks
April 26, 2025 - It converts a string into a Decimal object, effectively avoiding common floating-point rounding errors. ... eval() function reads and runs a string as a Python expression. It can turn a numeric string like "33.28" into a float. However, it's risky to use with untrusted input because it can run harmful code.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ how i convert float to string in this case?
r/learnpython on Reddit: How I convert float to string in this case?
August 21, 2022 -

I tried

n1=input('First number')
n2=input('Second number')
sum = float(n1) + float(n2)
str(sum)
print('The sum of the values is: ' + sum)

My error is:

TypeError: can only concatenate str (not "float") to str

I tried googling this error and got some answers like print(f' which I didn't really understand, and some others that looked a little complicated, I am very new.

I am trying to improve my googling skills.

Find elsewhere
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ pandas โ€บ pandas convert column to float in dataframe
Pandas Convert Column to Float in DataFrame - Spark By {Examples}
October 14, 2024 - You can use the Pandas DataFrame.astype() function to convert a column from string/int to float, you can apply this on a specific column or on an entire DataFrame. To cast the data type to a 54-bit signed float, you can use numpy.float64, ...
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ python string to float, float to string
Python String to float, float to String - AskPython
February 16, 2023 - Python provides us with the built-in float() method to convert the data type of input from String to float.
Top answer
1 of 7
49

You can convert most of the columns by just calling convert_objects:

In [36]:

df = df.convert_objects(convert_numeric=True)
df.dtypes
Out[36]:
Date         object
WD            int64
Manpower    float64
2nd          object
CTR          object
2ndU        float64
T1            int64
T2          int64
T3           int64
T4        float64
dtype: object

For column '2nd' and 'CTR' we can call the vectorised str methods to replace the thousands separator and remove the '%' sign and then astype to convert:

In [39]:

df['2nd'] = df['2nd'].str.replace(',','').astype(int)
df['CTR'] = df['CTR'].str.replace('%','').astype(np.float64)
df.dtypes
Out[39]:
Date         object
WD            int64
Manpower    float64
2nd           int32
CTR         float64
2ndU        float64
T1            int64
T2            int64
T3            int64
T4           object
dtype: object
In [40]:

df.head()
Out[40]:
        Date  WD  Manpower   2nd   CTR  2ndU   T1  ใ€€ใ€€T2   T3     T4
0   2013/4/6   6       NaN  2645  5.27  0.29  407   533  454    368
1   2013/4/7   7       NaN  2118  5.89  0.31  257   659  583    369
2  2013/4/13   6       NaN  2470  5.38  0.29  354   531  473  ใ€€ใ€€383
3  2013/4/14   7       NaN  2033  6.77  0.37  396   748  681    458
4  2013/4/20   6       NaN  2690  5.38  0.29  361   528  541    381

Or you can do the string handling operations above without the call to astype and then call convert_objects to convert everything in one go.

UPDATE

Since version 0.17.0 convert_objects is deprecated and there isn't a top-level function to do this so you need to do:

df.apply(lambda col:pd.to_numeric(col, errors='coerce'))

See the docs and this related question: pandas: to_numeric for multiple columns

2 of 7
41

convert_objects is deprecated.

For pandas >= 0.17.0, use pd.to_numeric

df["2nd"] = pd.to_numeric(df["2nd"])
Top answer
1 of 1
2

If memory is a problem, and if you know the size of the field ahead of time, you probably don't want to read the entire file in the first place. Something like this is probably more appropriate:

#allocate memory (np.empty would work too and be marginally faster, 
#                 but probably not worth mentioning).
a=np.zeros((3000,300),dtype=np.float32)  
with open(filename) as f:
    for i,line in enumerate(f):
        a[i,:]=map(np.float32,line.split()) 

from a couple quick (and surprising) tests on my machine, it appears that the map may not even be necessary:

a=np.zeros((3000,300),dtype=np.float32)  
with open(filename) as f:
    for i,line in enumerate(f):
        a[i,:]=line.split() 

This might not be the fastest, but certainly it'll be the most memory efficient way to do it.

Some tests:

import numpy as np

def func1():   #No map -- And pretty speedy :-).
    a=np.zeros((3000,300),dtype=np.float32)
    with open('junk.txt') as f:
        for i,line in enumerate(f):
            a[i,:]=line.split()

def func2():
    a=np.zeros((3000,300),dtype=np.float32)
    with open('junk.txt') as f:
        for i,line in enumerate(f):
            a[i,:]=map(np.float32,line.split())

def func3():
    a=np.zeros((3000,300),dtype=np.float32)
    with open('junk.txt') as f:
        for i,line in enumerate(f):
            a[i,:]=map(float,line.split())

import timeit

print timeit.timeit('func1()',setup='from __main__ import func1',number=3)  #1.36s
print timeit.timeit('func2()',setup='from __main__ import func2',number=3)  #11.53s
print timeit.timeit('func3()',setup='from __main__ import func3',number=3)  #1.72s
๐ŸŒ
FavTutor
favtutor.com โ€บ blogs โ€บ string-to-float-python
6 Ways to Convert String to Float in Python | FavTutor
August 31, 2021 - If any number is greater than this, you can indicate them by the string โ€˜infโ€™ in Python ... You can use the float() function to convert any data type into a floating-point number.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-list-of-float-to-string-conversion
Python - List of float to string conversion - GeeksforGeeks
January 28, 2025 - When working with lists of floats in Python, we may often need to convert the elements of the list from float to string format. For example, if we have a list of floating-point numbers like [1.23, 4.56, 7.89], converting them to strings allows us to perform string-specific operations or output them neatly.
Top answer
1 of 16
3120
>>> a = "545.2222"
>>> float(a)
545.22220000000004
>>> int(float(a))
545
2 of 16
606

Python2 method to check if a string is a float:

def is_float(value):
  if value is None:
      return False
  try:
      float(value)
      return True
  except:
      return False

For the Python3 version of is_float see: Checking if a string can be converted to float in Python

A longer and more accurate name for this function could be: is_convertible_to_float(value)

What is, and is not a float in Python may surprise you:

The below unit tests were done using python2. Check it that Python3 has different behavior for what strings are convertable to float. One confounding difference is that any number of interior underscores are now allowed: (float("1_3.4") == float(13.4)) is True

val                   is_float(val) Note
--------------------  ----------   --------------------------------
""                    False        Blank string
"127"                 True         Passed string
True                  True         Pure sweet Truth
"True"                False        Vile contemptible lie
False                 True         So false it becomes true
"123.456"             True         Decimal
"      -127    "      True         Spaces trimmed
"\t\n12\r\n"          True         whitespace ignored
"NaN"                 True         Not a number
"NaNanananaBATMAN"    False        I am Batman
"-iNF"                True         Negative infinity
"123.E4"              True         Exponential notation
".1"                  True         mantissa only
"1_2_3.4"             False        Underscores not allowed
"12 34"               False        Spaces not allowed on interior
"1,234"               False        Commas gtfo
u'\x30'               True         Unicode is fine.
"NULL"                False        Null is not special
0x3fade               True         Hexadecimal
"6e7777777777777"     True         Shrunk to infinity
"1.797693e+308"       True         This is max value
"infinity"            True         Same as inf
"infinityandBEYOND"   False        Extra characters wreck it
"12.34.56"            False        Only one dot allowed
u'ๅ››'                 False        Japanese '4' is not a float.
"#56"                 False        Pound sign
"56%"                 False        Percent of what?
"0E0"                 True         Exponential, move dot 0 places
0**0                  True         0___0  Exponentiation
"-5e-5"               True         Raise to a negative number
"+1e1"                True         Plus is OK with exponent
"+1e1^5"              False        Fancy exponent not interpreted
"+1e1.3"              False        No decimals in exponent
"-+1"                 False        Make up your mind
"(1)"                 False        Parenthesis is bad

You think you know what numbers are? You are not so good as you think! Not big surprise.

Don't use this code on life-critical software!

Catching broad exceptions this way, killing canaries and gobbling the exception creates a tiny chance that a valid float as string will return false. The float(...) line of code can failed for any of a thousand reasons that have nothing to do with the contents of the string. But if you're writing life-critical software in a duck-typing prototype language like Python, then you've got much larger problems.