forked from tdwojak/Python2017
77 lines
1.8 KiB
Python
Executable File
77 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
import pandas as pd
|
|
import sys
|
|
import numpy as np
|
|
|
|
def wczytaj_dane():
|
|
dane=pd.read_csv('mieszkania.csv',encoding='utf-8',index_col='Id',sep=',')
|
|
return dane
|
|
pass
|
|
|
|
def most_common_room_number(dane):
|
|
dane_agg = dane["Rooms"].value_counts()
|
|
return dane_agg.index.tolist()[0]
|
|
|
|
pass
|
|
|
|
def cheapest_flats(dane, n):
|
|
dane_cheapest = dane.sort_values(by=["Expected"])[:n]
|
|
return dane_cheapest
|
|
pass
|
|
|
|
def find_borough(desc):
|
|
dzielnice = ['Stare Miasto',
|
|
'Wilda',
|
|
'Jeżyce',
|
|
'Rataje',
|
|
'Piątkowo',
|
|
'Winogrady',
|
|
'Miłostowo',
|
|
'Dębiec']
|
|
for dzielnica in dzielnice:
|
|
if desc.find(dzielnica)>=0:
|
|
return dzielnica
|
|
return 'Inne'
|
|
pass
|
|
|
|
|
|
def add_borough(dane):
|
|
dane['Borough'] = dane.apply(lambda row: find_borough(row['Location']))
|
|
pass
|
|
|
|
def write_plot(dane, filename):
|
|
dane['Borough'].hist()
|
|
plt.savefig(filename)
|
|
pass
|
|
|
|
def mean_price(dane, room_number):
|
|
dane2 = dane[dane.Rooms == room_number]
|
|
return round(dane2.Expected.mean(),5)
|
|
pass
|
|
|
|
def find_13(dane):
|
|
ff = dane[dane['Floor'] == 13]
|
|
return ff['Borough'].unique()
|
|
pass
|
|
|
|
def find_best_flats(dane):
|
|
return dane[(dane['Rooms'] == 3) & (dane['Floor'] == 1) & (dane['Borough'] == 'Winogrady')]
|
|
pass
|
|
|
|
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()
|