2018-01-26 14:57:33 +01:00
|
|
|
#!/usr/bin/env python
|
2017-12-15 14:24:17 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2018-01-26 14:57:33 +01:00
|
|
|
|
2018-01-26 14:27:56 +01:00
|
|
|
import pandas as pd
|
2018-01-26 14:57:33 +01:00
|
|
|
import statistics
|
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
def wczytaj_dane():
|
2018-01-26 14:57:33 +01:00
|
|
|
raw_data = pd.read_csv('mieszkania.csv',sep=',')
|
|
|
|
data = pd.DataFrame(raw_data)
|
|
|
|
return data
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def most_common_room_number(dane):
|
2018-01-26 14:57:33 +01:00
|
|
|
rooms=dane['Rooms']
|
|
|
|
return(int(statistics.mode(rooms)))
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def cheapest_flats(dane, n):
|
2018-01-26 14:57:33 +01:00
|
|
|
cheapest=pd.DataFrame(dane['Expected'])
|
|
|
|
cheapest.sort=cheapest.sort_values(by=['Expected'])
|
|
|
|
return cheapest.sort[:n]
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def find_borough(desc):
|
|
|
|
dzielnice = ['Stare Miasto',
|
|
|
|
'Wilda',
|
|
|
|
'Jeżyce',
|
|
|
|
'Rataje',
|
|
|
|
'Piątkowo',
|
|
|
|
'Winogrady',
|
|
|
|
'Miłostowo',
|
|
|
|
'Dębiec']
|
2018-01-26 14:57:33 +01:00
|
|
|
for dzielnica in dzielnice:
|
|
|
|
if desc.find(dzielnica)!=-1:
|
|
|
|
return dzielnica
|
|
|
|
return 'Inne'
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
def add_borough(dane):
|
2018-01-26 14:57:33 +01:00
|
|
|
borough_list=[]
|
|
|
|
for data in dane['Location']:
|
|
|
|
borough_list.append(find_borough(data))
|
|
|
|
borough_series = pd.Series(borough_list,name='Borough')
|
|
|
|
dane['Borough']=borough_series
|
2018-01-26 14:27:56 +01:00
|
|
|
return dane
|
2017-12-15 14:24:17 +01:00
|
|
|
|
2018-01-26 14:57:33 +01:00
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
def write_plot(dane, filename):
|
2018-01-26 14:57:33 +01:00
|
|
|
data = add_borough(dane)
|
|
|
|
plot_data = data.groupby(dane['Borough']).size()
|
|
|
|
plt = plot_data.plot.bar()
|
|
|
|
fig = plt.get_figure()
|
|
|
|
fig.savefig('{}.png'.format(filename))
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def mean_price(dane, room_number):
|
2018-01-26 14:57:33 +01:00
|
|
|
data=dane.loc[dane['Rooms'] == room_number]
|
|
|
|
return round(statistics.mean(data['Expected']),2)
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def find_13(dane):
|
2018-01-26 14:57:33 +01:00
|
|
|
data = add_borough(dane)
|
|
|
|
boroughs = data.loc[data['Floor'] == 13]
|
|
|
|
return set(boroughs['Borough'])
|
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def find_best_flats(dane):
|
2018-01-26 14:57:33 +01:00
|
|
|
data = add_borough(dane)
|
|
|
|
best_flats = data.loc[(data['Borough'] == 'Winogrady') & (data['Floor'] == 1) & (data['Rooms'] == 3)]
|
|
|
|
return best_flats
|
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def main():
|
|
|
|
dane = wczytaj_dane()
|
|
|
|
print(dane[:5])
|
2018-01-26 14:57:33 +01:00
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
print("Najpopularniejsza liczba pokoi w mieszkaniu to: {}"
|
|
|
|
.format(most_common_room_number(dane)))
|
2018-01-26 14:57:33 +01:00
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
print("{} to najłądniejsza dzielnica w Poznaniu."
|
2018-01-26 14:27:56 +01:00
|
|
|
.format(find_borough("Grunwald i Jeżyce")))
|
2018-01-26 14:57:33 +01:00
|
|
|
|
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
print("Średnia cena mieszkania 3-pokojowego, to: {}"
|
|
|
|
.format(mean_price(dane, 3)))
|
2018-01-26 14:57:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
if __name__ == "__main__":
|
2018-01-26 14:57:33 +01:00
|
|
|
main()
|