wolfhece 2.2.1__py3-none-any.whl → 2.2.3__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.
wolfhece/PandasGrid.py ADDED
@@ -0,0 +1,67 @@
1
+ import wx
2
+ import wx.grid
3
+ import pandas as pd
4
+ import numpy as np
5
+ import matplotlib.pyplot as plt
6
+
7
+ class PandasGrid(wx.Dialog):
8
+
9
+ def __init__(self, parent, id, df: pd.DataFrame):
10
+ super().__init__(parent, title=f"DataFrame characteristics: {id}", size=(600, 400))
11
+
12
+ self.df = df
13
+
14
+ vbox = wx.BoxSizer(wx.VERTICAL)
15
+
16
+ # Create the grid
17
+ self.grid = wx.grid.Grid(self)
18
+ self.grid.CreateGrid(df.shape[0], df.shape[1])
19
+
20
+ # Set column labels
21
+ for col, colname in enumerate(df.columns):
22
+ self.grid.SetColLabelValue(col, str(colname))
23
+
24
+ # Fill grid and make cells read-only
25
+ for row in range(df.shape[0]):
26
+ for col in range(df.shape[1]):
27
+ val = str(df.iloc[row, col])
28
+ self.grid.SetCellValue(row, col, val)
29
+ self.grid.SetReadOnly(row, col, True)
30
+
31
+ vbox.Add(self.grid, 1, wx.EXPAND | wx.ALL, 10)
32
+
33
+ # Add a button to show histogram
34
+ self.hist_button = wx.Button(self, label="Histogram")
35
+ self.hist_button.Bind(wx.EVT_BUTTON, self.OnShowHistogram)
36
+ vbox.Add(self.hist_button, 0, wx.ALIGN_CENTER | wx.BOTTOM, 10)
37
+
38
+ self.SetSizer(vbox)
39
+
40
+ def OnShowHistogram(self, event):
41
+ selected_cols = self.grid.GetSelectedCols()
42
+ if not selected_cols:
43
+ wx.MessageBox("Please select a column to plot.", "Info", wx.OK | wx.ICON_INFORMATION)
44
+ return
45
+
46
+ col_idx = selected_cols[0]
47
+ colname = self.df.columns[col_idx]
48
+ data = pd.to_numeric(self.df[colname], errors='coerce').dropna()
49
+
50
+ if data.empty:
51
+ wx.MessageBox(f"No numeric data in column '{colname}'", "Info", wx.OK | wx.ICON_INFORMATION)
52
+ return
53
+
54
+ # Calcul de l'histogramme sans affichage
55
+ counts, bins = np.histogram(data, bins=20)
56
+ probabilities = counts / counts.sum()*100 # Normalisation
57
+
58
+ # Plot manuel
59
+ plt.figure(figsize=(6, 4))
60
+ plt.bar(bins[:-1], probabilities, width=np.diff(bins), align='edge',
61
+ color='skyblue', edgecolor='black')
62
+ plt.title(f"Histogram of {colname}")
63
+ plt.xlabel(colname)
64
+ plt.ylabel("Probability [%]")
65
+ plt.grid(visible=True)
66
+ plt.tight_layout()
67
+ plt.show()