Skip to content

Add optional column separator character to DataFrame.to_string() #30105

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
dov opened this issue Dec 6, 2019 · 3 comments
Closed

Add optional column separator character to DataFrame.to_string() #30105

dov opened this issue Dec 6, 2019 · 3 comments
Labels
Duplicate Report Duplicate issue or pull request Output-Formatting __repr__ of pandas objects, to_string

Comments

@dov
Copy link

dov commented Dec 6, 2019

I'd like more flexibility in the stringification of a pandas dataframe. Consider a trivial dataframe:

import pandas as pd

df = pd.DataFrame([[1.2454235445,2],
                   [3,4.452455]],
                   columns = ['A','B'])
print(df.to_string())

This outputs:

          A         B
0  1.245424  2.000000
1  3.000000  4.452455

My desired output is:

|   |       A  |       B  |
+---+----------+----------+
| 0 | 1.245424 | 2.000000 |
| 1 | 3.000000 | 4.452455 |

I suggest adding the following options to to_string() to support the above output:

  • output_column_separator -- The vertical bar in the above example
  • output_row_separator -- The hyphen in the above example
  • output_cross_separator -- The plus sign in the above example
@jreback
Copy link
Contributor

jreback commented Dec 6, 2019

why?

@dov
Copy link
Author

dov commented Dec 6, 2019

Because I often find myself copying a pandas dataframe output into an org-mode document, and there is no simple way of 1) using the float formatting preference of DataFrame.to_string() and 2) inserting the table delimiters. But more generally, I think that the stringified DataFrame is a matter of preference, just as a html'ified dataframe is styled according to preference.

@jreback
Copy link
Contributor

jreback commented Dec 6, 2019

see discussion and links here: #11052

@jreback jreback closed this as completed Dec 6, 2019
@jreback jreback added Duplicate Report Duplicate issue or pull request Output-Formatting __repr__ of pandas objects, to_string labels Dec 6, 2019
@jreback jreback added this to the No action milestone Dec 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

No branches or pull requests

2 participants