Giter Site home page Giter Site logo

Comments (1)

jeroenjanssens avatar jeroenjanssens commented on July 20, 2024

Let's say we have a DataFrame as you describe, with long column names and short values:

df = pl.DataFrame({"This is a really long column name with short values": [1],
                    "This is a second really long column name with short values": [2],
                    "This is a third really long column name with short values": [3],
                    "This is a fourth really long column name with short values": [4],
                    "This is a fifth really long column name with short values": [5],
                    "This is a sixth really long column name with short values": [6],
                    "This is a seventh really long column name with short values": [7],
                    "This is an eight really long column name with short values": [8],
                    "This is a ninth really long column name with short values": [9]})

With the default settings, df is printed as follows:

print(df)
shape: (1, 9)
┌───────────┬───────────┬───────────┬───────────┬───┬───────────┬───────────┬───────────┬──────────┐
│ This is a ┆ This is a ┆ This is a ┆ This is a ┆ … ┆ This is a ┆ This is a ┆ This is   ┆ This is  │
│ really    ┆ second    ┆ third     ┆ fourth    ┆   ┆ sixth     ┆ seventh   ┆ an eight  ┆ a ninth  │
│ long      ┆ really    ┆ really    ┆ really    ┆   ┆ really    ┆ really    ┆ really    ┆ really   │
│ column n… ┆ long c…   ┆ long co…  ┆ long c…   ┆   ┆ long co…  ┆ long …    ┆ long c…   ┆ long co… │
│ ---       ┆ ---       ┆ ---       ┆ ---       ┆   ┆ ---       ┆ ---       ┆ ---       ┆ ---      │
│ i64       ┆ i64       ┆ i64       ┆ i64       ┆   ┆ i64       ┆ i64       ┆ i64       ┆ i64      │
╞═══════════╪═══════════╪═══════════╪═══════════╪═══╪═══════════╪═══════════╪═══════════╪══════════╡
│ 1         ┆ 2         ┆ 3         ┆ 4         ┆ … ┆ 6         ┆ 7         ┆ 8         ┆ 9        │
└───────────┴───────────┴───────────┴───────────┴───┴───────────┴───────────┴───────────┴──────────┘

To show all columns:

with pl.Config(set_tbl_cols=-1):
    print(df)
shape: (1, 9)
┌──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┐
│ This is  ┆ This is  ┆ This is  ┆ This is  ┆ This is  ┆ This is  ┆ This is  ┆ This is  ┆ This is  │
│ a really ┆ a second ┆ a third  ┆ a fourth ┆ a fifth  ┆ a sixth  ┆ a        ┆ an eight ┆ a ninth  │
│ long     ┆ really   ┆ really   ┆ really   ┆ really   ┆ really   ┆ seventh  ┆ really   ┆ really   │
│ column   ┆ long c…  ┆ long co… ┆ long c…  ┆ long co… ┆ long co… ┆ really   ┆ long c…  ┆ long co… │
│ n…       ┆ ---      ┆ ---      ┆ ---      ┆ ---      ┆ ---      ┆ long …   ┆ ---      ┆ ---      │
│ ---      ┆ i64      ┆ i64      ┆ i64      ┆ i64      ┆ i64      ┆ ---      ┆ i64      ┆ i64      │
│ i64      ┆          ┆          ┆          ┆          ┆          ┆ i64      ┆          ┆          │
╞══════════╪══════════╪══════════╪══════════╪══════════╪══════════╪══════════╪══════════╪══════════╡
│ 1        ┆ 2        ┆ 3        ┆ 4        ┆ 5        ┆ 6        ┆ 7        ┆ 8        ┆ 9        │
└──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┘

To increase the width of the frame but constrain the width of the columns:

with pl.Config(set_tbl_cols=-1, set_fmt_str_lengths=20, set_tbl_width_chars=1000):
    print(df)
shape: (1, 9)
┌───────────────────────┬───────────────────────┬───────────────────────┬───────────────────────┬───────────────────────┬───────────────────────┬───────────────────────┬───────────────────────┬───────────────────────┐
│ This is a really lon… ┆ This is a second rea… ┆ This is a third real… ┆ This is a fourth rea… ┆ This is a fifth real… ┆ This is a sixth real… ┆ This is a seventh re… ┆ This is an eight rea… ┆ This is a ninth real… │
│ ---                   ┆ ---                   ┆ ---                   ┆ ---                   ┆ ---                   ┆ ---                   ┆ ---                   ┆ ---                   ┆ ---                   │
│ i64                   ┆ i64                   ┆ i64                   ┆ i64                   ┆ i64                   ┆ i64                   ┆ i64                   ┆ i64                   ┆ i64                   │
╞═══════════════════════╪═══════════════════════╪═══════════════════════╪═══════════════════════╪═══════════════════════╪═══════════════════════╪═══════════════════════╪═══════════════════════╪═══════════════════════╡
│ 1                     ┆ 2                     ┆ 3                     ┆ 4                     ┆ 5                     ┆ 6                     ┆ 7                     ┆ 8                     ┆ 9                     │
└───────────────────────┴───────────────────────┴───────────────────────┴───────────────────────┴───────────────────────┴───────────────────────┴───────────────────────┴───────────────────────┴───────────────────────┘

To me, it seems that these options are sufficient but perhaps I'm missing something.
Could you please clarify what you mean with "to be the minimum width feasible" ? What would the DataFrame look like if you were to print it by setting the option tbl_max_col_width_chars you propose?

from polars.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.