2018-06-03 10:04:16 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
2018-06-03 12:40:42 +02:00
|
|
|
import pandas as pd
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
import numpy as np
|
|
|
|
|
2018-06-03 10:04:16 +02:00
|
|
|
|
|
|
|
def wczytaj_dane():
|
2018-06-03 12:40:42 +02:00
|
|
|
return pd.read_csv('mieszkania.csv')
|
|
|
|
|
2018-06-03 10:04:16 +02:00
|
|
|
|
|
|
|
def most_common_room_number(dane):
|
2018-06-03 12:40:42 +02:00
|
|
|
return dane.Rooms.value_counts().index[0]
|
|
|
|
|
2018-06-03 10:04:16 +02:00
|
|
|
|
|
|
|
def cheapest_flats(dane, n):
|
2018-06-03 12:40:42 +02:00
|
|
|
return dane.sort_values(by=['Expected'], ascending=False).head(n)
|
|
|
|
|
2018-06-03 10:04:16 +02:00
|
|
|
|
|
|
|
def find_borough(desc):
|
|
|
|
dzielnice = ['Stare Miasto',
|
|
|
|
'Wilda',
|
|
|
|
'Jeżyce',
|
|
|
|
'Rataje',
|
|
|
|
'Piątkowo',
|
|
|
|
'Winogrady',
|
|
|
|
'Miłostowo',
|
|
|
|
'Dębiec']
|
2018-06-03 12:40:42 +02:00
|
|
|
|
|
|
|
common_boroughs = list(set(desc.split()).intersection(dzielnice))
|
|
|
|
if not common_boroughs:
|
|
|
|
return "Inne"
|
|
|
|
else:
|
|
|
|
return str(common_boroughs[0])
|
2018-06-03 10:04:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
def add_borough(dane):
|
2018-06-03 12:40:42 +02:00
|
|
|
dane['Borough'] = dane.Location.apply(lambda el: find_borough(str(el)))
|
|
|
|
|
2018-06-03 10:04:16 +02:00
|
|
|
|
|
|
|
def write_plot(dane, filename):
|
2018-06-03 12:40:42 +02:00
|
|
|
column_names = list(dane.Borough.value_counts().index)
|
|
|
|
x_pos = np.arange(len(column_names))
|
|
|
|
y_pos = list(dane.Borough.value_counts())
|
|
|
|
|
|
|
|
plt.bar(x_pos, y_pos, align='center')
|
|
|
|
plt.xticks(x_pos, column_names)
|
|
|
|
plt.xlabel('Dzielnica')
|
|
|
|
plt.ylabel('Liczba ogłoszeń')
|
|
|
|
plt.title('Liczba ogłoszeń mieszkaniowych z podziałem na dzielnice')
|
|
|
|
|
|
|
|
img = plt.gcf()
|
|
|
|
img.savefig(filename)
|
|
|
|
|
2018-06-03 10:04:16 +02:00
|
|
|
|
|
|
|
def mean_price(dane, room_number):
|
2018-06-03 12:40:42 +02:00
|
|
|
return dane.Expected[dane.Rooms == room_number].mean()
|
|
|
|
|
2018-06-03 10:04:16 +02:00
|
|
|
|
|
|
|
def find_13(dane):
|
2018-06-03 12:40:42 +02:00
|
|
|
return dane.Borough[dane.Floor == 13].unique()
|
|
|
|
|
2018-06-03 10:04:16 +02:00
|
|
|
|
|
|
|
def find_best_flats(dane):
|
2018-06-03 12:40:42 +02:00
|
|
|
return dane[(dane.Borough == 'Winogrady') & (dane.Rooms == 3) & (dane.Floor == 1)]
|
|
|
|
|
2018-06-03 10:04:16 +02:00
|
|
|
|
|
|
|
def main():
|
|
|
|
dane = wczytaj_dane()
|
|
|
|
print(dane[:5])
|
|
|
|
|
|
|
|
print("Najpopularniejsza liczba pokoi w mieszkaniu to: {}"
|
|
|
|
.format(most_common_room_number(dane)))
|
|
|
|
|
2018-06-03 12:40:42 +02:00
|
|
|
print("{} to najładniejsza dzielnica w Poznaniu."
|
|
|
|
.format(find_borough("Grunwald i Jeżyce")))
|
2018-06-03 10:04:16 +02:00
|
|
|
|
|
|
|
print("Średnia cena mieszkania 3-pokojowego, to: {}"
|
|
|
|
.format(mean_price(dane, 3)))
|
|
|
|
|
2018-06-03 12:40:42 +02:00
|
|
|
add_borough(dane)
|
|
|
|
|
|
|
|
print("Lista dzielnic, które zawierają ofertę mieszkania na 13 piętrze: {}"
|
|
|
|
.format(', '.join(find_13(dane))))
|
|
|
|
|
|
|
|
write_plot(dane, "test")
|
|
|
|
|
|
|
|
# print("Oferty mieszkań, które znajdują się na Winogradach, mają 3 pokoje i są na 1 piętrze:")
|
|
|
|
# print(find_best_flats(dane))
|
|
|
|
|
|
|
|
|
2018-06-03 10:04:16 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|