Have a huge pandas dataframe (df) like this:
id date a b c
0 0023 201110132120 -30 -45 7
1 0023 201110132130 -30 11 9111
2 0023 201110132140 -24 44 345
3 0023 201110132150 -19 223 11
4 0023 201110132200 -23 -3456 -1250
I need to write this dataframe to a file with special fixed-width for each field. For this i used numpy, f.e.:
np.savetxt('out.txt', df.values, fmt='%+4s %+12s %+5s %+5s %+6s')
That work's fine. Only lost header in this case. Is there a workaround?
I tested it also with pandas to_string function:
df.to_string()
But it is so slow. Why? Are there other options?