pandas-plots 0.11.25__tar.gz → 0.11.27__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pandas-plots
3
- Version: 0.11.25
3
+ Version: 0.11.27
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.6
34
35
 
35
36
  # pandas-plots
36
37
 
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = pandas-plots
3
- version = 0.11.25
3
+ version = 0.11.27
4
4
  author = smeisegeier
5
5
  author_email = dexterDSDo@googlemail.com
6
6
  description = A collection of helper for table handling and visualization
@@ -37,6 +37,7 @@ install_requires =
37
37
  duckdb >= 1.0.0
38
38
  kaleido >= 0.2.0
39
39
  nbformat >= 4.2.0
40
+ dataframe_image >= 0.2.6
40
41
 
41
42
  [egg_info]
42
43
  tag_build =
@@ -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,12 @@ 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,
278
+ png_conversion: Literal["chrome", "selenium"] = "selenium",
271
279
  ) -> pd.DataFrame:
272
280
  """
273
281
  A function to pivot a DataFrame based on specified parameters hand over to the *show_num_df* function.
@@ -299,6 +307,12 @@ def pivot_df(
299
307
  max_min_x: max value green, min valued red for x axis
300
308
  kpi_rag_list: a list of floats indicating the thresholds for rag lights. The list should have 2 elements.
301
309
  kpi_shape: a Literal indicating the shape of the KPIs ["squad", "circle"]
310
+ show_as_pct (bool, optional): Whether to show values as percentages. Defaults to False.
311
+ alter_font (bool, optional): Whether to alter the font. Defaults to True.
312
+ font_size_th (int, optional): The font size for the header. Defaults to 0.
313
+ font_size_td (int, optional): The font size for the table data. Defaults to 0.
314
+ png_path (str | Path, optional): The path to save the output PNG file. Defaults to None.
315
+ png_conversion (Literal["chrome", "selenium"], optional): The conversion method for the PNG file. Defaults to "selenium".
302
316
 
303
317
  Returns:
304
318
  pd.DataFrame: The pivoted DataFrame.
@@ -380,6 +394,13 @@ def pivot_df(
380
394
  kpi_mode=kpi_mode,
381
395
  kpi_rag_list=kpi_rag_list,
382
396
  kpi_shape=kpi_shape,
397
+ show_as_pct=show_as_pct,
398
+ alter_font=alter_font,
399
+ font_size_th=font_size_th,
400
+ font_size_td=font_size_td,
401
+ png_path=png_path,
402
+ png_conversion=png_conversion,
403
+
383
404
  )
384
405
 
385
406
 
@@ -398,6 +419,10 @@ def show_num_df(
398
419
  kpi_shape: Literal["squad", "circle"] = "squad",
399
420
  show_as_pct: bool = False,
400
421
  alter_font: bool = True,
422
+ font_size_th: int = 0,
423
+ font_size_td: int = 0,
424
+ png_path: str | Path = None,
425
+ png_conversion: Literal["chrome", "selenium"] = "selenium",
401
426
  ):
402
427
  """
403
428
  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 +448,10 @@ def show_num_df(
423
448
  - kpi_shape: a Literal indicating the shape of the KPIs ["squad", "circle"]
424
449
  - show_as_pct: a boolean indicating whether to show value as percentage (only advised on values ~1)
425
450
  - alter_font: a boolean indicating whether to alter the font family
451
+ - font_size_th: an integer indicating the font size for the header
452
+ - font_size_td: an integer indicating the font size for the table data
453
+ - png_path: a string or Path indicating the path to save the PNG file
454
+ - png_conversion: a Literal indicating the conversion method for the PNG file ["chrome", "selenium"]
426
455
 
427
456
  The function returns a styled representation of the DataFrame.
428
457
  """
@@ -637,16 +666,23 @@ def show_num_df(
637
666
  out.set_properties(**{"font-family": "Courier"})
638
667
 
639
668
  # * apply fonts for th (inkl. index)
640
- _props = [
641
- # ("font-size", "10pt"),
669
+ _props_th = [
642
670
  # ("font-weight", "bold"),
643
- # ("font-family", "Courier"),
644
671
  ("text-align", "right")
645
672
  ]
673
+
674
+ _props_td = [
675
+ ("text-align", "right")
676
+ ]
677
+ if font_size_th > 0:
678
+ _props_th.append(("font-size", f"{font_size_th}pt"))
679
+ if font_size_td > 0:
680
+ _props_td.append(("font-size", f"{font_size_td}pt"))
681
+
646
682
  out.set_table_styles(
647
683
  [
648
- dict(selector="th", props=_props),
649
- # dict(selector="th:nth-child(1)", props=_props),
684
+ dict(selector="th", props=_props_th),
685
+ dict(selector="td", props=_props_td),
650
686
  ]
651
687
  )
652
688
 
@@ -657,6 +693,10 @@ def show_num_df(
657
693
  subset=(df_orig.index, df_orig.columns) if total_exclude else None,
658
694
  )
659
695
 
696
+ if png_path is not None:
697
+ # * 72dpi default is too low for high res displays
698
+ dfi.export(obj=out, filename=png_path, dpi=150, table_conversion=png_conversion)
699
+
660
700
  return out
661
701
 
662
702
  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.27
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.6
34
35
 
35
36
  # pandas-plots
36
37
 
@@ -10,3 +10,4 @@ missingno>=0.5.2
10
10
  duckdb>=1.0.0
11
11
  kaleido>=0.2.0
12
12
  nbformat>=4.2.0
13
+ dataframe_image>=0.2.6
File without changes
File without changes