This commit is contained in:
wagner.agnieszka 2018-06-22 22:38:06 +02:00
parent 7a8dadbe3b
commit 49fe26305c

View File

@ -1,14 +1,15 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pandas as pd
import matplotlib.pyplot as plt
def wczytaj_dane():
import pandas as pd
dane = pd.read_csv("labs06/mieszkania.csv")
dane.head()
dane = pd.read_csv("mieszkania.csv")
print(dane.head())
return(dane)
def most_common_room_number(dane):
dane['Rooms'].value_counts().idxmax()
return(dane['Rooms'].value_counts().idxmax())
@ -24,20 +25,61 @@ def find_borough(desc):
'Piątkowo',
'Winogrady',
'Miłostowo',
'Dębiec']
pass
'Dębiec',
'Grunwald',
'Nowe Miasto']
check = 0
for dzielnica in dzielnice:
if dzielnica in desc:
check = 1
save_dzielnica = dzielnica
if check == 1:
return(save_dzielnica)
else:
return("Inne")
def add_borough(dane):
pass
dzielnice = ['Stare Miasto',
'Wilda',
'Jeżyce',
'Rataje',
'Piątkowo',
'Winogrady',
'Miłostowo',
'Dębiec',
'Grunwald',
'Nowe Miasto']
Borough = []
column = dane['Location']
for item in column:
check = 0
for dzielnica in dzielnice:
if dzielnica in item:
check = 1
save_dzielnica = dzielnica
if check == 1:
Borough.append(save_dzielnica)
else:
Borough.append("Inne")
Borough = pd.DataFrame(Borough)
dane = pd.concat([dane.reset_index(drop=True), Borough], axis=1)
print(dane)
def write_plot(dane, filename):
pass
dane.groupby('Borough')['Id'].nunique().plot(kind='bar')
plt.show()
plt.savefig('output.png')
def mean_price(dane, room_number):
p1 = dane[dane['Rooms'] == 2]
p1 = dane[dane['Rooms'] == room_number]
p2 = p1['Expected']
p2.mean()
return(p2.mean())
def find_13(dane):
p1 = dane[dane['Floor'] == 13]
@ -46,17 +88,18 @@ def find_13(dane):
def find_best_flats(dane):
p_index = dane['Location'].str.contains('Winogrady')
p = dane[p_index]
p[(p['Rooms'] == 3) & (p['Floor'] == 1)]
best_flats = p[(p['Rooms'] == 3) & (p['Floor'] == 1)]
print(best_flats)
def main():
dane = wczytaj_dane()
print(dane[:5])
print("Najpopularniejsza liczba pokoi w mieszkaniu to: {}"
.format(most_common_room_number(dane)))
print("{} to najłądniejsza dzielnica w Poznaniu."
.format(find_borough("Grunwald i Jeżyce"))))
print("{} to najładniejsza dzielnica w Poznaniu."
.format(find_borough("Grunwald i Jeżyce")))
print("Średnia cena mieszkania 3-pokojowego, to: {}"
.format(mean_price(dane, 3)))