2017-12-15 14:24:17 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
2018-01-02 16:06:30 +01:00
|
|
|
|
|
|
|
import sys
|
|
|
|
reload(sys)
|
|
|
|
sys.setdefaultencoding("utf-8")
|
|
|
|
|
2017-12-16 13:00:41 +01:00
|
|
|
import pandas as pd
|
2018-01-02 15:28:01 +01:00
|
|
|
import numpy as np
|
2018-01-02 16:06:30 +01:00
|
|
|
import matplotlib
|
|
|
|
import matplotlib.pyplot as plt
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def wczytaj_dane():
|
2017-12-16 13:00:41 +01:00
|
|
|
rooms_data = pd.read_csv('mieszkania.csv', # ścieżka do pliku
|
|
|
|
sep=',', # separator
|
|
|
|
encoding='utf-8', # kodowanie
|
|
|
|
index_col='Id') # ustawienie indeksu na kolumnę Date
|
|
|
|
return rooms_data
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def most_common_room_number(dane):
|
2017-12-16 13:10:58 +01:00
|
|
|
d=dane['Rooms']
|
|
|
|
d= d.value_counts()
|
2018-01-02 15:28:01 +01:00
|
|
|
j=0
|
|
|
|
"""
|
|
|
|
for i in d:
|
|
|
|
print d.index[j] , i
|
|
|
|
j +=1
|
|
|
|
"""
|
|
|
|
d = d.index[0]
|
|
|
|
return d
|
2017-12-15 14:24:17 +01:00
|
|
|
|
2017-12-16 13:10:58 +01:00
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
def cheapest_flats(dane, n):
|
2018-01-02 15:28:01 +01:00
|
|
|
SortDane = dane.sort_values('Expected',ascending=True)
|
|
|
|
PriceCheapest = SortDane['Expected']
|
|
|
|
PriceCheapest = PriceCheapest.head(n)
|
|
|
|
return PriceCheapest
|
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-02 15:28:01 +01:00
|
|
|
for district in dzielnice:
|
|
|
|
if district in desc: return district
|
|
|
|
return 'Inne'
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
def add_borough(dane):
|
2018-01-02 16:06:30 +01:00
|
|
|
boroughArr = []
|
|
|
|
for current_location in dane:
|
|
|
|
findborough = find_borough(current_location)
|
|
|
|
#print current_location , findborough
|
|
|
|
boroughArr.append(findborough)
|
|
|
|
return pd.Series(boroughArr)
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def write_plot(dane, filename):
|
2018-01-02 16:06:30 +01:00
|
|
|
add_borough(dane)
|
|
|
|
|
|
|
|
hist_data = dane['Borough'].value_counts()
|
|
|
|
|
|
|
|
# plt.figure()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wyplot = hist_data.plot(kind='bar', alpha=0.5, title="Liczba ogloszen mieszkan z podzialem na dzielnice",
|
|
|
|
fontsize=5, figsize=(7, 5))
|
|
|
|
|
|
|
|
wyplot.set_xlabel("Dzielnice")
|
|
|
|
|
|
|
|
wyplot.set_ylabel("Liczba ogloszen")
|
|
|
|
|
|
|
|
# plt.show()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fig = wyplot.get_figure()
|
|
|
|
|
|
|
|
fig.savefig(filename)
|
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def mean_price(dane, room_number):
|
2018-01-02 15:28:01 +01:00
|
|
|
AVGdane = dane[dane.Rooms == room_number]
|
|
|
|
AVGdane = round(AVGdane.Expected.mean(),2)
|
|
|
|
return AVGdane
|
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def find_13(dane):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def find_best_flats(dane):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def main():
|
|
|
|
dane = wczytaj_dane()
|
2017-12-16 13:00:41 +01:00
|
|
|
#print(dane[:5])
|
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
|
2017-12-16 13:00:41 +01:00
|
|
|
print ("Najpopularniejsza liczba pokoi w mieszkaniu to: {}"
|
2017-12-15 14:24:17 +01:00
|
|
|
.format(most_common_room_number(dane)))
|
|
|
|
|
|
|
|
print("{} to najłądniejsza dzielnica w Poznaniu."
|
2017-12-16 13:00:41 +01:00
|
|
|
.format(find_borough("Grunwald i Jeżyce")))
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
print("Średnia cena mieszkania 3-pokojowego, to: {}"
|
|
|
|
.format(mean_price(dane, 3)))
|
|
|
|
|
2018-01-02 15:28:01 +01:00
|
|
|
roomCheapest = cheapest_flats(dane, 5)
|
|
|
|
#print roomCheapest
|
|
|
|
|
2018-01-02 16:06:30 +01:00
|
|
|
district = add_borough(dane['Location'])
|
|
|
|
dane['Borough'] = district.values
|
|
|
|
#print(dane[:5])
|
|
|
|
|
|
|
|
write_plot(dane, 'plot.png')
|
2018-01-02 15:28:01 +01:00
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|