ws2026-woche05

Author

jbusse

abc_dateiname = "schugroesse.csv"
with open(abc_dateiname) as meine_eingabe_datei:
    text = meine_eingabe_datei.read()
meine_eingabe_datei
<_io.TextIOWrapper name='schugroesse.csv' mode='r' encoding='UTF-8'>
text
'gender;age;height;shoesize\nm;60;177;42\nf;23;160;38\nm;22;170;41\n'
print( f"{text}, Länge = {len(text)}" )
gender;age;height;shoesize
m;60;177;42
f;23;160;38
m;22;170;41
, Länge = 63
text.splitlines()
['gender;age;height;shoesize', 'm;60;177;42', 'f;23;160;38', 'm;22;170;41']
ergebnis = []

for zeile in text.splitlines():
    ergebnis.append( zeile.split(";") )

ergebnis
[['gender', 'age', 'height', 'shoesize'],
 ['m', '60', '177', '42'],
 ['f', '23', '160', '38'],
 ['m', '22', '170', '41']]
ergebnis = [  zeile.split(";")      for zeile in text.splitlines()[1:]       ]
ergebnis
[['m', '60', '177', '42'], ['f', '23', '160', '38'], ['m', '22', '170', '41']]
import pandas as pd
mein_schuhgrößen_df = pd.read_csv(abc_dateiname, delimiter=";")
mein_schuhgrößen_df
gender age height shoesize
0 m 60 177 42
1 f 23 160 38
2 m 22 170 41
!uv add matplotlib
Resolved 116 packages in 2ms

Checked 112 packages in 1ms
mein_schuhgrößen_df.boxplot()

mein_schuhgrößen_df.describe()
age height shoesize
count 3.000000 3.000000 3.000000
mean 35.000000 169.000000 40.333333
std 21.656408 8.544004 2.081666
min 22.000000 160.000000 38.000000
25% 22.500000 165.000000 39.500000
50% 23.000000 170.000000 41.000000
75% 41.500000 173.500000 41.500000
max 60.000000 177.000000 42.000000
mein_schuhgrößen_df.to_dict()
{'gender': {0: 'm', 1: 'f', 2: 'm'},
 'age': {0: 60, 1: 23, 2: 22},
 'height': {0: 177, 1: 160, 2: 170},
 'shoesize': {0: 42, 1: 38, 2: 41}}
mein_schuhgrößen_df.to_dict(orient="index")
{0: {'gender': 'm', 'age': 60, 'height': 177, 'shoesize': 42},
 1: {'gender': 'f', 'age': 23, 'height': 160, 'shoesize': 38},
 2: {'gender': 'm', 'age': 22, 'height': 170, 'shoesize': 41}}
mein_schuhgrößen_df.to_dict(orient="list")
{'gender': ['m', 'f', 'm'],
 'age': [60, 23, 22],
 'height': [177, 160, 170],
 'shoesize': [42, 38, 41]}
mein_schuhgrößen_df.values.tolist()
[['m', 60, 177, 42], ['f', 23, 160, 38], ['m', 22, 170, 41]]

Melbourne

