"/var/folders/ws/ytnwy3cs0hz8z73rvtwydngm0000gn/T/ipykernel_3699/2728226843.py:3: FutureWarning: Index.__or__ operating as a set operation is deprecated, in the future this will be a logical operation matching Series.__or__. Use index.union(other) instead\n",
"#df_new = df.drop(df[df.t <20 ].index | df[df.t > 80].index) #obsolete (and not working in some cases)\n",
"df_new = df.drop(index_to_be_drop)\n",
"print (\"Numero misure (dopo i tagli): \",len(df_new))\n",
"df_new"
]
...
...
%% Cell type:markdown id:a668e702 tags:
Esempio di lettura di un file di test dell'esperimento "Volano". Il numero di cifre significative nei dati sono arbitrarie. Lo scopo è solo di illustrare alcune funzioni utili di python per lavorare i dati.
%% Cell type:code id:2c3314df tags:
``` python
#plots will be shown inline
%matplotlibinline
importnumpyasnp
importmatplotlib.pyplotasplt
importmatplotlib.mlabasmlab
fromscipyimportstats
importpandasaspd
```
%% Cell type:code id:1313521e tags:
``` python
# sostituire la virgola con il punto
reading_file=open("dati_volano_raw.txt","r")
new_file_content=""
forlineinreading_file:
stripped_line=line.strip()
new_line=stripped_line.replace(",",".")
new_file_content+=new_line+"\n"
reading_file.close()
writing_file=open("dati_volano.txt","w")
writing_file.write(new_file_content)
writing_file.close()
```
%% Cell type:code id:7d55cb2e tags:
``` python
df=pd.read_csv('dati_volano.txt',header=1,sep='\t')#il separatore in questo caso era un "tab" (\t)
df
```
%% Output
Time (s) Angle (rad) Angular Velocity (rad/s) \
0 0.02 0.000000 NaN
1 0.04 0.000000 0.00000
2 0.06 0.000000 0.00000
3 0.08 0.000000 0.00000
4 0.10 0.000000 0.00000
... ... ... ...
4805 96.12 -9.501754 -0.03927
4806 96.14 -9.501754 0.00000
4807 96.16 -9.501754 0.00000
4808 96.18 -9.501754 0.00000
4809 96.20 -9.501754 0.00000
Angular Acceleration (rad/s²) Position (m) Velocity (m/s) \
0 NaN 0.000000 NaN
1 NaN 0.000000 0.000000
2 0.000000 0.000000 0.000000
3 0.000000 0.000000 0.000000
4 0.000000 0.000000 0.000000
... ... ... ...
4805 0.981748 -0.226837 -0.000937
4806 0.981748 -0.226837 0.000000
4807 0.000000 -0.226837 0.000000
4808 0.000000 -0.226837 0.000000
4809 NaN -0.226837 0.000000
Acceleration (m/s²)
0 NaN
1 NaN
2 0.000000
3 0.000000
4 0.000000
... ...
4805 0.023438
4806 0.023438
4807 0.000000
4808 0.000000
4809 NaN
[4810 rows x 7 columns]
%% Cell type:code id:7eb3c699 tags:
``` python
# remove lines with "NaN" (Not a Number)
df=df.dropna()
df
```
%% Output
Time (s) Angle (rad) Angular Velocity (rad/s) \
2 0.06 0.000000 0.00000
3 0.08 0.000000 0.00000
4 0.10 0.000000 0.00000
5 0.12 0.000000 0.00000
6 0.14 0.000000 0.00000
... ... ... ...
4804 96.10 -9.500183 -0.03927
4805 96.12 -9.501754 -0.03927
4806 96.14 -9.501754 0.00000
4807 96.16 -9.501754 0.00000
4808 96.18 -9.501754 0.00000
Angular Acceleration (rad/s²) Position (m) Velocity (m/s) \
#df_new = df.drop(df[df.t <20 ].index | df[df.t > 80].index) #obsolete (and not working in some cases)
df_new=df.drop(index_to_be_drop)
print ("Numero misure (dopo i tagli): ",len(df_new))
df_new
```
%% Output
Numero misure (iniziali): 4807
Numero misure (dopo i tagli): 3001
/var/folders/ws/ytnwy3cs0hz8z73rvtwydngm0000gn/T/ipykernel_3699/2728226843.py:3: FutureWarning: Index.__or__ operating as a set operation is deprecated, in the future this will be a logical operation matching Series.__or__. Use index.union(other) instead