Skip to content

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

Closed
@dov

Description

@dov

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Duplicate ReportDuplicate issue or pull requestOutput-Formatting__repr__ of pandas objects, to_string

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions