You can use dt.strftime for formating datetimes and then custom format of floats:

df['time'] = df['time'].dt.strftime('%Y,%m,%d %H:%M:%S')

cols = ['price1','price2']
df[cols] = df[cols].applymap(lambda x: '{0:.4f}'.format(x))
print (df)
                  time  price1  price2
0  2018,02,01 00:00:00  1.4527  1.6548
Answer from jezrael on Stack Overflow
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas convert floats to strings in dataframe
Pandas Convert Floats to Strings in DataFrame - Spark By {Examples}
December 5, 2024 - Similarly, you can use the apply() method along with a lambda function to perform custom formatting on specific columns in a Pandas DataFrame. This allows you to convert float values to strings while also applying specific formatting, such as ...
Discussions

Convert float to string without losing precision.
Use f-strings/format specifiers. num = 12.78 print(f'{num:.6f}') # prints 12.780000 The :.6f formats the float (f) num such that there are 6 decimal places. More on reddit.com
🌐 r/learnpython
5
1
February 23, 2021
Python Pandas Dataframe convert String column to Float while Keeping Precision (decimal places) - Stack Overflow
when I convert a column from string to float I lose decimal places, is there a clear way how to keep decimal places? dicti = {'1': ['55.230530663425', '43.597357785755'], '2': ['25.231784186637'... 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
python - Extract floats from a column of strings and round to 2 decimal places - Stack Overflow
If i have a data frame with values in a column 4.5678 5 7.987.998 I want to extract data for only 2 values after the decimal 4.56 5 7.98 The data is stored as a string. Any help will be appreciat... More on stackoverflow.com
🌐 stackoverflow.com
October 4, 2017
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-convert-floats-to-strings-in-pandas-dataframe
How to Convert Floats to Strings in Pandas DataFrame? - GeeksforGeeks
July 15, 2025 - There are three methods to convert Float to String: Method 1: Using DataFrame.astype(). ... This is used to cast a pandas object to a specified dtype.
🌐
Reddit
reddit.com › r/learnpython › convert float to string without losing precision.
r/learnpython on Reddit: Convert float to string without losing precision.
February 23, 2021 -

I am looking to manipulate a data frame of floats which all need 6 decimal points after manipulation.

I am looking to add brackets and () around the floats based on conditionals which is why I need to convert to strings. I then can concat the two strings together

However when I convert to str, it reduces the number of decimals to 2.

For example

-35.920000 Original Dataframe

Converted to str

-35.92 After conversion

If I convert the string back to a float, it does not retain the 6 decimals from the original df.

My understanding is both values are stored the same and they both are logically = when checked in the notebook , but for management reasons I am trying to see if there is a way to coerce the string method the take a literal copy of the float, rather than reducing it down.

Sorry for the formatting, I am on mobile .

Thanks

🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.to_string.html
pandas.DataFrame.to_string — pandas 3.0.1 documentation
DataFrame.to_string(buf=None, *, columns=None, col_space=None, header=True, index=True, na_rep='NaN', formatters=None, float_format=None, sparsify=None, index_names=True, justify=None, max_rows=None, max_cols=None, show_dimensions=False, decimal='.', line_width=None, min_rows=None, max_colwidth=None, encoding=None)[source]#
🌐
GeeksforGeeks
geeksforgeeks.org › formatting-integer-column-of-dataframe-in-pandas
Formatting float column of Dataframe in Pandas - GeeksforGeeks
January 10, 2024 - Example # Convert the whole dataframe as a string and displaydisplay(df.to_s ... In Pandas, missing data occurs when some values are missing or not collected properly and these missing values are represented as:None: A Python object used to represent missing values in object-type arrays.NaN: A special floating-point value from NumPy which is recognized by all systems that use IE
🌐
PythonHow
pythonhow.com › how › limit-floats-to-two-decimal-points
Here is how to limit floats to two decimal points in Python
Here is an example of how to use format to limit a float to two decimal points: x = 3.14159265 # Format x as a string with two decimal points y = "{:.2f}".format(x) print(y) # Output: "3.14"The format function takes a format string as the first argument and the value to format as the second argument.
🌐
Easy Tweaks
easytweaks.com › convert-float-value-string-python
How to convert floats to strings with Python and Pandas?
August 25, 2022 - Skip to content · BECOMING MORE EFFICIENT WITH TECH · HELPING TO REDUCE BUSY WORK SO YOU CAN FOCUS ON STUFF THAT MATTERS · Check out our latest posts: · How to change the default Email Account in Gmail and Outlook · How to fix Windows 11 Not detecting Bluetooth headset · How to fix Microsoft ...
Find elsewhere
🌐
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.

🌐
Finxter
blog.finxter.com › python-convert-float-to-string
Python Convert Float to String – Be on the Right Side of Change
March 9, 2024 - To set the precision after the comma to two decimal places when converting a float to a string, you can use Python’s f-string formatting functionality. For example, the expression f'{x:.2f}' converts the float variable x to a float with precision two (“2”) such as 1.23 or 3.14.
🌐
Finxter
blog.finxter.com › python-string-to-float-with-2-decimals-easy-conversion-guide
Python String to Float with 2 Decimals: Easy Conversion Guide – Be on the Right Side of Change
Pandas is a robust data manipulation library in Python that simplifies numerous data operations. For instance, you can convert a Series or DataFrame column to float and format decimals efficiently using Pandas. To achieve two decimal places, you might utilize the round() function:
Top answer
1 of 3
8

Use:

  • set_index for only numeric columns
  • replace $ with one or more whitespaces \s+
  • convert to floats by astype
  • convert to custom format by applymap

df = (df.set_index('Names')
        .replace('\$\s+','', regex=True)
        .astype(float)
        .applymap('{:,.2f}'.format))
print (df)
         Cider  Juice Subtotal (Cider) Subtotal (Juice)   Total
Names                                                          
Richard  13.00   9.00            71.50            40.50  112.00
George    7.00  21.00            38.50            94.50  133.00
Paul      0.00  23.00             0.00           103.50  103.50
John     22.00   5.00           121.00            22.50  143.50
Total    42.00  58.00           231.00           261.00  492.00
Average  10.50  14.50            57.75            65.25  123.00

EDIT:

I try improve your solution:

people_ordered = input('How many people ordered? ') 

Data = []
# Create the 4x3 table from user input
for i in range(int(people_ordered)):
    names = input("Enter the name of Person #{}: ".format(i+1))  # type str

    cider_orderred = int(input("How many orders of cider did {} have? ".format(names)))  # type str -> int
    juice_orderred = int(input("How many orders of juice did {} have? ".format(names)))  # type str -> int

    #create in loop tuple and append to list Data
    Data.append((names, cider_orderred, juice_orderred))

#create DataFrame form list of tuples, create index by Names
df1 = pd.DataFrame(Data, columns=['Names','Cider','Juice']).set_index('Names')

#count all new columns, rows
df1['Subtotal(Cider)'] = df1['Cider'] * 5.5
df1['Subtotal(Juice)'] = df1['Juice'] * 4.5
df1['Total'] = df1['Subtotal(Cider)'] + df1['Subtotal(Juice)']
df1.loc['Total'] = df1.sum()
#remove row Total for correct mean
df1.loc['Average'] = df1.drop('Total').mean()

#get custom format of columns in list cols
cols = ['Subtotal(Cider)','Subtotal(Juice)','Total']
df1[cols] = df1[cols].applymap('$ {:,.2f}'.format)
#create column from index
df1 = df1.reset_index()

print(df1)
     Names  Cider  Juice Subtotal(Cider) Subtotal(Juice)     Total
0        r   13.0    9.0         $ 71.50         $ 40.50  $ 112.00
1        g    7.0   21.0         $ 38.50         $ 94.50  $ 133.00
2        p    0.0   23.0          $ 0.00        $ 103.50  $ 103.50
3        j   22.0    5.0        $ 121.00         $ 22.50  $ 143.50
4    Total   42.0   58.0        $ 231.00        $ 261.00  $ 492.00
5  Average   10.5   14.5         $ 57.75         $ 65.25  $ 123.00
2 of 3
5

Just set all floats to 2 digits in general

pd.options.display.float_format = "{:.2f}".format

Although: df['column'].sum() will not become 2 digits...?

🌐
GitHub
github.com › pandas-dev › pandas › issues › 11302
Different precision calling .astype(str) on float numbers
October 12, 2015 - Different precision calling .astype(str) on float numbers#11302 · #11309 · Copy link · Labels · BugNumeric OperationsArithmetic, Comparison, and Logical operationsArithmetic, Comparison, and Logical operationsOutput-Formatting__repr__ of pandas objects, to_string__repr__ of pandas objects, to_string · Milestone · 0.17.1 · marcomayer · opened · on Oct 12, 2015 · Issue body actions · With pandas 0.16.2: import pandas as pd pd.DataFrame([1.12345678901234567890]).astype(str) 0 0 1.12345678901 ·
Author   marcomayer
🌐
ItSolutionstuff
itsolutionstuff.com › post › python-convert-string-to-float-with-2-decimal-places-exampleexample.html
Python Convert String to Float with 2 Decimal Places Example - ItSolutionstuff.com
October 30, 2023 - In this example, we start with the number 4.14159265359. We then use the round() function to round the number to 2 decimal places, and assign the result to the float_number variable.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-round-a-float-in-pandas
Pandas round() Method – How To Round a Float in Pandas
March 13, 2023 - Here's what the syntax for the ... of decimal places to be returned is passed in as a parameter. round(2) return rounds a number to two decimal places....
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.round.html
pandas.DataFrame.round — pandas documentation - PyData |
A DataFrame with the affected columns rounded to the specified number of decimal places. ... Round a numpy array to the given number of decimals. ... Round a Series to the given number of decimals. ... For values exactly halfway between rounded decimal values, pandas rounds to the nearest even value (e.g. -0.5 and 0.5 round to 0.0, 1.5 and 2.5 round to 2.0, etc.).