forked from tdwojak/Python2018
66 lines
1.7 KiB
Python
66 lines
1.7 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import pandas as pd
|
|
import matplotlib.pyplot as plt
|
|
|
|
def wczytaj_dane():
|
|
dane = pd.read_csv("./mieszkania.csv")
|
|
return dane
|
|
|
|
def most_common_room_number(dane):
|
|
return dane.Rooms.value_counts().idxmax()
|
|
|
|
def cheapest_flats(dane, n):
|
|
return dane.sort('Expected').head(n)
|
|
|
|
def find_borough(desc):
|
|
dzielnice = ['Stare Miasto',
|
|
'Wilda',
|
|
'Jeżyce',
|
|
'Rataje',
|
|
'Piątkowo',
|
|
'Winogrady',
|
|
'Miłostowo',
|
|
'Dębiec']
|
|
for dzielnica in dzielnice:
|
|
list = desc.split(' ')
|
|
for element in list:
|
|
if len(element) > 2 and element == dzielnica:
|
|
return dzielnica
|
|
break
|
|
return "Inne"
|
|
|
|
def add_borough(dane):
|
|
dane['Borough'] = dane['Location'].apply(find_borough)
|
|
return dane
|
|
|
|
def write_plot(dane, filename):
|
|
dane['Borough'].value_counts().plot.bar().get_figure().savefig(filename)
|
|
|
|
def mean_price(dane, room_number):
|
|
mean_price = dane.Expected[(dane['Rooms'] == room_number)]
|
|
return mean_price.mean()
|
|
|
|
def find_13(dane):
|
|
return dane.Location[(dane['Floor'] == 13)].unique()
|
|
|
|
def find_best_flats(dane):
|
|
return dane[(dane['Location'] == 'Winogrady') & (dane['Rooms'] == 3) & (dane['Floor'] == 1)]
|
|
|
|
def main():
|
|
dane = wczytaj_dane()
|
|
print(dane[:5])
|
|
|
|
print("Najpopularniejsza liczba pokoi w mieszkaniu to: {}"
|
|
.format(most_common_room_number(dane)))
|
|
|
|
print("{} to najłądniejsza dzielnica w Poznaniu."
|
|
.format(find_borough("Grunwald i Jeżyce")))
|
|
|
|
print("Średnia cena mieszkania 3-pokojowego, to: {}"
|
|
.format(mean_price(dane, 3)))
|
|
|
|
if __name__ == "__main__":
|
|
main()
|