I'm looking for a solution to remove/turn off the 2 spaces between columns that df.to_string
creates automatically.
Example:
from pandas import DataFrame
df = DataFrame()
df = df.append({'a':'12345', 'b': '12345'})
df.to_string(index=False, header=False)
'12345 1235'
For clarity, the result is: '12345..12345' where the dots represent actual spaces.
I already tried the pandas.set_option
and pandas.to_string
documentation.
EDIT: The above example is overly simplified. I am working with an existing df that has spaces all over the place and the output text files are consumed by another blackbox program that is based off char-widths for each line. I've already figured out how to reformat the columns with formatters and make sure my columns are not cutoff by pandas default so I am 90% there (minus these auto spaces).
FYI here are some good links on to_string()
formatting and data-truncation:
- Convert to date using formatters parameter in pandas to_string
- https://github.com/pandas-dev/pandas/issues/9784
Appreciate the help!