1
0
forked from tdwojak/Python2017

task02 ok

This commit is contained in:
s45147 2017-12-23 19:18:52 +01:00
parent 6bce9cdb6a
commit 14ba0bb0ea

View File

@ -1,14 +1,24 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pandas as pd
import matplotlib.pyplot as plt
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):
pass
dane_agg = dane["Rooms"].value_counts()
return dane_agg.index.tolist()[0]
def cheapest_flats(dane, n):
pass
dane_cheapest = dane.sort_values(by=["Expected"])[:n]
return dane_cheapest
def find_borough(desc):
dzielnice = ['Stare Miasto',
@ -19,36 +29,72 @@ def find_borough(desc):
'Winogrady',
'Miłostowo',
'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):
pass
dane['Borough'] = dane['Location'].map(lambda loc: find_borough(loc))
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):
pass
ff = dane[dane['Rooms'] == room_number]
return ff['Expected'].mean()
def find_13(dane):
pass
ff = dane[dane['Floor'] == 13]
return ff['Borough'].unique()
def find_best_flats(dane):
pass
bf = dane[(dane['Rooms'] == 3) & (dane['Floor'] == 1) & (dane['Borough'] == 'Winogrady')]
return bf
def main():
dane = wczytaj_dane()
add_borough(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"))))
.format(find_borough("Grunwald i Jeżyce")))
print("Średnia cena mieszkania 3-pokojowego, to: {}"
.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__":
main()