2017-12-15 14:24:17 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2017-12-25 12:08:16 +01:00
|
|
|
import pandas as pd
|
|
|
|
import matplotlib
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
def wczytaj_dane():
|
2017-12-25 12:08:16 +01:00
|
|
|
dane = pd.read_csv('mieszkania.csv',
|
|
|
|
sep=',',
|
|
|
|
encoding='utf-8')
|
|
|
|
return dane
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def most_common_room_number(dane):
|
2017-12-25 12:08:16 +01:00
|
|
|
return dane.Rooms.mode()[0]
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def cheapest_flats(dane, n):
|
2017-12-25 12:08:16 +01:00
|
|
|
dane = dane.sort_values('Expected',ascending=True)
|
|
|
|
return dane.head(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']
|
2017-12-25 12:08:16 +01:00
|
|
|
|
|
|
|
for dzielnica in dzielnice:
|
|
|
|
if desc.find(dzielnica)>=0:
|
|
|
|
return dzielnica
|
|
|
|
|
|
|
|
return 'Inne'
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
def add_borough(dane):
|
2017-12-25 12:08:16 +01:00
|
|
|
borough = []
|
|
|
|
for current_location in dane:
|
|
|
|
borough.append(find_borough(current_location))
|
|
|
|
return pd.Series(borough)
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def write_plot(dane, filename):
|
2017-12-25 12:08:16 +01:00
|
|
|
dane['Borough'].hist()
|
|
|
|
plt.savefig(filename)
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def mean_price(dane, room_number):
|
2017-12-25 12:08:16 +01:00
|
|
|
dane = dane[dane.Rooms == room_number]
|
|
|
|
return round(dane.Expected.mean(),2)
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def find_13(dane):
|
2017-12-25 12:08:16 +01:00
|
|
|
dane = dane[dane.Floor == 13]
|
|
|
|
return list(dane.Borough)
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def find_best_flats(dane):
|
2017-12-25 12:08:16 +01:00
|
|
|
dane = dane[(dane.Borough=='Winogrady') & (dane.Rooms==3) & (dane.Floor == 1)]
|
|
|
|
return dane
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def main():
|
|
|
|
dane = wczytaj_dane()
|
|
|
|
print(dane[:5])
|
|
|
|
|
|
|
|
print("Najpopularniejsza liczba pokoi w mieszkaniu to: {}"
|
|
|
|
.format(most_common_room_number(dane)))
|
|
|
|
|
2017-12-25 12:08:16 +01:00
|
|
|
najtansze = cheapest_flats(dane,10)
|
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
print("{} to najłądniejsza dzielnica w Poznaniu."
|
2017-12-25 12:08:16 +01:00
|
|
|
.format(find_borough("Grunwald i Jeżyce")))
|
|
|
|
|
|
|
|
dzielnice = add_borough(dane['Location'])
|
|
|
|
dane['Borough'] = dzielnice.values
|
|
|
|
|
|
|
|
write_plot(dane,'wykres.png')
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
print("Średnia cena mieszkania 3-pokojowego, to: {}"
|
|
|
|
.format(mean_price(dane, 3)))
|
|
|
|
|
2017-12-25 12:08:16 +01:00
|
|
|
find_13(dane)
|
|
|
|
|
|
|
|
find_best_flats(dane)
|
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|