p-ranav / tabulate

Table Maker for Modern C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

can i limit the index width?

nickhuangxinyu opened this issue · comments

i have a dataframe, which i want to show by tabulate:

|                           f_45                           |  1.6  |  1.6  |  1.6   |
|                           f_46                           | -3.0  |  3.0  |  3.0   |
|                           f_47                           |  2.8  |  2.8  |  2.8   |
|                           f_48                           |  2.5  |  2.5  |  2.5   |
|                           f_49                           | -3.0  |  3.0  |  3.0   |
|                           f_50                           |  1.5  |  1.5  |  1.5   |
|                           f_51                           | -0.5  |  0.5  |  0.5   |
|                           f_52                           | -0.1  |  0.1  |  0.1   |
|                           f_53                           | -1.1  |  1.1  |  1.1   |
|                           f_54                           | -2.2  |  2.2  |  2.2   |
|                           f_55                           | -8.6  |  8.6  |  8.6   |
|                           f_56                           |  8.1  |  8.1  |  8.1   |
|                           f_57                           |  6.5  |  6.5  |  6.5   |
|                           f_58                           |  6.3  |  6.3  |  6.3   |
|                           f_59                           |  5.5  |  5.5  |  5.5   |
|                           f_60                           |  5.5  |  5.5  |  5.5   |
|                           f_61                           |  2.5  |  2.5  |  2.5   |
|                           f_62                           | -3.1  |  3.1  |  3.1   |
|                           f_63                           | -1.3  |  1.3  |  1.3   |
|          FillNa(DecayLinear(XH::voi_ratio,10))           |  7.8  |  7.8  |  7.8   |
|                FillNa(Diff(SmartPrice,2))                |  7.7  |  7.7  |  7.7   |
|    FillNa(Div(SignedSqrt(Ewma(XH::voi,0.8)),WSpread))    |  3.8  |  3.8  |  3.8   |
| FillNa(Div(SignedSqrt(Ewma(XH::voi_ratio,0.8)),WSpread)) | -3.3  |  3.3  |  3.3   |
|         FillNa(Sub(XH::shadow_mid(10),AvgPrice))         | -6.7  |  6.7  |  6.7   |
|         FillNa(Sub(XH::shadow_mid(10),Wmid(0)))          | -0.4  |  0.4  |  0.4   |
|                  XH::high_low_dist(10)                   |  2.0  |  2.0  |  2.0   |
|                  XH::high_low_dist(30)                   |  2.1  |  2.1  |  2.1   |
|                  XH::volat_up_down(30)                   | -2.5  |  2.5  |  2.5   |
|                  XH::volat_up_down(60)                   |  0.2  |  0.2  |  0.2   |
|                           #CNT                           | 36.7  | 36.7  |  36.7  |
|                            R2                            | 202.6 | 202.6 | 202.6  |
+----------------------------------------------------------+-------+-------+--------+

please see the index column.

there are several columns whose length is large, can i set something to limit the width?

Yes, you can set the width of rows and columns:

#include "tabulate.hpp"
using namespace tabulate;

int main() {

  Table table;

  table.add_row({"Quantity", "Value"});

  table.add_row({"FillNa(Div(SignedSqrt(Ewma(XH::voi_ratio,0.8)),WSpread))", "-3.3"});

  // set the width of the first column
  table.column(0).format().width(40);

  std::cout << table << std::endl;

}
+----------------------------------------+-------+
| Quantity                               | Value |
+----------------------------------------+-------+
| FillNa(Div(SignedSqrt(Ewma(XH::voi_ra- | -3.3  |
| tio,0.8)),WSpread))                    |       |
+----------------------------------------+-------+

@p-ranav
thx, could you let me know how to do this in python?