81 lines
1.5 KiB
Python
81 lines
1.5 KiB
Python
import pandas as pd
|
|
import numpy as np
|
|
|
|
df = pd.read_csv("daten.csv",
|
|
delimiter=";",
|
|
na_values=["."],
|
|
index_col="ID",
|
|
encoding="utf-8")
|
|
|
|
meanRet = df.max()
|
|
# print(type(meanRet))
|
|
# print(meanRet)
|
|
|
|
onlyNumsDf = df[["Alter", "Größe"]]
|
|
# print(onlyNumsDf.mean())
|
|
|
|
df["Alter2"] = df["Alter"] * 2
|
|
# print(df)
|
|
|
|
onlyAlter = df["Alter"]
|
|
alterMean = onlyAlter.max()
|
|
# print(type(alterMean))
|
|
# print(alterMean)
|
|
|
|
charMap = {
|
|
0: "",
|
|
1: "A",
|
|
2: "M",
|
|
3: "O",
|
|
4: "G",
|
|
5: "U",
|
|
6: "S",
|
|
}
|
|
|
|
def intToChar(col):
|
|
retString = ""
|
|
for num in col:
|
|
char = charMap.get(num, " ")
|
|
retString += char
|
|
|
|
return retString
|
|
|
|
|
|
def timesTwo(num):
|
|
return num*2
|
|
|
|
charNums = df[["Alter", "Chars"]]
|
|
print(charNums)
|
|
print("")
|
|
def map_numbers_to_string(column):
|
|
return "".join(charMap[num] for num in column)
|
|
|
|
|
|
print(charNums.apply(intToChar, axis=0))
|
|
print("")
|
|
print(charNums.apply(timesTwo, axis=0))
|
|
# print(charNums.apply(intToChar))
|
|
print("")
|
|
alterSeries = df[["Alter"]]
|
|
print(alterSeries.apply(np.sum, axis=0))
|
|
|
|
print(df)
|
|
raucherGeschlechtDf = df.loc[10:70 ,["Raucher","Geschlecht"]]
|
|
geschlechtGrößeDf = df.loc[50:90, ["Geschlecht", "Größe"]]
|
|
alterBlutgruppeDf = df.loc[50:90 ,["Alter", "Blutgruppe"]]
|
|
print("\nRaucher Geschlecht: ")
|
|
print(raucherGeschlechtDf)
|
|
print("\nGeschlecht Größe: ")
|
|
print(geschlechtGrößeDf)
|
|
|
|
# print("\nMerge: ")
|
|
# res = raucherGeschlechtDf.merge(geschlechtGrößeDf, on="Geschlecht")
|
|
|
|
print("\nGroup: ")
|
|
res = raucherGeschlechtDf.groupby(geschlechtGrößeDf, by="Geschlecht")
|
|
|
|
print(res)
|
|
|
|
|
|
|