1
0
forked from tdwojak/Python2017
Python2017/labs06/task02.py
2018-01-26 14:57:33 +01:00

89 lines
2.1 KiB
Python
Executable File

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pandas as pd
import statistics
def wczytaj_dane():
raw_data = pd.read_csv('mieszkania.csv',sep=',')
data = pd.DataFrame(raw_data)
return data
def most_common_room_number(dane):
rooms=dane['Rooms']
return(int(statistics.mode(rooms)))
def cheapest_flats(dane, n):
cheapest=pd.DataFrame(dane['Expected'])
cheapest.sort=cheapest.sort_values(by=['Expected'])
return cheapest.sort[:n]
def find_borough(desc):
dzielnice = ['Stare Miasto',
'Wilda',
'Jeżyce',
'Rataje',
'Piątkowo',
'Winogrady',
'Miłostowo',
'Dębiec']
for dzielnica in dzielnice:
if desc.find(dzielnica)!=-1:
return dzielnica
return 'Inne'
def add_borough(dane):
borough_list=[]
for data in dane['Location']:
borough_list.append(find_borough(data))
borough_series = pd.Series(borough_list,name='Borough')
dane['Borough']=borough_series
return dane
def write_plot(dane, filename):
data = add_borough(dane)
plot_data = data.groupby(dane['Borough']).size()
plt = plot_data.plot.bar()
fig = plt.get_figure()
fig.savefig('{}.png'.format(filename))
return 0
def mean_price(dane, room_number):
data=dane.loc[dane['Rooms'] == room_number]
return round(statistics.mean(data['Expected']),2)
def find_13(dane):
data = add_borough(dane)
boroughs = data.loc[data['Floor'] == 13]
return set(boroughs['Borough'])
def find_best_flats(dane):
data = add_borough(dane)
best_flats = data.loc[(data['Borough'] == 'Winogrady') & (data['Floor'] == 1) & (data['Rooms'] == 3)]
return best_flats
def main():
dane = wczytaj_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")))
print("Średnia cena mieszkania 3-pokojowego, to: {}"
.format(mean_price(dane, 3)))
if __name__ == "__main__":
main()