From 73b84e53ff5842f214e7cbe99bace9260fe172ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Korycki?= Date: Tue, 17 Jul 2018 14:54:47 +0000 Subject: [PATCH] zad2homework --- labs06/zad2homework | 73 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 labs06/zad2homework diff --git a/labs06/zad2homework b/labs06/zad2homework new file mode 100644 index 0000000..7d63e68 --- /dev/null +++ b/labs06/zad2homework @@ -0,0 +1,73 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import pandas as pd +from statistics import mode +import matplotlib.pyplot as plt + +def wczytaj_dane(): + data = pd.read_csv('mieszkania.csv') + return data + +def most_common_room_number(dane): + return mode(dane.Rooms) + + +def cheapest_flats(dane, n): + sorted = dane.Expected.sort() + return sorted.head(n) + +def find_borough(desc): + dzielnice = ['Stare Miasto', + 'Wilda', + 'Jeżyce', + 'Rataje', + 'Piątkowo', + 'Winogrady', + 'Miłostowo', + 'Dębiec'] + 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): + dane['Borough'] = dane['Location'].apply(find_borough) + return dane + +def write_plot(dane, filename): + 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): + mean_price = dane.Expected[(dane['Rooms'] == room_number)] + return mean_price.mean() + +def find_13(dane): + return dane.Location[(dane['Floor'] == 13)].unique() + +def find_best_flats(dane): + return dane[(dane['Location'] == 'Winogrady') & (dane['Rooms'] == 3) & (dane['Floor'] == 1)] + +def main(): + dane = wczytaj_dane() + print(dane[:5]) + + print("Najpopularniejsza liczba pokoi w mieszkaniu to: {}" + .format(most_common_room_number(dane))) + + print("{} to najladniejsza dzielnica w Poznaniu." + .format(find_borough("Grunwald i Jeżyce"))) + + print("Srednia cena mieszkania 3-pokojowego, to: {}" + .format(mean_price(dane, 3))) + +if __name__ == "__main__": + main()