Thanks to visit codestin.com
Credit goes to github.com

Skip to content

eafpres/utilities

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

utilities

vprint.py

Print a pandas DataFrame with column headers rotated vertically.

Respects the pandas display option max_rows. Rotates column headers so that they are printed vertically (stacked), which can be helpful when there are many columns and/or long column names. Will attempt to provide extra width to columns with long data. The index is printed with the index names flagged as -index- {name}. MultiIndex is supported.

If max_width is provided, it limits the total printed width in characters. Otherwise, the terminal width is used as a default, or 80 if it cannot be determined.

Args

  • df (pd.DataFrame): The DataFrame to print.
    If no DataFrame is provided, will return silently.

  • max_width (int, optional): Maximum width (in characters) of the printed table.
    Defaults to terminal width.


Usage

Note: if you clone the repo, you will get the data folder with sample data:

import pandas as pd
from vprint import vprint
data = pd.read_csv('./data/housing_data_train.csv')
vprint(data, max_width=105)

vprint(data[['MSSubClass',
             'LotShape',
             'OverallQual',
             'OverallCond',
             'TotRmsAbvGrd',
             'MasVnrType',
             'GarageType',
             'SaleCondition']], 
       max_width=159)

CLI test

If you clone the repo, you will get the data folder with sample data. You can then use the following in the terminal to test:

> python vprint.py

output:

                                                                                                      S
-                                    N                                        T                       a
i            L                       e                O   O           E   E   o                       l
n    M       o                       i   C       H    v   v           x   x   t   F   G               e
d    S       t                   U   g   o       o    e   e   Y   R   t   t   R   i   a               C
e    S   M   F               L   t   h   n   B   u    r   r   e   o   e   e   m   r   r           S   o
x    u   S   r   L           o   i   b   d   l   s    a   a   a   o   r   r   s   e   a           a   n
-    b   Z   o   o   S       t   l   o   i   d   e    l   l   r   f   i   i   A   p   g   M   Y   l   d
     C   o   n   t   t   A   S   i   r   t   g   S    l   l   B   S   o   o   b   l   e   o   r   e   i
0    l   n   t   A   r   l   h   t   h   i   T   t    Q   C   u   t   r   r   v   a   T   S   S   T   t
|    a   i   a   r   e   l   a   i   o   o   y   y    u   o   i   y   1   2   G   c   y   o   o   y   i
|    s   n   g   e   e   e   p   e   o   n   p   l    a   n   l   l   s   n   r   e   p   l   l   p   o
v    s   g   e   a   t   y   e   s   d   1   e   e    l   d   t   e   t   d   d   s   e   d   d   e   n
---------------------------------------------------------------------------------------------------------
0    60  RL  65. 845 Pav nan Reg All Col Nor 1Fa 2Sto 7   5   200 Gab Vin Vin 8   0   Att 2   200 WD  Nor
1    20  RL  80. 960 Pav nan Reg All Vee Fee 1Fa 1Sto 6   8   197 Gab Met Met 6   1   Att 5   200 WD  Nor
2    60  RL  68. 112 Pav nan IR1 All Col Nor 1Fa 2Sto 7   5   200 Gab Vin Vin 6   1   Att 9   200 WD  Nor
3    70  RL  60. 955 Pav nan 999 All Cra Nor 1Fa 2Sto 7   5   191 Gab Wd  Wd  7   1   Det 2   200 WD  Abn
4    60  RL  84. 142 Pav nan 999 All NoR Nor 1Fa 2Sto 8   5   200 Gab Vin Vin 9   1   Att 12  200 WD  Nor
     60  RL  84. 142 Pav nan 999 All NoR Nor 1Fa 2Sto 8   5   200 Gab Vin Vin 9   1   Att 12  200 WD  Nor
5    50  RL  85. 141 Pav nan IR1 All Mit Nor 1Fa 1.5F 5   5   199 Gab Vin Vin 5   0   Att 10  200 WD  Nor
6    20  RL  75. 100 Pav nan Reg All Som Nor 1Fa 1Sto 8   5   200 Gab Vin Vin 7   1   Att 8   200 WD  Nor
 ... ... ... ... ... ... ... ... ... ... ... ...  ... ... ... ... ... ... ... ... ... ... ... ... ...
1452 180 RM  35. 367 Pav nan Reg All Edw Nor Twn SLvl 5   5   200 Gab Vin Vin 5   0   Bas 5   200 WD  Nor
1453 20  RL  90. 172 Pav nan Reg All Mit Nor 1Fa 1Sto 5   5   200 Gab Vin Vin 6   0   nan 7   200 WD  Abn
1454 20  FV  62. 750 Pav Pav Reg All Som Nor 1Fa 1Sto 7   5   200 Gab Vin Vin 6   0   Att 10  200 WD  Nor
1455 60  RL  62. 791 Pav nan Reg All Gil Nor 1Fa 2Sto 6   5   199 Gab Vin Vin 7   1   Att 8   200 WD  Nor
1456 20  RL  85. 131 Pav nan Reg All NWA Nor 1Fa 1Sto 6   6   197 Gab Ply Ply 7   2   Att 2   201 WD  Nor
1457 70  RL  66. 904 Pav nan Reg All Cra Nor 1Fa 2Sto 7   9   194 Gab Cem Cme 9   2   Att 5   201 WD  Nor
1458 20  RL  68. 971 Pav nan Reg All NAm Nor 1Fa 1Sto 5   6   195 Hip Met Met 5   0   Att 4   201 WD  Nor
1459 20  RL  75. 993 Pav nan Reg All Edw Nor 1Fa 1Sto 5   6   196 Gab HdB HdB 6   0   Att 6   200 WD  Nor

                                         S
-                     T                  a
i             O   O   o                  l
n    M        v   v   t   H      G       e
d    S        e   e   R   o      a       C
e    S   L    r   r   m   u      r       o
x    u   o    a   a   s   s      a       n
-    b   t    l   l   A   e      g       d
     C   S    l   l   b   S      e       i
0    l   h    Q   C   v   t      T       t
|    a   a    u   o   G   y      y       i
|    s   p    a   n   r   l      p       o
v    s   e    l   d   d   e      e       n
------------------------------------------------
0    60  Reg  7   5   8   2Story Attchd  Normal
1    20  Reg  6   8   6   1Story Attchd  Normal
2    60  IR1  7   5   6   2Story Attchd  Normal
3    70  9999 7   5   7   2Story Detchd  Abnorml
4    60  9999 8   5   9   2Story Attchd  Normal
     60  9999 8   5   9   2Story Attchd  Normal
5    50  IR1  5   5   5   1.5Fin Attchd  Normal
6    20  Reg  8   5   7   1Story Attchd  Normal
 ... ...  ... ... ... ...    ...     ...
1452 180 Reg  5   5   5   SLvl   Basment Normal
1453 20  Reg  5   5   6   1Story nan     Abnorml
1454 20  Reg  7   5   6   1Story Attchd  Normal
1455 60  Reg  6   5   7   2Story Attchd  Normal
1456 20  Reg  6   6   7   1Story Attchd  Normal
1457 70  Reg  7   9   9   2Story Attchd  Normal
1458 20  Reg  5   6   5   1Story Attchd  Normal
1459 20  Reg  5   6   6   1Story Attchd  Normal

Note that this test uses a terminal max width of 105.

About

utility functions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages