Vorlesung 4

This commit is contained in:
dev weycloud
2021-10-07 19:58:31 +02:00
parent f90d17f1b5
commit f967eef74c
7 changed files with 168 additions and 1 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.vscode/settings.json

View File

@@ -39,3 +39,10 @@
- ```Uebung1.py``` - ```Uebung1.py```
- Schleifen - Schleifen
- ```Uebung2.py``` - ```Uebung2.py```
# Vorlesung 4
07.10.2021
- ```Vorlesung IV.pdf```
- Listen und Arrays
- ```Uebung1.py```
- ToDo: ```Uebung2.py```

View File

@@ -0,0 +1,6 @@
x,freq
1,9
2,7
3,5
4,4
5,2
1 x freq
2 1 9
3 2 7
4 3 5
5 4 4
6 5 2

View File

@@ -0,0 +1,37 @@
import pandas as pd
import numpy as np
df = pd.read_csv('/home/pi/Documents/Code/Python/ProgrammierungUndDatenanalyse/Sonstiges/STAT2/vl2-varianz-v1.csv')
# Dataframe
print(df)
# x freq
# 0 1 9
# 1 2 7
# 2 3 5
# 3 4 4
# 4 5 2
print(df.sum())
# x 15
# freq 27
sums = df.sum()
print(sums['freq'])
# 27
# Calculate Mean, respecting frequencies
rowSum = 0
for index, row in df.iterrows():
rowSum = rowSum + row.x * row.freq
mean = rowSum / sums.freq
print("mean: ", mean)
# Calculate Variance, respecting frequencies
# Sample Variance: ^σ² = (1 / n - 1) * Σ(freq*(x - mean)²)
variancePart1 = (1 / (sums.freq - 1))
variancePart2 = 0
for index, row in df.iterrows():
variancePart2 = variancePart2 + (row.freq * (row.x - mean)**2)
print(row['x'], row['freq'], variancePart2)
variance = variancePart1 * variancePart2
print("variance: ", variance)
# variance: 1.703703703703704

View File

@@ -0,0 +1,43 @@
# Entry Level, Single Machine
# https://jupyter.org/try
# oder:
# apt-get install libatlas-base-dev
# pip3 install numpy
# (pip install matplotlib==2.0.2 (py2: sonst Problem mit "functools_lru_cache"))
# sudo apt-get install python-scipy
# sudo apt update
# sudo apt install libatlas-base-dev
# pip3 install pybind11
# pip3 install scipy
# apt install python3-gi-cairo
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,5,100) # Start und Ende der x-Achse
plt.figure(figsize=(10,8)) # Inches
plt.title('Entry Level, Single Machine')
plt.xlabel('Jahre', color='black')
plt.ylabel('Euro', color='black')
# NW-110 Essential
y = 240*x+190
plt.plot(x, y, label='NW-110 Essential', color='blue', linestyle='solid')
# NW-140 Essential
y = 360*x+190
plt.plot(x, y, label='NW-140 Essential', color='darkblue', linestyle='dashed')
# FG-30E FortiCare
y = 80*x+393
plt.plot(x, y, label='FG-30E FortiCare', color='lightgreen', linestyle='dotted')
# FG-40F FortiCare
y = 91*x+453
plt.plot(x, y, label='FG-40F FortiCare', color='green', linestyle='dashdot')
# Plot
plt.legend(loc='upper left')
plt.grid()
plt.show()

8
Sonstiges/spss-import.py Normal file
View File

@@ -0,0 +1,8 @@
# pip3 install pyreadstat
import pandas as pd
import numpy as np
import pyreadstat
df, meta = pyreadstat.read_sav('/home/pi/Downloads/ESS9e03 (2018).sav')
print(df.head())

65
Vorlesung 4/Uebung1.py Normal file
View File

@@ -0,0 +1,65 @@
# Große Datenmenge > 1000 Datensätze
from statistics import mean, median, stdev, variance # z.b. mean(list)
def inputNumericString(inp):
try:
float(inp)
except ValueError:
print("Could not convert Data to an integer")
else:
return float(inp).inputNumericString()
list = []
print("Bitte geben Sie Ihre ersten 5 Modulnoten ein")
list.append(int(input("Bitte geben Sie die nächste Modulnote ein: ")))
list.append(int(input("Bitte geben Sie die nächste Modulnote ein: ")))
list.append(int(input("Bitte geben Sie die nächste Modulnote ein: ")))
list.append(int(input("Bitte geben Sie die nächste Modulnote ein: ")))
list.append(int(input("Bitte geben Sie die nächste Modulnote ein: ")))
# Weitere: .clear() .count(el) .extend(otherList) .index(el) .insert(pos,el) .len() .remove(el) .reverse .sort(reverse)
# 1.1
modus = input("Bitte geben Sie 's' ein, wenn sie die Liste sortiert ausgeben möchten.")
if modus != "s":
print("Unsortiert: ", list)
else:
list.sort()
print("Sortiert: ", list)
# 1.2
needle = int(input("Welche Note soll gesucht werden?: "))
i=0
while i < len(list):
if i < len(list):
try:
print("Die Note", needle, "ist an Listen-Position: ", list.index(needle, i, i+1)) # from pos i to pos i
pass # not: break
except ValueError:
# triggers in every item, that doesnt match the needle
pass # not: break
i += 1
# 1.3
print("Min: ", min(list))
print("Max: ", max(list))
print("Median: ", median(list))
print("Mittelwert: ", mean(list))
print("Varianz: ", variance(list))
print("Standardabweichung: ", stdev(list))
list.remove(5)
print("Median (ohne 5en): ", median(list))
print("Mittelwert (ohne 5en): ", mean(list))
# 1.4
eingabe = input('Wenn gewünscht, geben Sie bitte eine weitere Note (1-5) ein: ')
if eingabe == '1' or eingabe == '2' or eingabe == '3' or eingabe == '4' or eingabe == '5':
neueZahl = int(eingabe)
#print(list[list.count()])
#storedLastItem = list[len(list)-1] # Store last item..
#list.append(storedLastItem)
#list.insert(0, neueZahl)
list.append(neueZahl)
#list.append(storedLastItem) # ReStore last item
print(list)
else:
print('Anzahl der Modulnoten: ', list.count())