melbourne_df = pd.read_csv("melb_data.csv")
melbourne_df.describe()
Rooms Price Distance Postcode Bedroom2 Bathroom Car Landsize BuildingArea YearBuilt Lattitude Longtitude Propertycount
count 13580.000000 1.358000e+04 13580.000000 13580.000000 13580.000000 13580.000000 13518.000000 13580.000000 7130.000000 8205.000000 13580.000000 13580.000000 13580.000000
mean 2.937997 1.075684e+06 10.137776 3105.301915 2.914728 1.534242 1.610075 558.416127 151.967650 1964.684217 -37.809203 144.995216 7454.417378
std 0.955748 6.393107e+05 5.868725 90.676964 0.965921 0.691712 0.962634 3990.669241 541.014538 37.273762 0.079260 0.103916 4378.581772
min 1.000000 8.500000e+04 0.000000 3000.000000 0.000000 0.000000 0.000000 0.000000 0.000000 1196.000000 -38.182550 144.431810 249.000000
25% 2.000000 6.500000e+05 6.100000 3044.000000 2.000000 1.000000 1.000000 177.000000 93.000000 1940.000000 -37.856822 144.929600 4380.000000
50% 3.000000 9.030000e+05 9.200000 3084.000000 3.000000 1.000000 2.000000 440.000000 126.000000 1970.000000 -37.802355 145.000100 6555.000000
75% 3.000000 1.330000e+06 13.000000 3148.000000 3.000000 2.000000 2.000000 651.000000 174.000000 1999.000000 -37.756400 145.058305 10331.000000
max 10.000000 9.000000e+06 48.100000 3977.000000 20.000000 8.000000 10.000000 433014.000000 44515.000000 2018.000000 -37.408530 145.526350 21650.000000
melbourne_df
Suburb Address Rooms Type Price Method SellerG Date Distance Postcode ... Bathroom Car Landsize BuildingArea YearBuilt CouncilArea Lattitude Longtitude Regionname Propertycount
0 Abbotsford 85 Turner St 2 h 1480000.0 S Biggin 3/12/2016 2.5 3067.0 ... 1.0 1.0 202.0 NaN NaN Yarra -37.79960 144.99840 Northern Metropolitan 4019.0
1 Abbotsford 25 Bloomburg St 2 h 1035000.0 S Biggin 4/02/2016 2.5 3067.0 ... 1.0 0.0 156.0 79.0 1900.0 Yarra -37.80790 144.99340 Northern Metropolitan 4019.0
2 Abbotsford 5 Charles St 3 h 1465000.0 SP Biggin 4/03/2017 2.5 3067.0 ... 2.0 0.0 134.0 150.0 1900.0 Yarra -37.80930 144.99440 Northern Metropolitan 4019.0
3 Abbotsford 40 Federation La 3 h 850000.0 PI Biggin 4/03/2017 2.5 3067.0 ... 2.0 1.0 94.0 NaN NaN Yarra -37.79690 144.99690 Northern Metropolitan 4019.0
4 Abbotsford 55a Park St 4 h 1600000.0 VB Nelson 4/06/2016 2.5 3067.0 ... 1.0 2.0 120.0 142.0 2014.0 Yarra -37.80720 144.99410 Northern Metropolitan 4019.0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
13575 Wheelers Hill 12 Strada Cr 4 h 1245000.0 S Barry 26/08/2017 16.7 3150.0 ... 2.0 2.0 652.0 NaN 1981.0 NaN -37.90562 145.16761 South-Eastern Metropolitan 7392.0
13576 Williamstown 77 Merrett Dr 3 h 1031000.0 SP Williams 26/08/2017 6.8 3016.0 ... 2.0 2.0 333.0 133.0 1995.0 NaN -37.85927 144.87904 Western Metropolitan 6380.0
13577 Williamstown 83 Power St 3 h 1170000.0 S Raine 26/08/2017 6.8 3016.0 ... 2.0 4.0 436.0 NaN 1997.0 NaN -37.85274 144.88738 Western Metropolitan 6380.0
13578 Williamstown 96 Verdon St 4 h 2500000.0 PI Sweeney 26/08/2017 6.8 3016.0 ... 1.0 5.0 866.0 157.0 1920.0 NaN -37.85908 144.89299 Western Metropolitan 6380.0
13579 Yarraville 6 Agnes St 4 h 1285000.0 SP Village 26/08/2017 6.3 3013.0 ... 1.0 1.0 362.0 112.0 1920.0 NaN -37.81188 144.88449 Western Metropolitan 6543.0

13580 rows × 21 columns

#melbourne_df.to_dict()

f-Strings

noten_auswertung = { "max": 3.7, "min": 1.0, "avg": 2.3 }
noten_auswertung
{'max': 3.7, 'min': 1.0, 'avg': 2.3}
max = 3.7
print( "max: ", max )
max:  3.7
print( f"max: --{max=}--    " )
max: --max=3.7--    
print( f"Antwort: {6*7=}" )
Antwort: 6*7=42
print( f"Antwort: {[ x*x for x in [2,3,4] ]=}" )
Antwort: [ x*x for x in [2,3,4] ]=[4, 9, 16]
s = "       Hallo   "
s
'       Hallo   '
s.strip()
'Hallo'