forked from tdwojak/Python2018
Dodaj 'labs06/task02.py'
This commit is contained in:
parent
b5dbb6ca08
commit
c5b58c514b
87
labs06/task02.py
Normal file
87
labs06/task02.py
Normal file
@ -0,0 +1,87 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import pandas as pd
|
||||
|
||||
def wczytaj_dane():
|
||||
|
||||
data = pd.read_csv('mieszkania.csv', sep = ',')
|
||||
return data
|
||||
|
||||
def most_common_room_number(dane):
|
||||
|
||||
x= dane['Rooms'].value_counts()
|
||||
return(x.index.values[0])
|
||||
|
||||
def cheapest_flats(dane, n):
|
||||
|
||||
cheap=dane.sort_values('Expected')
|
||||
return (cheap.head(n))
|
||||
|
||||
def find_borough(desc):
|
||||
|
||||
dzielnice = ['Stare Miasto',
|
||||
'Wilda',
|
||||
'Jeżyce',
|
||||
'Rataje',
|
||||
'Piątkowo',
|
||||
'Winogrady',
|
||||
'Miłostowo',
|
||||
'Dębiec']
|
||||
for dzielnica in dzielnice:
|
||||
if dzielnica in desc:
|
||||
return dzielnica
|
||||
return 'Inne'
|
||||
|
||||
def add_borough(dane):
|
||||
|
||||
values = []
|
||||
for i in dane['Location']:
|
||||
values.append(find_borough(i))
|
||||
|
||||
tempSeries = pd.Series(values)
|
||||
dane['Borough'] = tempSeries.values
|
||||
|
||||
def write_plot(dane, filename):
|
||||
|
||||
add_borough(dane)
|
||||
plot = dane['Borough'].value_counts()
|
||||
|
||||
wykres = plot.plot(kind='bar', alpha=0.5, title='Liczba mieszkań z podziałem na dzielnice', fontsize=7, figsize=(8,8))
|
||||
wykres.set_ylabel('Liczba ogloszeń')
|
||||
wykres.set_xlabel('Dzielnice')
|
||||
plik = wykres.get_figure()
|
||||
plik.savefig(filename)
|
||||
|
||||
def mean_price(dane, room_number):
|
||||
|
||||
price = dane.loc[dane['Rooms'] == room_number]
|
||||
return price['Expected'].mean()
|
||||
|
||||
def find_13(dane):
|
||||
|
||||
x = dane.loc[dane['Floor'] == 13]
|
||||
return list(set(x['Borough'].tolist()))
|
||||
|
||||
def find_best_flats(dane):
|
||||
|
||||
the_best = dane.loc[dane['Borough'] == 'Winogrady' & dane['Rooms'] == 3 & dane['Floor'] == 1]
|
||||
return the_best
|
||||
|
||||
def main():
|
||||
dane = wczytaj_dane()
|
||||
print(dane[:5])
|
||||
|
||||
print("Najpopularniejsza liczba pokoi w mieszkaniu to: {}"
|
||||
.format(most_common_room_number(dane)))
|
||||
|
||||
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)))
|
||||
|
||||
write_plot(dane, 'ogloszenia.png')
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in New Issue
Block a user