diff --git a/labs06/task02.py b/labs06/task02.py index 9d96016..7020153 100755 --- a/labs06/task02.py +++ b/labs06/task02.py @@ -1,15 +1,35 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +import os; +os.chdir('J:\PycharmProjects\Python2017\labs06') +import pandas as pd +import numpy as np +import matplotlib.pyplot as plt +import matplotlib +matplotlib.style.use('ggplot') +plt.rcParams['figure.figsize'] = (15, 5) def wczytaj_dane(): + dane = pd.read_csv('mieszkania.csv', sep=',') + dane.rename(columns={'Unnamed: 11': 'Borough'}, inplace=True) + #type(dane) + #print(dane.head()) + return(dane) pass + def most_common_room_number(dane): + m = dane.groupby(['Rooms']).count() + return(m['Id'].idxmax()) pass + def cheapest_flats(dane, n): + dane2 = dane.sort_values(by=['Expected']) + return(dane2.head(n)) pass + def find_borough(desc): dzielnice = ['Stare Miasto', 'Wilda', @@ -19,24 +39,54 @@ def find_borough(desc): 'Winogrady', 'Miłostowo', 'Dębiec'] + tekst = desc.split(" ") + for i in range(len(tekst)): + for j in range(len(dzielnice)): + if tekst[i] == dzielnice[j]: + return(dzielnice[j]) + else: + j = j + 1 + i = i + 1 + return('Inne') pass def add_borough(dane): + for i in range(5000):#len(dane.axes[0])): + dane['Borough'][i] = find_borough(dane['Location'][i]) + pass + def write_plot(dane, filename): + my_plot = dane['Borough'].hist() + fig = my_plot.get_figure() + + dir_name = 'J:/PycharmProjects/Python2017/labs06/' + filename_suffix = 'pdf' + fig.savefig(os.path.join(dir_name, filename + "." + filename_suffix)) pass + def mean_price(dane, room_number): + m = dane.groupby(['Rooms']).mean() + return(m['Expected'][room_number]) pass + def find_13(dane): + df_filtered = dane[dane['Floor'] == 13] + return(df_filtered['Borough']) pass + def find_best_flats(dane): + df_filtered = dane[dane['Floor'] == 1] + df_filtered2=df_filtered[df_filtered['Borough']=='Winogrady'] + df_filtered3 = df_filtered2[df_filtered2['Rooms'] == 3] pass + def main(): dane = wczytaj_dane() print(dane[:5]) @@ -45,7 +95,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)))