From c5b58c514b83d392f5c2661488712beeec90f670 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrea=20G=C3=B3ralczyk?= Date: Sat, 23 Jun 2018 16:42:09 +0000 Subject: [PATCH] Dodaj 'labs06/task02.py' --- labs06/task02.py | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 labs06/task02.py diff --git a/labs06/task02.py b/labs06/task02.py new file mode 100644 index 0000000..6c5797c --- /dev/null +++ b/labs06/task02.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import pandas as pd + +def wczytaj_dane(): + + data = pd.read_csv('mieszkania.csv', sep = ',') + return data + +def most_common_room_number(dane): + + x= dane['Rooms'].value_counts() + return(x.index.values[0]) + +def cheapest_flats(dane, n): + + cheap=dane.sort_values('Expected') + return (cheap.head(n)) + +def find_borough(desc): + + dzielnice = ['Stare Miasto', + 'Wilda', + 'Jeżyce', + 'Rataje', + 'Piątkowo', + 'Winogrady', + 'Miłostowo', + 'Dębiec'] + for dzielnica in dzielnice: + if dzielnica in desc: + return dzielnica + return 'Inne' + +def add_borough(dane): + + values = [] + for i in dane['Location']: + values.append(find_borough(i)) + + tempSeries = pd.Series(values) + dane['Borough'] = tempSeries.values + +def write_plot(dane, filename): + + add_borough(dane) + plot = dane['Borough'].value_counts() + + wykres = plot.plot(kind='bar', alpha=0.5, title='Liczba mieszkań z podziałem na dzielnice', fontsize=7, figsize=(8,8)) + wykres.set_ylabel('Liczba ogloszeń') + wykres.set_xlabel('Dzielnice') + plik = wykres.get_figure() + plik.savefig(filename) + +def mean_price(dane, room_number): + + price = dane.loc[dane['Rooms'] == room_number] + return price['Expected'].mean() + +def find_13(dane): + + x = dane.loc[dane['Floor'] == 13] + return list(set(x['Borough'].tolist())) + +def find_best_flats(dane): + + the_best = dane.loc[dane['Borough'] == 'Winogrady' & dane['Rooms'] == 3 & dane['Floor'] == 1] + return the_best + +def main(): + dane = wczytaj_dane() + print(dane[:5]) + + print("Najpopularniejsza liczba pokoi w mieszkaniu to: {}" + .format(most_common_room_number(dane))) + + 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))) + + write_plot(dane, 'ogloszenia.png') + +if __name__ == "__main__": + main() \ No newline at end of file