2017-12-15 14:24:17 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
2017-12-23 19:18:52 +01:00
|
|
|
import pandas as pd
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def wczytaj_dane():
|
2017-12-23 19:18:52 +01:00
|
|
|
csv_data = pd.read_csv('mieszkania.csv', index_col='Id')
|
|
|
|
return pd.DataFrame(csv_data)
|
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def most_common_room_number(dane):
|
2017-12-23 19:18:52 +01:00
|
|
|
|
|
|
|
dane_agg = dane["Rooms"].value_counts()
|
|
|
|
return dane_agg.index.tolist()[0]
|
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def cheapest_flats(dane, n):
|
2017-12-23 19:18:52 +01:00
|
|
|
dane_cheapest = dane.sort_values(by=["Expected"])[:n]
|
|
|
|
return dane_cheapest
|
|
|
|
|
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-23 19:18:52 +01:00
|
|
|
first = ""
|
|
|
|
found = False
|
|
|
|
for dz in dzielnice:
|
|
|
|
if dz in desc:
|
|
|
|
first = dz
|
|
|
|
found = True
|
|
|
|
break
|
|
|
|
|
|
|
|
if not found:
|
|
|
|
return 'Inne'
|
|
|
|
else:
|
|
|
|
return first
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
def add_borough(dane):
|
2017-12-23 19:18:52 +01:00
|
|
|
dane['Borough'] = dane['Location'].map(lambda loc: find_borough(loc))
|
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def write_plot(dane, filename):
|
2017-12-23 19:18:52 +01:00
|
|
|
|
|
|
|
dane['Borough'].value_counts().plot(kind='bar', figsize = (10, 10))
|
|
|
|
plt.savefig(filename)
|
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def mean_price(dane, room_number):
|
2017-12-23 19:18:52 +01:00
|
|
|
ff = dane[dane['Rooms'] == room_number]
|
|
|
|
return ff['Expected'].mean()
|
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def find_13(dane):
|
2017-12-23 19:18:52 +01:00
|
|
|
|
|
|
|
ff = dane[dane['Floor'] == 13]
|
|
|
|
return ff['Borough'].unique()
|
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def find_best_flats(dane):
|
2017-12-23 19:18:52 +01:00
|
|
|
|
|
|
|
bf = dane[(dane['Rooms'] == 3) & (dane['Floor'] == 1) & (dane['Borough'] == 'Winogrady')]
|
|
|
|
return bf
|
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
def main():
|
2017-12-23 19:18:52 +01:00
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
dane = wczytaj_dane()
|
2017-12-23 19:18:52 +01:00
|
|
|
add_borough(dane)
|
2017-12-15 14:24:17 +01:00
|
|
|
print(dane[:5])
|
|
|
|
|
2017-12-23 19:18:52 +01:00
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
print("Najpopularniejsza liczba pokoi w mieszkaniu to: {}"
|
|
|
|
.format(most_common_room_number(dane)))
|
|
|
|
|
|
|
|
print("{} to najłądniejsza dzielnica w Poznaniu."
|
2017-12-23 19:18:52 +01:00
|
|
|
.format(find_borough("Grunwald i Jeżyce")))
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
print("Średnia cena mieszkania 3-pokojowego, to: {}"
|
2017-12-23 19:18:52 +01:00
|
|
|
.format(mean_price(dane, 3)))
|
|
|
|
|
|
|
|
print("Dzielnice z mieszkaniami na 13 piętrze, to: {}"
|
|
|
|
.format(find_13(dane)))
|
|
|
|
|
|
|
|
ile = 10
|
|
|
|
print("Najtańsze oferty mieszkań, to: {}"
|
|
|
|
.format(cheapest_flats(dane, ile)))
|
|
|
|
|
|
|
|
write_plot(dane, 'mieszkania_plot.png')
|
|
|
|
|
2017-12-15 14:24:17 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2017-12-23 19:18:52 +01:00
|
|
|
main()
|