python-lab-toolkit 1.0.0__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.
- pylab/__init__.py +43 -0
- pylab/cli.py +282 -0
- pylab/data/Data.csv +11 -0
- pylab/data/alphabet_stock_data.csv +143 -0
- pylab/data/breast-cancer.csv +351 -0
- pylab/data/dirtydata.csv +33 -0
- pylab/data/groceries.csv +359 -0
- pylab/data/iris.csv +151 -0
- pylab/data/rainfall.csv +151 -0
- pylab/data/students.csv +7 -0
- pylab/data/winequality-red.csv +1601 -0
- pylab/data/winequality-white.csv +2401 -0
- pylab/datasets.py +277 -0
- pylab/environment.py +136 -0
- pylab/errors.py +53 -0
- pylab/generator.py +216 -0
- pylab/registry.py +562 -0
- pylab/templates/q1/variable_validator.py +43 -0
- pylab/templates/q10/password_strength.py +42 -0
- pylab/templates/q11/recursion_math.py +28 -0
- pylab/templates/q12/main_analyzer.py +46 -0
- pylab/templates/q12/text_analyzer.py +16 -0
- pylab/templates/q12/text_preprocessor.py +15 -0
- pylab/templates/q13/student.py +26 -0
- pylab/templates/q14/circle.py +26 -0
- pylab/templates/q15/employee_salary.py +46 -0
- pylab/templates/q16/smart_calculator.py +51 -0
- pylab/templates/q17/complex_number.py +43 -0
- pylab/templates/q18/vehicle_inheritance.py +43 -0
- pylab/templates/q19/file_word_counter.py +48 -0
- pylab/templates/q19/sample.txt +6 -0
- pylab/templates/q2/single_number.py +26 -0
- pylab/templates/q20/age_validator.py +27 -0
- pylab/templates/q21/transaction_manager.py +45 -0
- pylab/templates/q22/date_formatter.py +30 -0
- pylab/templates/q23/rainfall_analyzer.py +73 -0
- pylab/templates/q24/student_marks.py +58 -0
- pylab/templates/q25/library_manager.py +182 -0
- pylab/templates/q26/mysql_employee_manager.py +239 -0
- pylab/templates/q27/crud_client.py +98 -0
- pylab/templates/q27/mock_server.py +85 -0
- pylab/templates/q28/index.html +33 -0
- pylab/templates/q28/login_handler.py +31 -0
- pylab/templates/q28/server.py +44 -0
- pylab/templates/q29/index.html +50 -0
- pylab/templates/q29/register_handler.py +42 -0
- pylab/templates/q29/server.py +42 -0
- pylab/templates/q3/string_operations.py +32 -0
- pylab/templates/q30/crud_handler.py +60 -0
- pylab/templates/q30/database.py +66 -0
- pylab/templates/q30/index.html +59 -0
- pylab/templates/q30/server.py +51 -0
- pylab/templates/q31/numpy_matrix.py +40 -0
- pylab/templates/q32/numpy_slicing.py +43 -0
- pylab/templates/q33/pandas_students.py +41 -0
- pylab/templates/q34/pandas_salary.py +37 -0
- pylab/templates/q35/sales_barchart.py +58 -0
- pylab/templates/q36/weather_plot.py +50 -0
- pylab/templates/q37/age_categorization.py +38 -0
- pylab/templates/q38/concat_rows.py +38 -0
- pylab/templates/q39/concat_cols.py +38 -0
- pylab/templates/q4/menu_string_processor.py +68 -0
- pylab/templates/q40/concat_merge.py +44 -0
- pylab/templates/q41/pandas_joins.py +46 -0
- pylab/templates/q42/groupby_school.py +32 -0
- pylab/templates/q43/groupby_multi.py +29 -0
- pylab/templates/q44/alphabet_stock_viz.py +95 -0
- pylab/templates/q45/multi_plot.py +65 -0
- pylab/templates/q46/dataframe_barchart.py +60 -0
- pylab/templates/q47/preprocess_data.py +54 -0
- pylab/templates/q48/clean_dirtydata.py +62 -0
- pylab/templates/q49/wine_regression.py +169 -0
- pylab/templates/q5/phonebook.py +105 -0
- pylab/templates/q50/breast_cancer_classifier.py +147 -0
- pylab/templates/q51/iris_clustering.py +95 -0
- pylab/templates/q52/apriori_groceries.py +88 -0
- pylab/templates/q6/calculator.py +67 -0
- pylab/templates/q7/session_attendees.py +37 -0
- pylab/templates/q8/number_properties.py +68 -0
- pylab/templates/q9/greet_people.py +26 -0
- python_lab_toolkit-1.0.0.dist-info/LICENSE +21 -0
- python_lab_toolkit-1.0.0.dist-info/METADATA +427 -0
- python_lab_toolkit-1.0.0.dist-info/RECORD +86 -0
- python_lab_toolkit-1.0.0.dist-info/WHEEL +5 -0
- python_lab_toolkit-1.0.0.dist-info/entry_points.txt +2 -0
- python_lab_toolkit-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
def run_apriori():
|
|
5
|
+
try:
|
|
6
|
+
import pandas as pd
|
|
7
|
+
from mlxtend.preprocessing import TransactionEncoder
|
|
8
|
+
from mlxtend.frequent_patterns import apriori, association_rules
|
|
9
|
+
except ImportError:
|
|
10
|
+
print("Error: pandas and mlxtend are required for Q52.")
|
|
11
|
+
print("Install with: pip install pandas mlxtend")
|
|
12
|
+
return
|
|
13
|
+
|
|
14
|
+
csv_path = "groceries.csv"
|
|
15
|
+
if not os.path.exists(csv_path):
|
|
16
|
+
print(f"Error: {csv_path} not found.")
|
|
17
|
+
return
|
|
18
|
+
|
|
19
|
+
print("=== Groceries Market Basket Apriori Association Rules ===")
|
|
20
|
+
os.makedirs("results", exist_ok=True)
|
|
21
|
+
|
|
22
|
+
transactions = []
|
|
23
|
+
with open(csv_path, "r", encoding="utf-8") as f:
|
|
24
|
+
for line in f:
|
|
25
|
+
line_str = line.strip()
|
|
26
|
+
if line_str:
|
|
27
|
+
items = [item.strip() for item in line_str.split(",") if item.strip()]
|
|
28
|
+
if items:
|
|
29
|
+
transactions.append(items)
|
|
30
|
+
|
|
31
|
+
print(f"1. Total Market Basket Transactions Loaded: {len(transactions)}")
|
|
32
|
+
|
|
33
|
+
all_items = [item for txn in transactions for item in txn]
|
|
34
|
+
item_series = pd.Series(all_items)
|
|
35
|
+
print("\n2. Top 10 Most Frequent Individual Items:")
|
|
36
|
+
top_items = item_series.value_counts().head(10)
|
|
37
|
+
for it, cnt in top_items.items():
|
|
38
|
+
support = cnt / len(transactions)
|
|
39
|
+
print(f" {it:<22} : {cnt} times (Support: {support:.3f})")
|
|
40
|
+
|
|
41
|
+
te = TransactionEncoder()
|
|
42
|
+
te_ary = te.fit(transactions).transform(transactions)
|
|
43
|
+
df_encoded = pd.DataFrame(te_ary, columns=te.columns_)
|
|
44
|
+
|
|
45
|
+
min_support = 0.02
|
|
46
|
+
print(f"\n3. Generating Frequent Itemsets with min_support >= {min_support}...")
|
|
47
|
+
frequent_itemsets = apriori(df_encoded, min_support=min_support, use_colnames=True)
|
|
48
|
+
frequent_itemsets["length"] = frequent_itemsets["itemsets"].apply(lambda s: len(s))
|
|
49
|
+
print(f" Found {len(frequent_itemsets)} frequent itemsets.")
|
|
50
|
+
|
|
51
|
+
if frequent_itemsets.empty:
|
|
52
|
+
print("No itemsets met the support threshold. Adjust min_support.")
|
|
53
|
+
return
|
|
54
|
+
|
|
55
|
+
min_threshold = 0.10
|
|
56
|
+
print(f"\n4. Generating Association Rules (metric='confidence', min_threshold={min_threshold})...")
|
|
57
|
+
rules = association_rules(frequent_itemsets, metric="confidence", min_threshold=min_threshold)
|
|
58
|
+
print(f" Generated {len(rules)} total association rules.")
|
|
59
|
+
|
|
60
|
+
if rules.empty:
|
|
61
|
+
print("No association rules found meeting the threshold criteria.")
|
|
62
|
+
return
|
|
63
|
+
|
|
64
|
+
rules_sorted_lift = rules.sort_values(by="lift", ascending=False)
|
|
65
|
+
print("\n5. Top 5 Rules Ranked by Lift:")
|
|
66
|
+
print(f"{'Antecedents':<28} -> {'Consequents':<24} | {'Support':<8} | {'Conf':<8} | {'Lift':<8}")
|
|
67
|
+
print("-" * 84)
|
|
68
|
+
|
|
69
|
+
for _, row in rules_sorted_lift.head(5).iterrows():
|
|
70
|
+
ant = ", ".join(list(row["antecedents"]))
|
|
71
|
+
con = ", ".join(list(row["consequents"]))
|
|
72
|
+
sup = row["support"]
|
|
73
|
+
cnf = row["confidence"]
|
|
74
|
+
lft = row["lift"]
|
|
75
|
+
print(f"{ant:<28} -> {con:<24} | {sup:<8.4f} | {cnf:<8.4f} | {lft:<8.4f}")
|
|
76
|
+
|
|
77
|
+
rules_out = os.path.join("results", "groceries_association_rules.csv")
|
|
78
|
+
rules_export = rules.copy()
|
|
79
|
+
rules_export["antecedents"] = rules_export["antecedents"].apply(lambda s: ", ".join(list(s)))
|
|
80
|
+
rules_export["consequents"] = rules_export["consequents"].apply(lambda s: ", ".join(list(s)))
|
|
81
|
+
rules_export.to_csv(rules_out, index=False)
|
|
82
|
+
print(f"\nComplete association rules exported to: {rules_out}")
|
|
83
|
+
|
|
84
|
+
def main():
|
|
85
|
+
run_apriori()
|
|
86
|
+
|
|
87
|
+
if __name__ == "__main__":
|
|
88
|
+
main()
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
|
|
3
|
+
def add(a, b):
|
|
4
|
+
return a + b
|
|
5
|
+
|
|
6
|
+
def subtract(a, b):
|
|
7
|
+
return a - b
|
|
8
|
+
|
|
9
|
+
def multiply(a, b):
|
|
10
|
+
return a * b
|
|
11
|
+
|
|
12
|
+
def divide(a, b):
|
|
13
|
+
if b == 0:
|
|
14
|
+
raise ZeroDivisionError("Division by zero is not permitted.")
|
|
15
|
+
return a / b
|
|
16
|
+
|
|
17
|
+
def floor_divide(a, b):
|
|
18
|
+
if b == 0:
|
|
19
|
+
raise ZeroDivisionError("Floor division by zero is not permitted.")
|
|
20
|
+
return a // b
|
|
21
|
+
|
|
22
|
+
def modulus(a, b):
|
|
23
|
+
if b == 0:
|
|
24
|
+
raise ZeroDivisionError("Modulo by zero is not permitted.")
|
|
25
|
+
return a % b
|
|
26
|
+
|
|
27
|
+
def power(a, b):
|
|
28
|
+
return a ** b
|
|
29
|
+
|
|
30
|
+
def calculate(op, a, b):
|
|
31
|
+
operations = {
|
|
32
|
+
"+": add,
|
|
33
|
+
"-": subtract,
|
|
34
|
+
"*": multiply,
|
|
35
|
+
"/": divide,
|
|
36
|
+
"//": floor_divide,
|
|
37
|
+
"%": modulus,
|
|
38
|
+
"**": power,
|
|
39
|
+
}
|
|
40
|
+
if op not in operations:
|
|
41
|
+
raise ValueError(f"Unsupported operator '{op}'. Supported: +, -, *, /, //, %, **")
|
|
42
|
+
return operations[op](a, b)
|
|
43
|
+
|
|
44
|
+
def main():
|
|
45
|
+
print("=== Simple Arithmetic Calculator ===")
|
|
46
|
+
demo_ops = [
|
|
47
|
+
(15, "+", 7),
|
|
48
|
+
(25, "-", 9),
|
|
49
|
+
(8, "*", 6),
|
|
50
|
+
(100, "/", 8),
|
|
51
|
+
(100, "//", 8),
|
|
52
|
+
(17, "%", 5),
|
|
53
|
+
(2, "**", 8),
|
|
54
|
+
]
|
|
55
|
+
print("Demonstration Computations:")
|
|
56
|
+
for a, op, b in demo_ops:
|
|
57
|
+
res = calculate(op, a, b)
|
|
58
|
+
print(f" {a} {op} {b} = {res}")
|
|
59
|
+
|
|
60
|
+
if len(sys.argv) == 4:
|
|
61
|
+
first = float(sys.argv[1])
|
|
62
|
+
oper = sys.argv[2]
|
|
63
|
+
second = float(sys.argv[3])
|
|
64
|
+
print(f"\nCLI Execution: {first} {oper} {second} = {calculate(oper, first, second)}")
|
|
65
|
+
|
|
66
|
+
if __name__ == "__main__":
|
|
67
|
+
main()
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
|
|
3
|
+
def analyze_attendees(ai_session, cyber_session):
|
|
4
|
+
all_attendees = ai_session.union(cyber_session)
|
|
5
|
+
both_sessions = ai_session.intersection(cyber_session)
|
|
6
|
+
ai_only = ai_session.difference(cyber_session)
|
|
7
|
+
cyber_only = cyber_session.difference(ai_session)
|
|
8
|
+
return {
|
|
9
|
+
"all_attendees": sorted(all_attendees),
|
|
10
|
+
"both_sessions": sorted(both_sessions),
|
|
11
|
+
"ai_only": sorted(ai_only),
|
|
12
|
+
"cyber_only": sorted(cyber_only),
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
def display_results(results):
|
|
16
|
+
print("=== Conference Session Attendee Analysis ===")
|
|
17
|
+
print(f"Total Unique Attendees ({len(results['all_attendees'])}):")
|
|
18
|
+
print(f" {', '.join(results['all_attendees'])}")
|
|
19
|
+
print(f"\nAttendees in Both Sessions ({len(results['both_sessions'])}):")
|
|
20
|
+
print(f" {', '.join(results['both_sessions']) if results['both_sessions'] else 'None'}")
|
|
21
|
+
print(f"\nAI-Only Attendees ({len(results['ai_only'])}):")
|
|
22
|
+
print(f" {', '.join(results['ai_only']) if results['ai_only'] else 'None'}")
|
|
23
|
+
print(f"\nCybersecurity-Only Attendees ({len(results['cyber_only'])}):")
|
|
24
|
+
print(f" {', '.join(results['cyber_only']) if results['cyber_only'] else 'None'}")
|
|
25
|
+
|
|
26
|
+
def main():
|
|
27
|
+
ai_attendees = {"Alice", "Bob", "Charlie", "David", "Emma", "Frank"}
|
|
28
|
+
cyber_attendees = {"Charlie", "David", "Grace", "Heidi", "Ivan", "Frank"}
|
|
29
|
+
|
|
30
|
+
print(f"AI Session List: {sorted(ai_attendees)}")
|
|
31
|
+
print(f"Cybersecurity Session List: {sorted(cyber_attendees)}\n")
|
|
32
|
+
|
|
33
|
+
analysis = analyze_attendees(ai_attendees, cyber_attendees)
|
|
34
|
+
display_results(analysis)
|
|
35
|
+
|
|
36
|
+
if __name__ == "__main__":
|
|
37
|
+
main()
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
|
|
3
|
+
def is_even(n):
|
|
4
|
+
return n % 2 == 0
|
|
5
|
+
|
|
6
|
+
def is_palindrome(n):
|
|
7
|
+
s = str(abs(n))
|
|
8
|
+
return s == s[::-1]
|
|
9
|
+
|
|
10
|
+
def is_armstrong(n):
|
|
11
|
+
if n < 0:
|
|
12
|
+
return False
|
|
13
|
+
digits = [int(d) for d in str(n)]
|
|
14
|
+
power = len(digits)
|
|
15
|
+
return sum(d ** power for d in digits) == n
|
|
16
|
+
|
|
17
|
+
def is_prime(n):
|
|
18
|
+
if n <= 1:
|
|
19
|
+
return False
|
|
20
|
+
if n <= 3:
|
|
21
|
+
return True
|
|
22
|
+
if n % 2 == 0 or n % 3 == 0:
|
|
23
|
+
return False
|
|
24
|
+
i = 5
|
|
25
|
+
while i * i <= n:
|
|
26
|
+
if n % i == 0 or n % (i + 2) == 0:
|
|
27
|
+
return False
|
|
28
|
+
i += 6
|
|
29
|
+
return True
|
|
30
|
+
|
|
31
|
+
def is_perfect(n):
|
|
32
|
+
if n <= 1:
|
|
33
|
+
return False
|
|
34
|
+
divisors_sum = 1
|
|
35
|
+
for i in range(2, int(n ** 0.5) + 1):
|
|
36
|
+
if n % i == 0:
|
|
37
|
+
divisors_sum += i
|
|
38
|
+
pair = n // i
|
|
39
|
+
if pair != i:
|
|
40
|
+
divisors_sum += pair
|
|
41
|
+
return divisors_sum == n
|
|
42
|
+
|
|
43
|
+
def check_all_properties(n):
|
|
44
|
+
return {
|
|
45
|
+
"number": n,
|
|
46
|
+
"even": is_even(n),
|
|
47
|
+
"palindrome": is_palindrome(n),
|
|
48
|
+
"armstrong": is_armstrong(n),
|
|
49
|
+
"prime": is_prime(n),
|
|
50
|
+
"perfect": is_perfect(n),
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
def main():
|
|
54
|
+
print("=== Number Properties Suite ===")
|
|
55
|
+
test_numbers = [6, 7, 28, 121, 153, 370, 496, 13, 20]
|
|
56
|
+
for num in test_numbers:
|
|
57
|
+
props = check_all_properties(num)
|
|
58
|
+
desc = []
|
|
59
|
+
if props["even"]: desc.append("Even")
|
|
60
|
+
else: desc.append("Odd")
|
|
61
|
+
if props["prime"]: desc.append("Prime")
|
|
62
|
+
if props["palindrome"]: desc.append("Palindrome")
|
|
63
|
+
if props["armstrong"]: desc.append("Armstrong")
|
|
64
|
+
if props["perfect"]: desc.append("Perfect")
|
|
65
|
+
print(f"Number {num:<4} -> {', '.join(desc)}")
|
|
66
|
+
|
|
67
|
+
if __name__ == "__main__":
|
|
68
|
+
main()
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
|
|
3
|
+
def greet_people(*names):
|
|
4
|
+
if not names:
|
|
5
|
+
return "Hello, Guest! Welcome!"
|
|
6
|
+
elif len(names) == 1:
|
|
7
|
+
return f"Hello, {names[0]}! Welcome to Python Lab!"
|
|
8
|
+
elif len(names) == 2:
|
|
9
|
+
return f"Hello, {names[0]} and {names[1]}! Welcome to Python Lab!"
|
|
10
|
+
else:
|
|
11
|
+
joined_names = ", ".join(names[:-1]) + f", and {names[-1]}"
|
|
12
|
+
return f"Hello, {joined_names}! Welcome to Python Lab!"
|
|
13
|
+
|
|
14
|
+
def main():
|
|
15
|
+
print("=== Variable-Argument Greeting Function ===")
|
|
16
|
+
print("Zero arguments:")
|
|
17
|
+
print(" " + greet_people())
|
|
18
|
+
print("\nSingle argument:")
|
|
19
|
+
print(" " + greet_people("Alice"))
|
|
20
|
+
print("\nTwo arguments:")
|
|
21
|
+
print(" " + greet_people("Alice", "Bob"))
|
|
22
|
+
print("\nMultiple arguments:")
|
|
23
|
+
print(" " + greet_people("Alice", "Bob", "Charlie", "Diana", "Evan"))
|
|
24
|
+
|
|
25
|
+
if __name__ == "__main__":
|
|
26
|
+
main()
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Python Lab Toolkit Developers
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|