1
0
forked from tdwojak/Python2017

Zadanie domowe labs06

This commit is contained in:
s45166 2018-01-19 21:55:49 +01:00
parent 457d5f2146
commit 6cf371942e

View File

@ -1,14 +1,25 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import pandas as pd
def wczytaj_dane(): def wczytaj_dane():
pass
mieszkania = pd.read_csv('C:\Users\mlyska\Documents\python2017\labs06\mieszkania.csv', sep = ',')
mieszkania.fillna('', inplace=True)
mieszkania['Description'] = mieszkania['Description'] + mieszkania['Unnamed: 7'] + mieszkania['Unnamed: 8'] + \
mieszkania['Unnamed: 9'] + mieszkania['Unnamed: 10'] + mieszkania['Unnamed: 11']
mieszkania.drop(['Unnamed: 7','Unnamed: 8','Unnamed: 9','Unnamed: 10','Unnamed: 11'], 1, inplace=True)
return mieszkania
def most_common_room_number(dane): def most_common_room_number(dane):
pass counter = dane['Rooms'].value_counts()
maxCount = counter.to_frame()
return maxCount.index.values[0]
def cheapest_flats(dane, n): def cheapest_flats(dane, n):
pass dane.sort_values('Expected')
return dane.head(n)
def find_borough(desc): def find_borough(desc):
dzielnice = ['Stare Miasto', dzielnice = ['Stare Miasto',
@ -19,23 +30,46 @@ def find_borough(desc):
'Winogrady', 'Winogrady',
'Miłostowo', 'Miłostowo',
'Dębiec'] 'Dębiec']
pass
for i in dzielnice:
if i in desc:
return i
break
if desc not in dzielnice:
return 'Inne'
def add_borough(dane): def add_borough(dane):
pass values = []
for i in dane['Location']:
values.append(find_borough(i))
tempSeries = pd.Series(values)
dane['Borough'] = tempSeries.values
def write_plot(dane, filename): def write_plot(dane, filename):
pass add_borough(dane)
dataPlot = dane['Borough'].value_counts()
imgPlot = dataPlot.plot(kind='bar', alpha=0.5, title='Liczba ogloszen mieszkan z podzialem na dzielnice', fontsize=6, figsize=(8,7))
imgPlot.set_ylabel('Liczba ogloszen')
imgPlot.set_xlabel('Dzielnice')
filePlot = imgPlot.get_figure()
filePlot.savefig(filename)
def mean_price(dane, room_number): def mean_price(dane, room_number):
pass x = dane.loc[dane['Rooms'] == room_number]
return x['Expected'].mean()
def find_13(dane): def find_13(dane):
pass x = dane.loc[dane['Floor'] == 13]
return list(set(x['Borough'].tolist()))
def find_best_flats(dane): def find_best_flats(dane):
pass best = dane.loc[dane['Borough'] == 'Winogrady' & dane['Rooms'] == 3 & dane['Floor'] == 1]
return best
def main(): def main():
dane = wczytaj_dane() dane = wczytaj_dane()
@ -45,10 +79,12 @@ def main():
.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)))
write_plot(dane, 'ogloszenia.png')
if __name__ == "__main__": if __name__ == "__main__":
main() main()