1

I need to print all the columns in my file, but the result I get is this....

enter image description here

Do you know how I can show all the columns of my data frame?

the code is this:


file = pl.read_excel('1.xlsx')

file = file.drop_nulls()

print(file)
Dean MacGregor
  • 11,847
  • 9
  • 34
  • 72
V0N_fs
  • 23
  • 3
  • 1
    Does this answer your question? [Pretty-print an entire Pandas Series / DataFrame](https://stackoverflow.com/questions/19124601/pretty-print-an-entire-pandas-series-dataframe) – Julien Aug 18 '23 at 01:50
  • 1
    https://pola-rs.github.io/polars/py-polars/html/reference/api/polars.Config.set_tbl_cols.html#polars.Config.set_tbl_cols – jqurious Aug 18 '23 at 04:26

1 Answers1

0

You can use polars.Config.set_tbl_cols and polars.DataFrame.width to print dynamically all columns for any Polars DataFrame

E.g.,:

import numpy as np
import polars as pl

df = pl.DataFrame(np.random.rand(5,16))
print(df)

by default gives:

shape: (5, 16)
┌──────────┬──────────┬──────────┬──────────┬───┬───────────┬───────────┬───────────┬───────────┐
│ column_0 ┆ column_1 ┆ column_2 ┆ column_3 ┆ … ┆ column_12 ┆ column_13 ┆ column_14 ┆ column_15 │
│ ---      ┆ ---      ┆ ---      ┆ ---      ┆   ┆ ---       ┆ ---       ┆ ---       ┆ ---       │
│ f64      ┆ f64      ┆ f64      ┆ f64      ┆   ┆ f64       ┆ f64       ┆ f64       ┆ f64       │
╞══════════╪══════════╪══════════╪══════════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 0.958006 ┆ 0.163983 ┆ 0.262214 ┆ 0.530242 ┆ … ┆ 0.576648  ┆ 0.396245  ┆ 0.295081  ┆ 0.210877  │
│ 0.46446  ┆ 0.743915 ┆ 0.560319 ┆ 0.033047 ┆ … ┆ 0.565604  ┆ 0.199547  ┆ 0.302649  ┆ 0.379063  │
│ 0.468403 ┆ 0.299781 ┆ 0.950776 ┆ 0.144336 ┆ … ┆ 0.820197  ┆ 0.809254  ┆ 0.659095  ┆ 0.235215  │
│ 0.995248 ┆ 0.07849  ┆ 0.964677 ┆ 0.620723 ┆ … ┆ 0.336031  ┆ 0.595888  ┆ 0.867185  ┆ 0.21454   │
│ 0.0762   ┆ 0.250534 ┆ 0.61255  ┆ 0.989831 ┆ … ┆ 0.463782  ┆ 0.539486  ┆ 0.440982  ┆ 0.741468  │
└──────────┴──────────┴──────────┴──────────┴───┴───────────┴───────────┴───────────┴───────────┘

Whereas, the following will print the whole dataframe (however "wide" it may be):

with pl.Config(tbl_cols=df.width):
    print(df)
shape: (5, 16)
┌──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬───────────┬───────────┬───────────┬───────────┬───────────┬───────────┐
│ column_0 ┆ column_1 ┆ column_2 ┆ column_3 ┆ column_4 ┆ column_5 ┆ column_6 ┆ column_7 ┆ column_8 ┆ column_9 ┆ column_10 ┆ column_11 ┆ column_12 ┆ column_13 ┆ column_14 ┆ column_15 │
│ ---      ┆ ---      ┆ ---      ┆ ---      ┆ ---      ┆ ---      ┆ ---      ┆ ---      ┆ ---      ┆ ---      ┆ ---       ┆ ---       ┆ ---       ┆ ---       ┆ ---       ┆ ---       │
│ f64      ┆ f64      ┆ f64      ┆ f64      ┆ f64      ┆ f64      ┆ f64      ┆ f64      ┆ f64      ┆ f64      ┆ f64       ┆ f64       ┆ f64       ┆ f64       ┆ f64       ┆ f64       │
╞══════════╪══════════╪══════════╪══════════╪══════════╪══════════╪══════════╪══════════╪══════════╪══════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 0.958006 ┆ 0.163983 ┆ 0.262214 ┆ 0.530242 ┆ 0.338138 ┆ 0.748381 ┆ 0.929955 ┆ 0.646207 ┆ 0.793273 ┆ 0.996641 ┆ 0.198061  ┆ 0.89925   ┆ 0.576648  ┆ 0.396245  ┆ 0.295081  ┆ 0.210877  │
│ 0.46446  ┆ 0.743915 ┆ 0.560319 ┆ 0.033047 ┆ 0.61844  ┆ 0.086474 ┆ 0.627254 ┆ 0.30209  ┆ 0.863573 ┆ 0.345243 ┆ 0.437457  ┆ 0.443728  ┆ 0.565604  ┆ 0.199547  ┆ 0.302649  ┆ 0.379063  │
│ 0.468403 ┆ 0.299781 ┆ 0.950776 ┆ 0.144336 ┆ 0.670752 ┆ 0.197305 ┆ 0.444721 ┆ 0.02048  ┆ 0.907439 ┆ 0.726926 ┆ 0.209236  ┆ 0.713068  ┆ 0.820197  ┆ 0.809254  ┆ 0.659095  ┆ 0.235215  │
│ 0.995248 ┆ 0.07849  ┆ 0.964677 ┆ 0.620723 ┆ 0.104222 ┆ 0.952729 ┆ 0.160296 ┆ 0.532762 ┆ 0.839671 ┆ 0.333935 ┆ 0.386702  ┆ 0.178337  ┆ 0.336031  ┆ 0.595888  ┆ 0.867185  ┆ 0.21454   │
│ 0.0762   ┆ 0.250534 ┆ 0.61255  ┆ 0.989831 ┆ 0.870024 ┆ 0.306701 ┆ 0.466684 ┆ 0.404459 ┆ 0.53981  ┆ 0.37813  ┆ 0.175629  ┆ 0.281876  ┆ 0.463782  ┆ 0.539486  ┆ 0.440982  ┆ 0.741468  │
└──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴───────────┴───────────┴───────────┴───────────┴───────────┴───────────┘
John Collins
  • 2,067
  • 9
  • 17