forked from tdwojak/Python2018
95 lines
2.5 KiB
Python
Executable File
95 lines
2.5 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import pandas as pd
|
|
from matplotlib import pyplot as plt
|
|
from sklearn import linear_model
|
|
|
|
def wczytaj_dane():
|
|
data = pd.read_csv("J:/PycharmProjects/Python2018/labs06/mieszkania.csv")
|
|
return pd.DataFrame(data)
|
|
|
|
def most_common_room_number(dane):
|
|
dane2 = dane['Rooms'].value_counts().head(1)
|
|
pokoje = int(dane2.index[0])
|
|
return pokoje
|
|
|
|
def cheapest_flats(dane, n):
|
|
result = dane.sort_values('Expected').head(n)
|
|
return result
|
|
|
|
def find_borough(desc):
|
|
dzielnice = ['Stare Miasto',
|
|
'Wilda',
|
|
'Jeżyce',
|
|
'Rataje',
|
|
'Piątkowo',
|
|
'Winogrady',
|
|
'Miłostowo',
|
|
'Dębiec']
|
|
for i in range(0,len(dzielnice)):
|
|
if dzielnice[i] in desc:
|
|
result = dzielnice[i]
|
|
break
|
|
else:
|
|
result = 'Inne'
|
|
return result
|
|
|
|
def add_borough(dane):
|
|
dane['Borough'] = dane['Location'].apply(find_borough)
|
|
return dane
|
|
|
|
def write_plot(dane, filename):
|
|
dane['Borough'].value_counts().plot(kind='barh')
|
|
plt.savefig('J:/PycharmProjects/Python2018/labs06/'+filename)
|
|
return 0
|
|
|
|
def mean_price(dane, room_number):
|
|
dane2 = dane[dane.Rooms == room_number]
|
|
srednia = round(dane2.Expected.mean(),2)
|
|
return srednia
|
|
|
|
def find_13(dane):
|
|
dane2 = dane[dane.Floor == 13]
|
|
lista_dzielnic = dane2['Borough'].unique()
|
|
return lista_dzielnic
|
|
|
|
def find_best_flats(dane):
|
|
dane2 = dane[(dane['Borough']=='Winogrady') & (dane['Rooms']==3) & (dane['Floor']==1)]
|
|
return dane2
|
|
|
|
def reg_lin(dane, metraz, pokoje):
|
|
reg = linear_model.LinearRegression()
|
|
reg.fit(dane[['SqrMeters', 'Rooms']], dane['Expected'])
|
|
result = reg.predict(pd.DataFrame([(metraz, pokoje)], columns=['var1', 'var2']))
|
|
return result
|
|
|
|
"""
|
|
dane = wczytaj_dane()
|
|
print(most_common_room_number(dane))
|
|
print(cheapest_flats(dane, 2))
|
|
print(find_borough('Winogrady i Jeżyce'))
|
|
add_borough(dane)
|
|
write_plot(dane, 'wykres')
|
|
print(mean_price(dane, 3))
|
|
print(find_13(dane))
|
|
print(find_best_flats(dane).shape[0])
|
|
print(reg_lin(dane, 60, 3))
|
|
"""
|
|
|
|
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()
|