Code fuer Hausarbeit d
This commit is contained in:
@@ -69,11 +69,42 @@ dfUnivariateAnalyse.to_csv('UnivariateAnalyse.csv')
|
|||||||
|
|
||||||
|
|
||||||
### d) Balkendiagramme
|
### d) Balkendiagramme
|
||||||
dfNominaleMerkmale = df[["bluetooth", "dual_sim", "4G"]].astype(int)
|
|
||||||
#dfNominaleSummen = dfNominaleMerkmale["bluetooth", "dual_sim", "4G"].sum()
|
# Arbeitstabelle erzeugen, die nur die Spalten der nominalen Merkmale enthält:
|
||||||
#print(dfNominaleMerkmale)
|
dfNominaleMerkmale = df[["bluetooth", "dual_sim", "4G"]].astype(int) # inkl. Typenumwandlung zur Ganzzahl (int)
|
||||||
#dfNominaleMerkmale.plot(kind="hist")
|
|
||||||
#plt.show()
|
# Jetzt Abwechselnd:
|
||||||
|
# ___Yes = Extrahieren der Datensätze mit Merkmalsausprägung 1 (yes)
|
||||||
|
# anzahl___Yes = Anzahl der Datensätze ermitteln
|
||||||
|
# ___No = Extrahieren der Datensätze mit Merkmalsausprägung 0 (no)
|
||||||
|
# anzahl___No = Anzahl der Datensätze ermitteln
|
||||||
|
bluetoothYes = dfNominaleMerkmale.loc[dfNominaleMerkmale['bluetooth'] == 1]
|
||||||
|
anzahlBluetoothYes = bluetoothYes.shape[0] # Anzahl ermitteln
|
||||||
|
bluetoothNo = dfNominaleMerkmale.loc[dfNominaleMerkmale['bluetooth'] == 0,]
|
||||||
|
anzahlBluetoothNo = bluetoothNo.shape[0] # Anzahl ermitteln
|
||||||
|
dualSimYes = dfNominaleMerkmale.loc[dfNominaleMerkmale['dual_sim'] == 1]
|
||||||
|
anzahlDualSimYes = dualSimYes.shape[0] # Anzahl ermitteln
|
||||||
|
dualSimNo = dfNominaleMerkmale.loc[dfNominaleMerkmale['dual_sim'] == 0]
|
||||||
|
anzahlDualSimNo = dualSimNo.shape[0] # Anzahl ermitteln
|
||||||
|
g4Yes = dfNominaleMerkmale.loc[dfNominaleMerkmale['4G'] == 1]
|
||||||
|
anzahl4GYes = g4Yes.shape[0] # Anzahl ermitteln
|
||||||
|
g4No = dfNominaleMerkmale.loc[dfNominaleMerkmale['4G'] == 0]
|
||||||
|
anzahl4GNo = g4No.shape[0] # Anzahl ermitteln
|
||||||
|
|
||||||
|
# Neues Dataframe erzeugen, das je Merkmal die Anzahl der Yes/No Ausprägungen abbildet
|
||||||
|
anzahlYes = [anzahlBluetoothYes, anzahlDualSimYes, anzahl4GYes]
|
||||||
|
anzahlNo = [anzahlBluetoothNo, anzahlDualSimNo, anzahl4GNo]
|
||||||
|
index = ["bluetooth", "dual_sim", "4G"] # Beschriftung der indeX-Achse
|
||||||
|
dfAnzahlYesNo = pd.DataFrame({'yes': anzahlYes, 'no': anzahlNo}, index=index)
|
||||||
|
# print(dfAnzahlYesNo)
|
||||||
|
# yes no
|
||||||
|
# bluetooth 104 96
|
||||||
|
# dual_sim 109 91
|
||||||
|
# 4G 90 110
|
||||||
|
|
||||||
|
# Für dieses Dataframe ein Balkendiagramm erzeugen, mit Rotation=0
|
||||||
|
dfAnzahlYesNo.plot.bar()
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -102,6 +133,6 @@ plt.xlabel('ram', color='black')
|
|||||||
plt.ylabel('battery_power', color='black')
|
plt.ylabel('battery_power', color='black')
|
||||||
#plt.xlim([0,50]) # set x-Axis View Range,[from,to]
|
#plt.xlim([0,50]) # set x-Axis View Range,[from,to]
|
||||||
plt.scatter(werteListeX, werteListeY)
|
plt.scatter(werteListeX, werteListeY)
|
||||||
plt.show()
|
#plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user