import pandas as pdimport repd.options.plotting.backend ="matplotlib"header = {}withopen("01.dat", "r") as f:for line in f:if r := re.match(r'^INFO,([^,]*),([^,]*)$', line): header[r[2].strip()] = r[1]if line.strip() =="[Data]":break df = pd.read_csv(f, delimiter=",", index_col="Temperature (K)")df.head()
Comment
Time Stamp (sec)
Magnetic Field (Oe)
Moment (emu)
M. Std. Err. (emu)
Temperature (K)
1.894809
NaN
358.894085
2000.191002
0.000067
7.134839e-07
3.078118
NaN
362.511599
2000.191002
0.000070
7.662391e-07
4.010035
NaN
372.406449
2000.191002
0.000068
5.733090e-07
5.069258
NaN
372.630530
2000.191002
0.000070
7.033015e-07
5.995225
NaN
376.526731
2000.191002
0.000069
7.084128e-07
Pandas
# Zobrazí prvních 5 řádků datprint("Prvních 5 řádků:")print(df.head())# Základní popis statistik datprint("\nZákladní statistiky:")print(df.describe())# Zobrazení informací o datech (datové typy, null hodnoty, velikost atd.)print("\nInformace o datech:")print(df.info())
Prvních 5 řádků:
Comment Time Stamp (sec) Magnetic Field (Oe) Moment (emu) \
Temperature (K)
1.894809 NaN 358.894085 2000.191002 0.000067
3.078118 NaN 362.511599 2000.191002 0.000070
4.010035 NaN 372.406449 2000.191002 0.000068
5.069258 NaN 372.630530 2000.191002 0.000070
5.995225 NaN 376.526731 2000.191002 0.000069
M. Std. Err. (emu)
Temperature (K)
1.894809 7.134839e-07
3.078118 7.662391e-07
4.010035 5.733090e-07
5.069258 7.033015e-07
5.995225 7.084128e-07
Základní statistiky:
Time Stamp (sec) Magnetic Field (Oe) Moment (emu) M. Std. Err. (emu)
count 300.000000 300.000000 300.000000 3.000000e+02
mean 1104.659126 2000.191002 0.000052 5.020059e-07
std 426.730677 0.000000 0.000012 1.246511e-07
min 358.894085 2000.191002 0.000032 2.790489e-07
25% 747.380907 2000.191002 0.000041 3.994841e-07
50% 1093.057337 2000.191002 0.000050 4.926898e-07
75% 1481.394855 2000.191002 0.000064 5.988325e-07
max 1828.118167 2000.191002 0.000073 7.987605e-07
Informace o datech:
<class 'pandas.core.frame.DataFrame'>
Index: 300 entries, 1.8948093429447053 to 301.094156836479
Data columns (total 5 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Comment 25 non-null object
1 Time Stamp (sec) 300 non-null float64
2 Magnetic Field (Oe) 300 non-null float64
3 Moment (emu) 300 non-null float64
4 M. Std. Err. (emu) 300 non-null float64
dtypes: float64(4), object(1)
memory usage: 14.1+ KB
None
Pandas
# Filtrování dat (např. výběr řádků, kde hodnota ve sloupci 'age' je větší než 30)filtered_df = df[df['Time Stamp (sec)'] >500]print("\nFiltrování dle času")print(filtered_df)# Vytvoření nového sloupce (např. výpočet BMI na základě sloupců 'weight' a 'height')df['Xi'] =0# #???print("\nNový sloupec BMI:")print(df[['Magnetic Field (Oe)', 'Moment (emu)', 'Xi']].head())
Filtrování dle času
Comment \
Temperature (K)
25.928075 NaN
27.034747 NaN
27.987122 NaN
28.978676 NaN
30.051740 NaN
... ...
297.021017 NaN
298.043718 sample offset = 34.54 mm touchdown = 9.3200001...
298.950699 NaN
299.989653 NaN
301.094157 NaN
Time Stamp (sec) Magnetic Field (Oe) Moment (emu) \
Temperature (K)
25.928075 501.914716 2000.191002 0.000071
27.034747 511.185624 2000.191002 0.000072
27.987122 520.558571 2000.191002 0.000070
28.978676 522.824700 2000.191002 0.000071
30.051740 523.900309 2000.191002 0.000072
... ... ... ...
297.021017 1808.808241 2000.191002 0.000034
298.043718 1812.464221 2000.191002 0.000033
298.950699 1815.072137 2000.191002 0.000034
299.989653 1819.358787 2000.191002 0.000032
301.094157 1828.118167 2000.191002 0.000034
M. Std. Err. (emu)
Temperature (K)
25.928075 5.955311e-07
27.034747 6.088898e-07
27.987122 6.528519e-07
28.978676 6.465979e-07
30.051740 6.970362e-07
... ...
297.021017 3.088224e-07
298.043718 3.666648e-07
298.950699 3.654659e-07
299.989653 2.790489e-07
301.094157 3.216486e-07
[276 rows x 5 columns]
Nový sloupec BMI:
Magnetic Field (Oe) Moment (emu) Xi
Temperature (K)
1.894809 2000.191002 0.000067 0
3.078118 2000.191002 0.000070 0
4.010035 2000.191002 0.000068 0
5.069258 2000.191002 0.000070 0
5.995225 2000.191002 0.000069 0