forked from tdwojak/Python2018
laboratoria4
This commit is contained in:
parent
2ea7ef9e52
commit
4d03009ff6
@ -1,14 +1,22 @@
|
||||
#!/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():
|
||||
pass
|
||||
data = pd.read_csv("J:/PycharmProjects/Python2018/labs06/mieszkania.csv")
|
||||
return pd.DataFrame(data)
|
||||
|
||||
def most_common_room_number(dane):
|
||||
pass
|
||||
dane2 = dane['Rooms'].value_counts().head(1)
|
||||
pokoje = int(dane2.index[0])
|
||||
return pokoje
|
||||
|
||||
def cheapest_flats(dane, n):
|
||||
pass
|
||||
result = dane.sort_values('Expected').head(n)
|
||||
return result
|
||||
|
||||
def find_borough(desc):
|
||||
dzielnice = ['Stare Miasto',
|
||||
@ -19,23 +27,55 @@ def find_borough(desc):
|
||||
'Winogrady',
|
||||
'Miłostowo',
|
||||
'Dębiec']
|
||||
pass
|
||||
|
||||
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):
|
||||
pass
|
||||
dane['Borough'] = dane['Location'].apply(find_borough)
|
||||
return dane
|
||||
|
||||
def write_plot(dane, filename):
|
||||
pass
|
||||
dane['Borough'].value_counts().plot(kind='barh')
|
||||
plt.savefig('J:/PycharmProjects/Python2018/labs06/'+filename)
|
||||
return 0
|
||||
|
||||
def mean_price(dane, room_number):
|
||||
pass
|
||||
dane2 = dane[dane.Rooms == room_number]
|
||||
srednia = round(dane2.Expected.mean(),2)
|
||||
return srednia
|
||||
|
||||
def find_13(dane):
|
||||
pass
|
||||
dane2 = dane[dane.Floor == 13]
|
||||
lista_dzielnic = dane2['Borough'].unique()
|
||||
return lista_dzielnic
|
||||
|
||||
def find_best_flats(dane):
|
||||
pass
|
||||
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()
|
||||
@ -45,7 +85,7 @@ def main():
|
||||
.format(most_common_room_number(dane)))
|
||||
|
||||
print("{} to najłądniejsza dzielnica w Poznaniu."
|
||||
.format(find_borough("Grunwald i Jeżyce"))))
|
||||
.format(find_borough("Grunwald i Jeżyce")))
|
||||
|
||||
print("Średnia cena mieszkania 3-pokojowego, to: {}"
|
||||
.format(mean_price(dane, 3)))
|
||||
|
Loading…
Reference in New Issue
Block a user