forked from tdwojak/Python2017
117 lines
2.9 KiB
Python
Executable File
117 lines
2.9 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import sys
|
|
reload(sys)
|
|
sys.setdefaultencoding("utf-8")
|
|
|
|
import pandas as pd
|
|
|
|
|
|
def wczytaj_dane():
|
|
rooms_data = pd.read_csv('mieszkania.csv', # ścieżka do pliku
|
|
sep=',', # separator
|
|
encoding='utf-8', # kodowanie
|
|
index_col='Id') # ustawienie indeksu na kolumnę Date
|
|
return rooms_data
|
|
|
|
def most_common_room_number(dane):
|
|
d=dane['Rooms']
|
|
d= d.value_counts()
|
|
j=0
|
|
"""
|
|
for i in d:
|
|
print d.index[j] , i
|
|
j +=1
|
|
"""
|
|
d = d.index[0]
|
|
return d
|
|
|
|
|
|
def cheapest_flats(dane, n):
|
|
SortDane = dane.sort_values('Expected',ascending=True)
|
|
PriceCheapest = SortDane['Expected']
|
|
PriceCheapest = PriceCheapest.head(n)
|
|
return PriceCheapest
|
|
|
|
def find_borough(desc):
|
|
dzielnice = ['Stare Miasto',
|
|
'Wilda',
|
|
'Jeżyce',
|
|
'Rataje',
|
|
'Piątkowo',
|
|
'Winogrady',
|
|
'Miłostowo',
|
|
'Dębiec']
|
|
for district in dzielnice:
|
|
if district in desc: return district
|
|
return 'Inne'
|
|
|
|
|
|
def add_borough(dane):
|
|
boroughArr = []
|
|
for current_location in dane:
|
|
findborough = find_borough(current_location)
|
|
#print current_location , findborough
|
|
boroughArr.append(findborough)
|
|
return pd.Series(boroughArr)
|
|
|
|
def write_plot(dane, filename):
|
|
add_borough(dane)
|
|
hist_data = dane['Borough'].value_counts()
|
|
Hist_out = hist_data.plot(kind='bar', alpha=0.5, title="Appartments in Distrinct",fontsize=5, figsize=(7, 5))
|
|
fig = Hist_out.get_figure()
|
|
fig.savefig(filename)
|
|
|
|
def mean_price(dane, room_number):
|
|
AVGdane = dane[dane.Rooms == room_number]
|
|
AVGdane = round(AVGdane.Expected.mean(),2)
|
|
return AVGdane
|
|
|
|
|
|
def find_13(dane):
|
|
add_borough(dane)
|
|
List_13 = []
|
|
WhatLookFor = dane['Borough'].loc[dane['Floor'] == 13]
|
|
for j in WhatLookFor:
|
|
List_13.append(j)
|
|
return List_13
|
|
|
|
def find_best_flats(dane):
|
|
add_borough(dane)
|
|
TheBest = dane[(dane.Borough == 'Winogrady') & (dane.Rooms == 3) & (dane.Floor == 1)]
|
|
return TheBest
|
|
|
|
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)))
|
|
|
|
roomCheapest = cheapest_flats(dane, 5)
|
|
print roomCheapest
|
|
|
|
district = add_borough(dane['Location'])
|
|
dane['Borough'] = district.values
|
|
#print(dane[:5])
|
|
|
|
write_plot(dane, 'plot.png')
|
|
|
|
list_13 = find_13(dane)
|
|
print list_13
|
|
|
|
TheBestFlat = find_best_flats(dane)
|
|
print TheBestFlat['Location']
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|