From 3f1dc2ab7aa76e4702c85f42b0d616606a664e2e Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 23 Jun 2018 13:25:32 +0200 Subject: [PATCH] homework --- labs06/task02.py | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/labs06/task02.py b/labs06/task02.py index 9d96016..11234f3 100755 --- a/labs06/task02.py +++ b/labs06/task02.py @@ -1,14 +1,20 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +import pandas as pd +from statistics import mode +import matplotlib.pyplot as plt def wczytaj_dane(): - pass + data = pd.read_csv('mieszkania.csv') + return data def most_common_room_number(dane): - pass + return mode(dane.Rooms) + def cheapest_flats(dane, n): - pass + sorted = dane.Expected.sort() + return sorted.head(n) def find_borough(desc): dzielnice = ['Stare Miasto', @@ -19,23 +25,35 @@ def find_borough(desc): 'Winogrady', 'Miłostowo', 'Dębiec'] - pass + for dzielnica in dzielnice: + list = desc.split(' ') + for element in list: + if len(element) > 2 and element == dzielnica: + return dzielnica + break + return "Inne" + def add_borough(dane): - pass + dane['Borough'] = dane['Location'].apply(find_borough) + return dane def write_plot(dane, filename): - pass + plotdata = pd.Series(dane.Location.value_counts()) + plotdata.plot(x='Location', y='Liczba ogłoszeń', kind='bar') + plt.savefig(filename) + def mean_price(dane, room_number): - pass + mean_price = dane.Expected[(dane['Rooms'] == room_number)] + return mean_price.mean() def find_13(dane): - pass + return dane.Location[(dane['Floor'] == 13)].unique() def find_best_flats(dane): - pass + return dane[(dane['Location'] == 'Winogrady') & (dane['Rooms'] == 3) & (dane['Floor'] == 1)] def main(): dane = wczytaj_dane() @@ -45,7 +63,7 @@ def main(): .format(most_common_room_number(dane))) print("{} to najłądniejsza dzielnica w Poznaniu." - .format(find_borough("Grunwald i Jeżyce")))) + .format(find_borough("Grunwald i Jeżyce"))) print("Średnia cena mieszkania 3-pokojowego, to: {}" .format(mean_price(dane, 3)))