-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_notebooks.py
More file actions
40 lines (32 loc) · 2.61 KB
/
Copy pathupdate_notebooks.py
File metadata and controls
40 lines (32 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import json
import os
def insert_cells(nb_path, new_cells, insert_index=None):
with open(nb_path, 'r', encoding='utf-8') as f:
nb = json.load(f)
if insert_index is None:
nb["cells"].extend(new_cells)
else:
nb["cells"] = nb["cells"][:insert_index] + new_cells + nb["cells"][insert_index:]
with open(nb_path, 'w', encoding='utf-8') as f:
json.dump(nb, f, ensure_ascii=False, indent=1)
def md_cell(text):
return {"cell_type": "markdown", "metadata": {}, "source": [text]}
def code_cell(code):
return {"cell_type": "code", "execution_count": None, "metadata": {}, "outputs": [], "source": [code]}
# 1. Update 02_lists_tuples_dicts.ipynb
list_comp_cells = [
md_cell("### 1.1 List Comprehensions (Συνοπτική Δημιουργία Λιστών)\nΈνας πολύ 'Pythonic' τρόπος να δημιουργούμε νέες λίστες γρήγορα από υπάρχουσες."),
code_cell("# Δημιουργία λίστας με τα τετράγωνα των αριθμών από το 1 έως το 5\nsquares = [x**2 for x in range(1, 6)]\nprint('Τετράγωνα:', squares)\n\n# Φιλτράρισμα μόνο των ζυγών αριθμών\nevens = [x for x in range(1, 11) if x % 2 == 0]\nprint('Ζυγοί αριθμοί:', evens)")
]
# Insert after the Lists code cell (which is at index 2, so insert at 3)
insert_cells('02_Data_Structures/02_lists_tuples_dicts.ipynb', list_comp_cells, insert_index=3)
# 2. Update 06_pandas_numpy_intro.ipynb
viz_cells = [
md_cell("## 3. Εισαγωγή στην Οπτικοποίηση Δεδομένων (Matplotlib)\nΜε τη βιβλιοθήκη **Matplotlib** (και το module `pyplot`) μπορούμε να φτιάξουμε εύκολα γραφήματα."),
code_cell("import matplotlib.pyplot as plt\n\n# Δεδομένα\nx = [1, 2, 3, 4, 5]\ny = [2, 4, 6, 8, 10]\n\n# Δημιουργία Γραμμικού Γραφήματος\nplt.plot(x, y, marker='o', color='b', label='Γραμμή 1')\nplt.title('Απλό Γράφημα')\nplt.xlabel('Άξονας X')\nplt.ylabel('Άξονας Y')\nplt.legend()\nplt.show()"),
md_cell("### 3.1 Γράφημα Στηλών (Bar Chart)"),
code_cell("cities = ['Αθήνα', 'Θεσ/νίκη', 'Πάτρα']\npopulation = [3.1, 0.8, 0.2] # σε εκατομμύρια\n\nplt.bar(cities, population, color='green')\nplt.title('Πληθυσμός Πόλεων')\nplt.ylabel('Εκατομμύρια')\nplt.show()")
]
# Append to the end
insert_cells('06_Intro_to_Data_Science/06_pandas_numpy_intro.ipynb', viz_cells)
print("Notebooks updated successfully!")