kshri 0.2.0__tar.gz → 0.2.2__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.
- {kshri-0.2.0/src/kshri.egg-info → kshri-0.2.2}/PKG-INFO +1 -1
- {kshri-0.2.0 → kshri-0.2.2}/pyproject.toml +1 -1
- {kshri-0.2.0 → kshri-0.2.2}/src/kshri/__init__.py +3 -1
- kshri-0.2.2/src/kshri/eda.py +145 -0
- {kshri-0.2.0 → kshri-0.2.2/src/kshri.egg-info}/PKG-INFO +1 -1
- {kshri-0.2.0 → kshri-0.2.2}/src/kshri.egg-info/SOURCES.txt +1 -0
- {kshri-0.2.0 → kshri-0.2.2}/LICENSE +0 -0
- {kshri-0.2.0 → kshri-0.2.2}/README.md +0 -0
- {kshri-0.2.0 → kshri-0.2.2}/setup.cfg +0 -0
- {kshri-0.2.0 → kshri-0.2.2}/src/kshri/core.py +0 -0
- {kshri-0.2.0 → kshri-0.2.2}/src/kshri/crazy.py +0 -0
- {kshri-0.2.0 → kshri-0.2.2}/src/kshri/modern.py +0 -0
- {kshri-0.2.0 → kshri-0.2.2}/src/kshri.egg-info/dependency_links.txt +0 -0
- {kshri-0.2.0 → kshri-0.2.2}/src/kshri.egg-info/top_level.txt +0 -0
|
@@ -13,8 +13,9 @@ from .modern import (
|
|
|
13
13
|
cosine_similarity,
|
|
14
14
|
to_llm_prompt,
|
|
15
15
|
)
|
|
16
|
+
from .eda import dashboard
|
|
16
17
|
|
|
17
|
-
__version__ = "0.2.
|
|
18
|
+
__version__ = "0.2.2"
|
|
18
19
|
__all__ = [
|
|
19
20
|
"Array",
|
|
20
21
|
"DataFrame",
|
|
@@ -28,4 +29,5 @@ __all__ = [
|
|
|
28
29
|
"quick_predict",
|
|
29
30
|
"cosine_similarity",
|
|
30
31
|
"to_llm_prompt",
|
|
32
|
+
"dashboard",
|
|
31
33
|
]
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import html
|
|
2
|
+
import os
|
|
3
|
+
import statistics
|
|
4
|
+
import webbrowser
|
|
5
|
+
from .core import DataFrame
|
|
6
|
+
from .crazy import roast, vibe_check, explain_like_im_5
|
|
7
|
+
|
|
8
|
+
def dashboard(df, filename="kshri_dashboard.html", open_browser=True):
|
|
9
|
+
"""Generate a sleek, interactive HTML EDA dashboard from a DataFrame in one line."""
|
|
10
|
+
data_df = df if isinstance(df, DataFrame) else DataFrame(df)
|
|
11
|
+
cols = data_df.columns
|
|
12
|
+
if not cols:
|
|
13
|
+
raise ValueError("Cannot generate dashboard for an empty DataFrame.")
|
|
14
|
+
|
|
15
|
+
col_names = list(cols.keys())
|
|
16
|
+
num_rows = len(next(iter(cols.values())))
|
|
17
|
+
num_cols = len(col_names)
|
|
18
|
+
missing_total = sum(1 for c in cols.values() for v in c if v is None)
|
|
19
|
+
|
|
20
|
+
roast_text = html.escape(roast(data_df)).replace("\n", "<br>")
|
|
21
|
+
vibe_text = html.escape(vibe_check(data_df)).replace("\n", "<br>")
|
|
22
|
+
|
|
23
|
+
# Build column summary cards
|
|
24
|
+
cards_html = []
|
|
25
|
+
for name, values in cols.items():
|
|
26
|
+
clean_vals = [v for v in values if v is not None]
|
|
27
|
+
missing_cnt = len(values) - len(clean_vals)
|
|
28
|
+
nums = [v for v in clean_vals if isinstance(v, (int, float))]
|
|
29
|
+
|
|
30
|
+
if nums:
|
|
31
|
+
avg = round(statistics.mean(nums), 2)
|
|
32
|
+
med = round(statistics.median(nums), 2)
|
|
33
|
+
mn, mx = min(nums), max(nums)
|
|
34
|
+
insight = html.escape(explain_like_im_5(nums))
|
|
35
|
+
# Mini SVG bar sparkline
|
|
36
|
+
span = (mx - mn) or 1
|
|
37
|
+
bars = []
|
|
38
|
+
for idx, n in enumerate(nums[:30]):
|
|
39
|
+
h = max(8, int(((n - mn) / span) * 45) + 8)
|
|
40
|
+
bars.append(f'<rect x="{idx*10}" y="{55-h}" width="7" height="{h}" rx="2" fill="#38bdf8"/>')
|
|
41
|
+
sparkline = f'<svg width="100%" height="55" viewBox="0 0 {max(1, len(nums[:30]))*10} 55">{"".join(bars)}</svg>'
|
|
42
|
+
stats_html = f"""
|
|
43
|
+
<div class="stat-grid">
|
|
44
|
+
<div><span>Mean</span><strong>{avg}</strong></div>
|
|
45
|
+
<div><span>Median</span><strong>{med}</strong></div>
|
|
46
|
+
<div><span>Min / Max</span><strong>{mn} / {mx}</strong></div>
|
|
47
|
+
<div><span>Missing</span><strong>{missing_cnt}</strong></div>
|
|
48
|
+
</div>
|
|
49
|
+
{sparkline}
|
|
50
|
+
<p class="insight">{insight}</p>
|
|
51
|
+
"""
|
|
52
|
+
else:
|
|
53
|
+
unique_cnt = len(set(str(v) for v in clean_vals))
|
|
54
|
+
top_val = max(set(clean_vals), key=clean_vals.count) if clean_vals else "N/A"
|
|
55
|
+
stats_html = f"""
|
|
56
|
+
<div class="stat-grid">
|
|
57
|
+
<div><span>Type</span><strong>Text / Categorical</strong></div>
|
|
58
|
+
<div><span>Unique</span><strong>{unique_cnt}</strong></div>
|
|
59
|
+
<div><span>Top Value</span><strong>{html.escape(str(top_val))}</strong></div>
|
|
60
|
+
<div><span>Missing</span><strong>{missing_cnt}</strong></div>
|
|
61
|
+
</div>
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
cards_html.append(f"""
|
|
65
|
+
<div class="card">
|
|
66
|
+
<h3>{html.escape(str(name))}</h3>
|
|
67
|
+
{stats_html}
|
|
68
|
+
</div>
|
|
69
|
+
""")
|
|
70
|
+
|
|
71
|
+
# Build preview table (first 25 rows)
|
|
72
|
+
header_cells = "".join(f"<th>{html.escape(str(c))}</th>" for c in col_names)
|
|
73
|
+
body_rows = []
|
|
74
|
+
for r in range(min(25, num_rows)):
|
|
75
|
+
row_cells = []
|
|
76
|
+
for c in col_names:
|
|
77
|
+
val = cols[c][r]
|
|
78
|
+
display = '<span class="null-tag">None</span>' if val is None else html.escape(str(val))
|
|
79
|
+
row_cells.append(f"<td>{display}</td>")
|
|
80
|
+
body_rows.append(f"<tr>{''.join(row_cells)}</tr>")
|
|
81
|
+
|
|
82
|
+
page = f"""<!DOCTYPE html>
|
|
83
|
+
<html lang="en">
|
|
84
|
+
<head>
|
|
85
|
+
<meta charset="UTF-8">
|
|
86
|
+
<title>Kshri EDA Dashboard</title>
|
|
87
|
+
<style>
|
|
88
|
+
body {{ font-family: system-ui, -apple-system, sans-serif; background: #0f172a; color: #f8fafc; margin: 0; padding: 24px; }}
|
|
89
|
+
.header {{ display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #1e293b; padding-bottom: 16px; margin-bottom: 24px; }}
|
|
90
|
+
.badge {{ background: #38bdf8; color: #0f172a; font-weight: 700; padding: 4px 10px; border-radius: 999px; font-size: 13px; }}
|
|
91
|
+
.kpi-row {{ display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 24px; }}
|
|
92
|
+
.kpi {{ background: #1e293b; padding: 16px; border-radius: 12px; }}
|
|
93
|
+
.kpi span {{ color: #94a3b8; font-size: 13px; }}
|
|
94
|
+
.kpi h2 {{ margin: 6px 0 0; font-size: 26px; color: #38bdf8; }}
|
|
95
|
+
.alerts {{ display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-bottom: 24px; }}
|
|
96
|
+
.alert-box {{ background: #1e293b; border-left: 4px solid #f59e0b; padding: 16px; border-radius: 8px; line-height: 1.5; }}
|
|
97
|
+
.cards {{ display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin-bottom: 28px; }}
|
|
98
|
+
.card {{ background: #1e293b; padding: 18px; border-radius: 12px; }}
|
|
99
|
+
.card h3 {{ margin: 0 0 12px; color: #e2e8f0; border-bottom: 1px solid #334155; padding-bottom: 8px; }}
|
|
100
|
+
.stat-grid {{ display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }}
|
|
101
|
+
.stat-grid span {{ display: block; font-size: 12px; color: #94a3b8; }}
|
|
102
|
+
.insight {{ font-size: 13px; color: #cbd5e1; background: #0f172a; padding: 10px; border-radius: 8px; margin: 8px 0 0; }}
|
|
103
|
+
table {{ width: 100%; border-collapse: collapse; background: #1e293b; border-radius: 12px; overflow: hidden; }}
|
|
104
|
+
th, td {{ padding: 10px 14px; text-align: left; border-bottom: 1px solid #334155; font-size: 14px; }}
|
|
105
|
+
th {{ background: #334155; color: #38bdf8; }}
|
|
106
|
+
.null-tag {{ background: #ef444433; color: #f87171; padding: 2px 6px; border-radius: 4px; font-size: 12px; }}
|
|
107
|
+
</style>
|
|
108
|
+
</head>
|
|
109
|
+
<body>
|
|
110
|
+
<div class="header">
|
|
111
|
+
<div><h1 style="margin:0;">Kshri EDA Dashboard</h1><small style="color:#94a3b8;">Auto-generated Exploratory Data Analysis</small></div>
|
|
112
|
+
<span class="badge">kshri v0.2.2</span>
|
|
113
|
+
</div>
|
|
114
|
+
<div class="kpi-row">
|
|
115
|
+
<div class="kpi"><span>Total Rows</span><h2>{num_rows}</h2></div>
|
|
116
|
+
<div class="kpi"><span>Total Columns</span><h2>{num_cols}</h2></div>
|
|
117
|
+
<div class="kpi"><span>Missing Cells</span><h2>{missing_total}</h2></div>
|
|
118
|
+
</div>
|
|
119
|
+
<div class="alerts">
|
|
120
|
+
<div class="alert-box"><strong>Kshri Roast:</strong><br>{roast_text}</div>
|
|
121
|
+
<div class="alert-box" style="border-color:#38bdf8;"><strong>Vibe Check:</strong><br>{vibe_text}</div>
|
|
122
|
+
</div>
|
|
123
|
+
<h2>Column Analysis</h2>
|
|
124
|
+
<div class="cards">{''.join(cards_html)}</div>
|
|
125
|
+
<h2>Data Preview (First {min(25, num_rows)} Rows)</h2>
|
|
126
|
+
<table><thead><tr>{header_cells}</tr></thead><tbody>{''.join(body_rows)}</tbody></table>
|
|
127
|
+
</body>
|
|
128
|
+
</html>"""
|
|
129
|
+
|
|
130
|
+
out_path = os.path.abspath(filename)
|
|
131
|
+
with open(out_path, "w", encoding="utf-8") as f:
|
|
132
|
+
f.write(page)
|
|
133
|
+
|
|
134
|
+
print(f"Dashboard saved to: {out_path}")
|
|
135
|
+
if open_browser:
|
|
136
|
+
webbrowser.open(f"file://{out_path}")
|
|
137
|
+
|
|
138
|
+
# Auto-render inline if running inside Google Colab or Jupyter
|
|
139
|
+
try:
|
|
140
|
+
from IPython.display import display, HTML
|
|
141
|
+
display(HTML(page))
|
|
142
|
+
except ImportError:
|
|
143
|
+
pass
|
|
144
|
+
|
|
145
|
+
return out_path
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|