Below I created a function to format all the floats in a pandas DataFrame to a specific precision (6 d.p) and convert to string for output to a GUI (hence why I didn't just change the pandas display options). Is this the most efficient way to convert all floats in a pandas DataFrame to strings of a specified format?
import pandas as pd
df = pd.DataFrame({'x':[5.4525242,6.5254245,7.254542],'y':[5.4525242,6.5254245,7.254542]})
def _format_floats(df):
df.loc[:,df.dtypes==float]=df.loc[:,df.dtypes==float].apply(lambda row: ["{:.6f}".format(num) for num in row])
_format_floats(df)
#Example output numbers changes to string with 6 decimals
df.iloc[0,0]
#'5.452524'
df.loc[...] == ...
looks like it should just bedf.loc[...] = ...
. \$\endgroup\$ – scnerd Sep 10 '19 at 15:06