1
0
forked from tdwojak/Python2017

labs04 z1

This commit is contained in:
s45148 2018-01-06 00:11:57 +01:00
parent ad880b3674
commit e69a13c79a

View File

@ -1,23 +1,27 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import pandas as pd import pandas as pd
import sys
import numpy as np
def wczytaj_dane(): def wczytaj_dane():
my_data = pd.read_csv('mieszkania.csv', my_data = pd.read_csv('mieszkania.csv',
encoding='utf-8', encoding='utf-8',
index_col='Id') index_col='Id',
sep = ',')
return my_data return my_data
#print(my_data) #print(my_data)
def most_common_room_number(dane): def most_common_room_number(dane):
room_num = dane['Rooms'] rooms = dane['Rooms']
room_num_rank = room_num.value_counts() rooms_max = rooms.value_counts().index[0]
room_num_list = list(room_num_rank) return rooms_max
return type(room_num_rank)
#return ( room_num_list[room_num_list.index(max(room_num_list))] ) #return ( room_num_list[room_num_list.index(max(room_num_list))] )
#pass #pass
def cheapest_flats(dane, n): def cheapest_flats(dane, n):
pass expected = dane['Expected']
n_cheapest = expected.sort_values().head(n)
return n_cheapest
def find_borough(desc): def find_borough(desc):
dzielnice = ['Stare Miasto', dzielnice = ['Stare Miasto',
@ -28,23 +32,27 @@ def find_borough(desc):
'Winogrady', 'Winogrady',
'Miłostowo', 'Miłostowo',
'Dębiec'] 'Dębiec']
pass for dzielnica in dzielnice:
if dzielnica in desc:
return dzielnica
return 'Inne'
def add_borough(dane): def add_borough(dane):
pass dane['Borough'] = dane.apply(lambda row: find_borough(row['Location']))
def write_plot(dane, filename): def write_plot(dane, filename):
pass dane['Borough'].value_counts().plot.bar().get_figure().savefig(filename)
def mean_price(dane, room_number): def mean_price(dane, room_number):
pass mean_value = dane.loc[dane['Rooms'] == room_number]['Expected'].mean()
return mean_value
def find_13(dane): def find_13(dane):
pass return dane.loc[dane['Floor'] == 13]['Borough'].unique()
def find_best_flats(dane): def find_best_flats(dane):
pass best_flats = dane.loc[(df['Borough'] == 'Winogrady') & (dane['Rooms'] == 3) & (dane['Floor'] == 1)]
return best_flats
def main(): def main():
dane = wczytaj_dane() dane = wczytaj_dane()