forked from tdwojak/Python2018
task02 ready (without extra task 10)
This commit is contained in:
parent
aee299ad3b
commit
95f6c11a79
61
labs06/task02.py
Executable file → Normal file
61
labs06/task02.py
Executable file → Normal file
@ -1,14 +1,21 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
|
||||
def wczytaj_dane():
|
||||
pass
|
||||
return pd.read_csv('mieszkania.csv')
|
||||
|
||||
|
||||
def most_common_room_number(dane):
|
||||
pass
|
||||
return dane.Rooms.value_counts().index[0]
|
||||
|
||||
|
||||
def cheapest_flats(dane, n):
|
||||
pass
|
||||
return dane.sort_values(by=['Expected'], ascending=False).head(n)
|
||||
|
||||
|
||||
def find_borough(desc):
|
||||
dzielnice = ['Stare Miasto',
|
||||
@ -19,23 +26,44 @@ def find_borough(desc):
|
||||
'Winogrady',
|
||||
'Miłostowo',
|
||||
'Dębiec']
|
||||
pass
|
||||
|
||||
common_boroughs = list(set(desc.split()).intersection(dzielnice))
|
||||
if not common_boroughs:
|
||||
return "Inne"
|
||||
else:
|
||||
return str(common_boroughs[0])
|
||||
|
||||
|
||||
def add_borough(dane):
|
||||
pass
|
||||
dane['Borough'] = dane.Location.apply(lambda el: find_borough(str(el)))
|
||||
|
||||
|
||||
def write_plot(dane, filename):
|
||||
pass
|
||||
column_names = list(dane.Borough.value_counts().index)
|
||||
x_pos = np.arange(len(column_names))
|
||||
y_pos = list(dane.Borough.value_counts())
|
||||
|
||||
plt.bar(x_pos, y_pos, align='center')
|
||||
plt.xticks(x_pos, column_names)
|
||||
plt.xlabel('Dzielnica')
|
||||
plt.ylabel('Liczba ogłoszeń')
|
||||
plt.title('Liczba ogłoszeń mieszkaniowych z podziałem na dzielnice')
|
||||
|
||||
img = plt.gcf()
|
||||
img.savefig(filename)
|
||||
|
||||
|
||||
def mean_price(dane, room_number):
|
||||
pass
|
||||
return dane.Expected[dane.Rooms == room_number].mean()
|
||||
|
||||
|
||||
def find_13(dane):
|
||||
pass
|
||||
return dane.Borough[dane.Floor == 13].unique()
|
||||
|
||||
|
||||
def find_best_flats(dane):
|
||||
pass
|
||||
return dane[(dane.Borough == 'Winogrady') & (dane.Rooms == 3) & (dane.Floor == 1)]
|
||||
|
||||
|
||||
def main():
|
||||
dane = wczytaj_dane()
|
||||
@ -44,11 +72,22 @@ def main():
|
||||
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("{} to najładniejsza dzielnica w Poznaniu."
|
||||
.format(find_borough("Grunwald i Jeżyce")))
|
||||
|
||||
print("Średnia cena mieszkania 3-pokojowego, to: {}"
|
||||
.format(mean_price(dane, 3)))
|
||||
|
||||
add_borough(dane)
|
||||
|
||||
print("Lista dzielnic, które zawierają ofertę mieszkania na 13 piętrze: {}"
|
||||
.format(', '.join(find_13(dane))))
|
||||
|
||||
write_plot(dane, "test")
|
||||
|
||||
# print("Oferty mieszkań, które znajdują się na Winogradach, mają 3 pokoje i są na 1 piętrze:")
|
||||
# print(find_best_flats(dane))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
BIN
labs06/test.png
Normal file
BIN
labs06/test.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
Loading…
Reference in New Issue
Block a user