From 420ea2c62f258819665073de0ff414c8b1f4c1e5 Mon Sep 17 00:00:00 2001 From: dzastinn94 Date: Wed, 20 Jun 2018 19:44:03 +0200 Subject: [PATCH] dodaje zadania domowe --- labs06/homework.py | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 labs06/homework.py diff --git a/labs06/homework.py b/labs06/homework.py new file mode 100644 index 0000000..e2d23d4 --- /dev/null +++ b/labs06/homework.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import pandas as pd +import sys +import numpy as np + +def wczytaj_dane(): + my_data = pd.read_csv('mieszkania.csv', + encoding='utf-8', + index_col='Id', + sep = ',') + return my_data + + +def most_common_room_number(dane): + rooms = dane['Rooms'] + return rooms.value_counts().index[0] + +def cheapest_flats(dane, n): + dane2 = dane.sort_values(by=['Expected']) + return(dane2.head(n)) + +def find_borough(desc): + dzielnice = ['Stare Miasto', + 'Wilda', + 'Jeżyce', + 'Rataje', + 'Piątkowo', + 'Winogrady', + 'Miłostowo', + 'Dębiec'] + for dzielnia in dzielnice: + if dzielnia in desc: + return dzielnia + return 'Inne' + +def add_borough(dane): + dane['Borough'] = dane.apply(lambda row: find_borough(row['Location'])) + +def write_plot(dane, filename): + dane['Borough'].value_counts().plot.bar().get_figure().savefig(filename) + +def mean_price(dane, room_number): + mean_value = dane.loc[dane['Rooms'] == room_number]['Expected'].mean() + return mean_value + +def find_13(dane): + return dane.loc[dane['Floor'] == 13]['Borough'].unique() + +def find_best_flats(dane): + best_flats = dane.loc[(df['Borough'] == 'Winogrady') & (dane['Rooms'] == 3) & (dane['Floor'] == 1)] + return 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("Średnia cena mieszkania 3-pokojowego, to: {}" + .format(mean_price(dane, 3))) + +if __name__ == "__main__": + main()