aidevelopementtoolkit.logging_utils.printing_utils
print_table(df: pd.DataFrame, max_rows: Optional[int] = None, tablefmt: str = 'rounded_grid', max_num_columns: Optional[int] = None) -> None
Print a pandas DataFrame as a formatted table in the terminal.
| Parameters: |
|
|---|
Notes
Uses tabulate for rendering. Does not modify the DataFrame.
Examples:
Basic usage: >>> df = pd.DataFrame({"A": [1, 2], "B": [3, 4]}) >>> print_table(df)
Limit number of rows: >>> print_table(df, max_rows=1)
Change table format: >>> print_table(df, tablefmt="github")
Split into multiple tables (column chunks): >>> wide_df = pd.DataFrame({ ... "A": [1, 2], ... "B": [3, 4], ... "C": [5, 6], ... "D": [7, 8], ... }) >>> print_table(wide_df, max_num_columns=2)
Source code in aidevelopementtoolkit/logging_utils/printing_utils.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
human_readable(number: float) -> str
Convert a large number into a human-readable string with suffixes.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Examples:
>>> human_readable(1234567)
'1.23M'
>>> human_readable(9876543210)
'9.88B'
>>> human_readable(1234)
'1.23K'
Source code in aidevelopementtoolkit/logging_utils/printing_utils.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |