pandas-plots 0.11.25__py3-none-any.whl → 0.11.26__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pandas_plots/tbl.py CHANGED
@@ -4,6 +4,7 @@
4
4
  import math
5
5
  import os
6
6
  from collections import abc
7
+ from pathlib import Path
7
8
  from typing import Literal, get_args
8
9
  import numpy as np
9
10
 
@@ -12,6 +13,7 @@ import pandas as pd
12
13
  import plotly.express as px
13
14
  from plotly.subplots import make_subplots
14
15
  from scipy import stats
16
+ import dataframe_image as dfi
15
17
 
16
18
  from .hlp import wrap_text
17
19
 
@@ -268,6 +270,11 @@ def pivot_df(
268
270
  kpi_rag_list: list[float] = None,
269
271
  kpi_mode: KPI_LITERAL = None,
270
272
  kpi_shape: Literal["squad", "circle"] = "squad",
273
+ show_as_pct: bool = False,
274
+ alter_font: bool = True,
275
+ font_size_th: int = 0,
276
+ font_size_td: int = 0,
277
+ png_path: str | Path = None,
271
278
  ) -> pd.DataFrame:
272
279
  """
273
280
  A function to pivot a DataFrame based on specified parameters hand over to the *show_num_df* function.
@@ -299,6 +306,11 @@ def pivot_df(
299
306
  max_min_x: max value green, min valued red for x axis
300
307
  kpi_rag_list: a list of floats indicating the thresholds for rag lights. The list should have 2 elements.
301
308
  kpi_shape: a Literal indicating the shape of the KPIs ["squad", "circle"]
309
+ show_as_pct (bool, optional): Whether to show values as percentages. Defaults to False.
310
+ alter_font (bool, optional): Whether to alter the font. Defaults to True.
311
+ font_size_th (int, optional): The font size for the header. Defaults to 0.
312
+ font_size_td (int, optional): The font size for the table data. Defaults to 0.
313
+ png_path (str | Path, optional): The path to save the output PNG file. Defaults to None.
302
314
 
303
315
  Returns:
304
316
  pd.DataFrame: The pivoted DataFrame.
@@ -380,6 +392,11 @@ def pivot_df(
380
392
  kpi_mode=kpi_mode,
381
393
  kpi_rag_list=kpi_rag_list,
382
394
  kpi_shape=kpi_shape,
395
+ show_as_pct=show_as_pct,
396
+ alter_font=alter_font,
397
+ font_size_th=font_size_th,
398
+ font_size_td=font_size_td,
399
+ png_path=png_path,
383
400
  )
384
401
 
385
402
 
@@ -398,6 +415,9 @@ def show_num_df(
398
415
  kpi_shape: Literal["squad", "circle"] = "squad",
399
416
  show_as_pct: bool = False,
400
417
  alter_font: bool = True,
418
+ font_size_th: int = 0,
419
+ font_size_td: int = 0,
420
+ png_path: str | Path = None,
401
421
  ):
402
422
  """
403
423
  A function to display a DataFrame with various options for styling and formatting, including the ability to show totals, apply data bar coloring, and control the display precision.
@@ -423,6 +443,9 @@ def show_num_df(
423
443
  - kpi_shape: a Literal indicating the shape of the KPIs ["squad", "circle"]
424
444
  - show_as_pct: a boolean indicating whether to show value as percentage (only advised on values ~1)
425
445
  - alter_font: a boolean indicating whether to alter the font family
446
+ - font_size_th: an integer indicating the font size for the header
447
+ - font_size_td: an integer indicating the font size for the table data
448
+ - png_path: a string or Path indicating the path to save the PNG file
426
449
 
427
450
  The function returns a styled representation of the DataFrame.
428
451
  """
@@ -637,16 +660,23 @@ def show_num_df(
637
660
  out.set_properties(**{"font-family": "Courier"})
638
661
 
639
662
  # * apply fonts for th (inkl. index)
640
- _props = [
641
- # ("font-size", "10pt"),
663
+ _props_th = [
642
664
  # ("font-weight", "bold"),
643
- # ("font-family", "Courier"),
644
665
  ("text-align", "right")
645
666
  ]
667
+
668
+ _props_td = [
669
+ ("text-align", "right")
670
+ ]
671
+ if font_size_th > 0:
672
+ _props_th.append(("font-size", f"{font_size_th}pt"))
673
+ if font_size_td > 0:
674
+ _props_td.append(("font-size", f"{font_size_td}pt"))
675
+
646
676
  out.set_table_styles(
647
677
  [
648
- dict(selector="th", props=_props),
649
- # dict(selector="th:nth-child(1)", props=_props),
678
+ dict(selector="th", props=_props_th),
679
+ dict(selector="td", props=_props_td),
650
680
  ]
651
681
  )
652
682
 
@@ -657,6 +687,10 @@ def show_num_df(
657
687
  subset=(df_orig.index, df_orig.columns) if total_exclude else None,
658
688
  )
659
689
 
690
+ if png_path is not None:
691
+ # * 72dpi default is too low for high res displays
692
+ dfi.export(obj=out, filename=png_path, dpi=120)
693
+
660
694
  return out
661
695
 
662
696
  def print_summary(df: pd.DataFrame | pd.Series, name: str="🟠 "):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pandas-plots
3
- Version: 0.11.25
3
+ Version: 0.11.26
4
4
  Summary: A collection of helper for table handling and visualization
5
5
  Home-page: https://github.com/smeisegeier/pandas-plots
6
6
  Author: smeisegeier
@@ -31,6 +31,7 @@ Requires-Dist: missingno>=0.5.2
31
31
  Requires-Dist: duckdb>=1.0.0
32
32
  Requires-Dist: kaleido>=0.2.0
33
33
  Requires-Dist: nbformat>=4.2.0
34
+ Requires-Dist: dataframe_image==0.2.3
34
35
 
35
36
  # pandas-plots
36
37
 
@@ -0,0 +1,10 @@
1
+ pandas_plots/hlp.py,sha256=N6NrbFagVMMX-ZnV0rIBEz82SeSoOkksfMcCap55W7E,16588
2
+ pandas_plots/pii.py,sha256=2WKE-W9s285jPdsTqCgt1uxuW4lj1PYCVOYB2fYDNwQ,2195
3
+ pandas_plots/pls.py,sha256=U-tjh0DnYQYg-n02hh_HyvObMerkGCBP8tirKFIEEn4,37376
4
+ pandas_plots/tbl.py,sha256=vnaRonXKntFePMX8U5pF92HMp04bxiQ6s4ZNninnlfU,29797
5
+ pandas_plots/ven.py,sha256=2x3ACo2vSfO3q6fv-UdDQ0h1SJyt8WChBGgE5SDCdCk,11673
6
+ pandas_plots-0.11.26.dist-info/LICENSE,sha256=6KQ5KVAAhRaB-JJKpX4cefKvRZRgI7GUPc92_2d31XY,1051
7
+ pandas_plots-0.11.26.dist-info/METADATA,sha256=9FNqRPjwHGYxsWn9VOy5w8xlSS1sKgVe73f2iwkLNrw,7258
8
+ pandas_plots-0.11.26.dist-info/WHEEL,sha256=A3WOREP4zgxI0fKrHUG8DC8013e3dK3n7a6HDbcEIwE,91
9
+ pandas_plots-0.11.26.dist-info/top_level.txt,sha256=XnaNuIHBqMmCeh_U7nKOYTwFue_SIA0wxuDgdPmnnSk,13
10
+ pandas_plots-0.11.26.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- pandas_plots/hlp.py,sha256=N6NrbFagVMMX-ZnV0rIBEz82SeSoOkksfMcCap55W7E,16588
2
- pandas_plots/pii.py,sha256=2WKE-W9s285jPdsTqCgt1uxuW4lj1PYCVOYB2fYDNwQ,2195
3
- pandas_plots/pls.py,sha256=U-tjh0DnYQYg-n02hh_HyvObMerkGCBP8tirKFIEEn4,37376
4
- pandas_plots/tbl.py,sha256=A1SqvssDA4ofI_WJ-sdWIb9Bo5X-sELD8pley22Y4X4,28380
5
- pandas_plots/ven.py,sha256=2x3ACo2vSfO3q6fv-UdDQ0h1SJyt8WChBGgE5SDCdCk,11673
6
- pandas_plots-0.11.25.dist-info/LICENSE,sha256=6KQ5KVAAhRaB-JJKpX4cefKvRZRgI7GUPc92_2d31XY,1051
7
- pandas_plots-0.11.25.dist-info/METADATA,sha256=ozN_fz1-7R1-lEMGUQD_XJ4qa3RBUsGdS0gXw7EGBrY,7220
8
- pandas_plots-0.11.25.dist-info/WHEEL,sha256=A3WOREP4zgxI0fKrHUG8DC8013e3dK3n7a6HDbcEIwE,91
9
- pandas_plots-0.11.25.dist-info/top_level.txt,sha256=XnaNuIHBqMmCeh_U7nKOYTwFue_SIA0wxuDgdPmnnSk,13
10
- pandas_plots-0.11.25.dist-info/RECORD,,