Skip to content

Commit 974387c

Browse files
committed
6.5
1 parent fb48034 commit 974387c

File tree

4 files changed

+38
-109
lines changed

4 files changed

+38
-109
lines changed

.ipynb_checkpoints/05ex_OSEMN-checkpoint.ipynb

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
{
1111
"cell_type": "code",
12-
"execution_count": 2,
12+
"execution_count": 6,
1313
"metadata": {},
1414
"outputs": [],
1515
"source": [
@@ -118,41 +118,7 @@
118118
},
119119
{
120120
"cell_type": "code",
121-
"execution_count": 13,
122-
"metadata": {
123-
"scrolled": true
124-
},
125-
"outputs": [
126-
{
127-
"ename": "AttributeError",
128-
"evalue": "'str' object has no attribute 'append'",
129-
"output_type": "error",
130-
"traceback": [
131-
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
132-
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
133-
"Cell \u001b[1;32mIn[13], line 10\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m card_number \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[0;32m 9\u001b[0m \u001b[38;5;28;01mcontinue\u001b[39;00m\n\u001b[1;32m---> 10\u001b[0m card_list\u001b[38;5;241m.\u001b[39mappend(card_number)\n\u001b[0;32m 11\u001b[0m f\u001b[38;5;241m.\u001b[39mclose()\n\u001b[0;32m 12\u001b[0m \u001b[38;5;28mprint\u001b[39m(card_list)\n",
134-
"\u001b[1;31mAttributeError\u001b[0m: 'str' object has no attribute 'append'"
135-
]
136-
}
137-
],
138-
"source": [
139-
"card_list =\"\"\n",
140-
"with open(\"credit_card.dat\", mode=\"r\") as f:\n",
141-
" for line in f:\n",
142-
" card_number=\"\"\n",
143-
" for i in [i*6 for i in range(int((len(line)-4)/6))]:\n",
144-
" y = line[i:i+6]\n",
145-
" card_number+=chr(int(y,2))\n",
146-
" if card_number == \"\":\n",
147-
" continue\n",
148-
" card_list.append(card_number)\n",
149-
"f.close()\n",
150-
"print(card_list)"
151-
]
152-
},
153-
{
154-
"cell_type": "code",
155-
"execution_count": 5,
121+
"execution_count": 9,
156122
"metadata": {},
157123
"outputs": [
158124
{
@@ -250,7 +216,7 @@
250216
"name": "python",
251217
"nbconvert_exporter": "python",
252218
"pygments_lexer": "ipython3",
253-
"version": "3.11.4"
219+
"version": "3.11.5"
254220
}
255221
},
256222
"nbformat": 4,

.ipynb_checkpoints/06ex_Pandas-checkpoint.ipynb

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@
5959
"source": [
6060
"N = 10000\n",
6161
"df = pd.read_csv('data_000637.txt', nrows = N)\n",
62-
"print(df.head())\n",
63-
"#df.describe() mi da anche info tipo media, st dev etc"
62+
"print(df.head())"
6463
]
6564
},
6665
{
@@ -72,7 +71,7 @@
7271
},
7372
{
7473
"cell_type": "code",
75-
"execution_count": 4,
74+
"execution_count": 13,
7675
"metadata": {},
7776
"outputs": [
7877
{
@@ -84,9 +83,8 @@
8483
}
8584
],
8685
"source": [
87-
"max_bx_counter = df['BX_COUNTER'].max() #prendo df e cerco il max nella colonna \"BX_COUNTER\".\n",
88-
"num_bx_in_orbit = max_bx_counter + 1 #il max sarà max + 1\n",
89-
"print(f'The number of BX in an ORBIT is: {num_bx_in_orbit}') #l'f all'inizio mi fa stampare una stringa"
86+
"num_bx_in_orbit = df[\"BX_COUNTER\"].max() + 1\n",
87+
"print(f'The number of BX in an ORBIT is: {num_bx_in_orbit}')"
9088
]
9189
},
9290
{
@@ -98,7 +96,7 @@
9896
},
9997
{
10098
"cell_type": "code",
101-
"execution_count": 5,
99+
"execution_count": 16,
102100
"metadata": {},
103101
"outputs": [
104102
{
@@ -111,13 +109,12 @@
111109
],
112110
"source": [
113111
"df_full = pd.read_csv('data_000637.txt')\n",
114-
"max_orbit = df_full['ORBIT_CNT'].max() #valore max dell'orbit_cnt\n",
115-
"min_orbit = df_full['ORBIT_CNT'].min() #valore min\n",
116-
"duration_orbits = max_orbit - min_orbit + 1 #durata in orbits\n",
117-
"duration_bx = duration_orbits * num_bx_in_orbit #calcolo la durata in bx\n",
118-
"duration_ns = duration_bx * 25 #converto in ns dato che un bx sono 25 nanosecondi\n",
119-
"duration_seconds = duration_ns / 1e9\n",
120-
"print(f'Data taking lasted: {duration_seconds} seconds')"
112+
"max_orbit = df_full['ORBIT_CNT'].max()\n",
113+
"min_orbit = df_full['ORBIT_CNT'].min()\n",
114+
"duration_orbits = max_orbit - min_orbit + 1\n",
115+
"duration_bx = duration_orbits * num_bx_in_orbit\n",
116+
"duration_s = duration_bx * 25 / 1e9\n",
117+
"print(f'Data taking lasted: {duration_s} seconds')"
121118
]
122119
},
123120
{
@@ -316,15 +313,18 @@
316313
},
317314
{
318315
"cell_type": "code",
319-
"execution_count": 29,
316+
"execution_count": 2,
320317
"metadata": {},
321318
"outputs": [
322319
{
323-
"name": "stdout",
324-
"output_type": "stream",
325-
"text": [
326-
"Number of unique orbits: 11001\n",
327-
"Number of unique orbits with at least one meas from TDC_CHANNEL=139: 10976\n"
320+
"ename": "NameError",
321+
"evalue": "name 'df_full' is not defined",
322+
"output_type": "error",
323+
"traceback": [
324+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
325+
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
326+
"Cell \u001b[1;32mIn[2], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m n_of_unique_orbits \u001b[38;5;241m=\u001b[39m df_full[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mORBIT_CNT\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;241m.\u001b[39mnunique() \u001b[38;5;66;03m#unici in tutto il dataset\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mNumber of unique orbits: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mn_of_unique_orbits\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 4\u001b[0m n_uniq_139 \u001b[38;5;241m=\u001b[39m df_full[df_full[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mTDC_CHANNEL\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m139\u001b[39m][\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mORBIT_CNT\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;241m.\u001b[39mnunique()\n",
327+
"\u001b[1;31mNameError\u001b[0m: name 'df_full' is not defined"
328328
]
329329
}
330330
],
@@ -353,7 +353,7 @@
353353
"name": "python",
354354
"nbconvert_exporter": "python",
355355
"pygments_lexer": "ipython3",
356-
"version": "3.11.4"
356+
"version": "3.11.5"
357357
}
358358
},
359359
"nbformat": 4,

05ex_OSEMN.ipynb

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
{
1111
"cell_type": "code",
12-
"execution_count": 2,
12+
"execution_count": 6,
1313
"metadata": {},
1414
"outputs": [],
1515
"source": [
@@ -118,41 +118,7 @@
118118
},
119119
{
120120
"cell_type": "code",
121-
"execution_count": 13,
122-
"metadata": {
123-
"scrolled": true
124-
},
125-
"outputs": [
126-
{
127-
"ename": "AttributeError",
128-
"evalue": "'str' object has no attribute 'append'",
129-
"output_type": "error",
130-
"traceback": [
131-
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
132-
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
133-
"Cell \u001b[1;32mIn[13], line 10\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m card_number \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[0;32m 9\u001b[0m \u001b[38;5;28;01mcontinue\u001b[39;00m\n\u001b[1;32m---> 10\u001b[0m card_list\u001b[38;5;241m.\u001b[39mappend(card_number)\n\u001b[0;32m 11\u001b[0m f\u001b[38;5;241m.\u001b[39mclose()\n\u001b[0;32m 12\u001b[0m \u001b[38;5;28mprint\u001b[39m(card_list)\n",
134-
"\u001b[1;31mAttributeError\u001b[0m: 'str' object has no attribute 'append'"
135-
]
136-
}
137-
],
138-
"source": [
139-
"card_list =\"\"\n",
140-
"with open(\"credit_card.dat\", mode=\"r\") as f:\n",
141-
" for line in f:\n",
142-
" card_number=\"\"\n",
143-
" for i in [i*6 for i in range(int((len(line)-4)/6))]:\n",
144-
" y = line[i:i+6]\n",
145-
" card_number+=chr(int(y,2))\n",
146-
" if card_number == \"\":\n",
147-
" continue\n",
148-
" card_list.append(card_number)\n",
149-
"f.close()\n",
150-
"print(card_list)"
151-
]
152-
},
153-
{
154-
"cell_type": "code",
155-
"execution_count": 5,
121+
"execution_count": 9,
156122
"metadata": {},
157123
"outputs": [
158124
{
@@ -250,7 +216,7 @@
250216
"name": "python",
251217
"nbconvert_exporter": "python",
252218
"pygments_lexer": "ipython3",
253-
"version": "3.11.4"
219+
"version": "3.11.5"
254220
}
255221
},
256222
"nbformat": 4,

06ex_Pandas.ipynb

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@
5959
"source": [
6060
"N = 10000\n",
6161
"df = pd.read_csv('data_000637.txt', nrows = N)\n",
62-
"print(df.head())\n",
63-
"#df.describe() mi da anche info tipo media, st dev etc"
62+
"print(df.head())"
6463
]
6564
},
6665
{
@@ -72,7 +71,7 @@
7271
},
7372
{
7473
"cell_type": "code",
75-
"execution_count": 4,
74+
"execution_count": 13,
7675
"metadata": {},
7776
"outputs": [
7877
{
@@ -84,9 +83,8 @@
8483
}
8584
],
8685
"source": [
87-
"max_bx_counter = df['BX_COUNTER'].max() #prendo df e cerco il max nella colonna \"BX_COUNTER\".\n",
88-
"num_bx_in_orbit = max_bx_counter + 1 #il max sarà max + 1\n",
89-
"print(f'The number of BX in an ORBIT is: {num_bx_in_orbit}') #l'f all'inizio mi fa stampare una stringa"
86+
"num_bx_in_orbit = df[\"BX_COUNTER\"].max() + 1\n",
87+
"print(f'The number of BX in an ORBIT is: {num_bx_in_orbit}')"
9088
]
9189
},
9290
{
@@ -98,7 +96,7 @@
9896
},
9997
{
10098
"cell_type": "code",
101-
"execution_count": 5,
99+
"execution_count": 16,
102100
"metadata": {},
103101
"outputs": [
104102
{
@@ -111,13 +109,12 @@
111109
],
112110
"source": [
113111
"df_full = pd.read_csv('data_000637.txt')\n",
114-
"max_orbit = df_full['ORBIT_CNT'].max() #valore max dell'orbit_cnt\n",
115-
"min_orbit = df_full['ORBIT_CNT'].min() #valore min\n",
116-
"duration_orbits = max_orbit - min_orbit + 1 #durata in orbits\n",
117-
"duration_bx = duration_orbits * num_bx_in_orbit #calcolo la durata in bx\n",
118-
"duration_ns = duration_bx * 25 #converto in ns dato che un bx sono 25 nanosecondi\n",
119-
"duration_seconds = duration_ns / 1e9\n",
120-
"print(f'Data taking lasted: {duration_seconds} seconds')"
112+
"max_orbit = df_full['ORBIT_CNT'].max()\n",
113+
"min_orbit = df_full['ORBIT_CNT'].min()\n",
114+
"duration_orbits = max_orbit - min_orbit + 1\n",
115+
"duration_bx = duration_orbits * num_bx_in_orbit\n",
116+
"duration_s = duration_bx * 25 / 1e9\n",
117+
"print(f'Data taking lasted: {duration_s} seconds')"
121118
]
122119
},
123120
{

0 commit comments

Comments
 (0)