task02 ok
This commit is contained in:
parent
6bce9cdb6a
commit
14ba0bb0ea
@ -1,14 +1,24 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import pandas as pd
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
|
||||||
def wczytaj_dane():
|
def wczytaj_dane():
|
||||||
pass
|
csv_data = pd.read_csv('mieszkania.csv', index_col='Id')
|
||||||
|
return pd.DataFrame(csv_data)
|
||||||
|
|
||||||
|
|
||||||
def most_common_room_number(dane):
|
def most_common_room_number(dane):
|
||||||
pass
|
|
||||||
|
dane_agg = dane["Rooms"].value_counts()
|
||||||
|
return dane_agg.index.tolist()[0]
|
||||||
|
|
||||||
|
|
||||||
def cheapest_flats(dane, n):
|
def cheapest_flats(dane, n):
|
||||||
pass
|
dane_cheapest = dane.sort_values(by=["Expected"])[:n]
|
||||||
|
return dane_cheapest
|
||||||
|
|
||||||
|
|
||||||
def find_borough(desc):
|
def find_borough(desc):
|
||||||
dzielnice = ['Stare Miasto',
|
dzielnice = ['Stare Miasto',
|
||||||
@ -19,36 +29,72 @@ def find_borough(desc):
|
|||||||
'Winogrady',
|
'Winogrady',
|
||||||
'Miłostowo',
|
'Miłostowo',
|
||||||
'Dębiec']
|
'Dębiec']
|
||||||
pass
|
first = ""
|
||||||
|
found = False
|
||||||
|
for dz in dzielnice:
|
||||||
|
if dz in desc:
|
||||||
|
first = dz
|
||||||
|
found = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if not found:
|
||||||
|
return 'Inne'
|
||||||
|
else:
|
||||||
|
return first
|
||||||
|
|
||||||
|
|
||||||
def add_borough(dane):
|
def add_borough(dane):
|
||||||
pass
|
dane['Borough'] = dane['Location'].map(lambda loc: find_borough(loc))
|
||||||
|
|
||||||
|
|
||||||
def write_plot(dane, filename):
|
def write_plot(dane, filename):
|
||||||
pass
|
|
||||||
|
dane['Borough'].value_counts().plot(kind='bar', figsize = (10, 10))
|
||||||
|
plt.savefig(filename)
|
||||||
|
|
||||||
|
|
||||||
def mean_price(dane, room_number):
|
def mean_price(dane, room_number):
|
||||||
pass
|
ff = dane[dane['Rooms'] == room_number]
|
||||||
|
return ff['Expected'].mean()
|
||||||
|
|
||||||
|
|
||||||
def find_13(dane):
|
def find_13(dane):
|
||||||
pass
|
|
||||||
|
ff = dane[dane['Floor'] == 13]
|
||||||
|
return ff['Borough'].unique()
|
||||||
|
|
||||||
|
|
||||||
def find_best_flats(dane):
|
def find_best_flats(dane):
|
||||||
pass
|
|
||||||
|
bf = dane[(dane['Rooms'] == 3) & (dane['Floor'] == 1) & (dane['Borough'] == 'Winogrady')]
|
||||||
|
return bf
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
dane = wczytaj_dane()
|
dane = wczytaj_dane()
|
||||||
|
add_borough(dane)
|
||||||
print(dane[:5])
|
print(dane[:5])
|
||||||
|
|
||||||
|
|
||||||
print("Najpopularniejsza liczba pokoi w mieszkaniu to: {}"
|
print("Najpopularniejsza liczba pokoi w mieszkaniu to: {}"
|
||||||
.format(most_common_room_number(dane)))
|
.format(most_common_room_number(dane)))
|
||||||
|
|
||||||
print("{} to najłądniejsza dzielnica w Poznaniu."
|
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: {}"
|
print("Średnia cena mieszkania 3-pokojowego, to: {}"
|
||||||
.format(mean_price(dane, 3)))
|
.format(mean_price(dane, 3)))
|
||||||
|
|
||||||
|
print("Dzielnice z mieszkaniami na 13 piętrze, to: {}"
|
||||||
|
.format(find_13(dane)))
|
||||||
|
|
||||||
|
ile = 10
|
||||||
|
print("Najtańsze oferty mieszkań, to: {}"
|
||||||
|
.format(cheapest_flats(dane, ile)))
|
||||||
|
|
||||||
|
write_plot(dane, 'mieszkania_plot.png')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
Loading…
Reference in New Issue
Block a user