I have a pandas dataframe of floats and wish to write out to_csv, setting whitespace as the delimeter, and with trailing zeros to pad so it is still readable (i.e with equally spaced columns).
The complicating factor is I also want each column to be rounded to different number of decimals (some need much higher accuracy).
To reproduce:
import pandas as pd
df = pd.DataFrame( [[1.00000, 3.00000, 5.00000],
[1.45454, 3.45454, 5.45454]] )
df_rounded = df.round( {0:1, 1:3, 2:5} )
df_rounded.to_csv('out.txt', sep=' ', header=False)
Current result for out.txt:
0 1.0 3.0 5.0
1 1.5 3.455 5.45454
Desired:
0 1.0 3.000 5.00000
1 1.5 3.455 5.45454