Skip to content

DataFrame.to_string() remove extra white space between columns #571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lodagro opened this issue Jan 4, 2012 · 4 comments
Closed

DataFrame.to_string() remove extra white space between columns #571

lodagro opened this issue Jan 4, 2012 · 4 comments

Comments

@lodagro
Copy link
Contributor

lodagro commented Jan 4, 2012

DataFrame.to_string() uses one extra white space between columns for sign alignment.
Remove it, for user who need exact column width, how to do this nicely?

see also mailing list discussion

@wesm
Copy link
Member

wesm commented Jan 8, 2012

this is still a problem post PR, will have a look

In [1]: paste
In [331]: DF=DataFrame({'i':[1,1,1],'j':[1,2,3],'k':[4,4,4],'mass_g_d':
[1.1,2.5,10.4]})

In [332]:

In [333]: intformatter = lambda x: '%10i' %x

In [334]: floatformatter = lambda x: '%10.5f' %x

In [335]: print(DF.to_string(columns=['k','i','j','mass_g_d'],
   .....:                    index_names=False,
   .....:                    colSpace=0,
   .....:                    formatters={'k':intformatter,
   .....:                                'i':intformatter,
   .....:                                'j':intformatter,
   .....:                                'mass_g_d':floatformatter}))
## -- End pasted text --
pandas/core/frame.py:939: FutureWarning: colSpace is deprecated, use col_space
  FutureWarning)
  k          i          j          mass_g_d  
0          4          1          1    1.10000
1          4          1          2    2.50000
2          4          1          3   10.40000

@wesm
Copy link
Member

wesm commented Jan 8, 2012

Sorry, my bad, after looking at the formatters, I think this is a right-justify problem. Hmmmmm

@wesm
Copy link
Member

wesm commented Jan 8, 2012

OK, kludge my way to victory, and only took 6 minutes:


In [335]: print(DF.to_string(columns=['k','i','j','mass_g_d'],
   .....:                    index_names=False,
   .....:                    colSpace=0, justify='right',
   .....:                    formatters={'k':intformatter,
   .....:                                'i':intformatter,
   .....:                                'j':intformatter,
   .....:                                'mass_g_d':floatformatter}))
## -- End pasted text --
pandas/core/frame.py:939: FutureWarning: colSpace is deprecated, use col_space
  FutureWarning)
           k          i          j   mass_g_d
0          4          1          1    1.10000
1          4          1          2    2.50000
2          4          1          3   10.40000

@wesm wesm closed this as completed Jan 8, 2012
@wesm
Copy link
Member

wesm commented Jan 8, 2012

What would ya'll think about having justify='right' as the default options? Looks more like R, but maybe it would make life easier overall. Eyeballed what hierarchical columns and it seems fine to me


In [16]: print frame.T.ix[:, :6].to_string(justify='right')
first     foo                     bar             baz
second    one     two   three     one     two     two
exp                                                  
A      -1.137 -1.6775  0.7792  0.3529  0.6557 -0.1332
B      -0.568 -0.7236  0.6556 -0.2667 -0.8273  1.1148
C       0.890 -0.4917 -0.3609  0.5157 -0.2967  1.1162

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants