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

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())