1
0
forked from tdwojak/Python2017

lab 6 filled

This commit is contained in:
s45163 2018-01-20 19:02:56 +01:00
parent bd731bbc44
commit 3fa9c4f31f

View File

@ -1,54 +1,77 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def wczytaj_dane():
pass
def most_common_room_number(dane):
pass
def cheapest_flats(dane, n):
pass
def find_borough(desc):
dzielnice = ['Stare Miasto',
'Wilda',
'Jeżyce',
'Rataje',
'Piątkowo',
'Winogrady',
'Miłostowo',
'Dębiec']
pass
import pandas as pd
import matplotlib.pyplot as plt
def add_borough(dane):
pass
def wczytaj_dane ( ):
return pd.read_csv ( 'mieszkania.csv' )
def write_plot(dane, filename):
pass
def mean_price(dane, room_number):
pass
def most_common_room_number ( dane ):
return dane[ 'Rooms' ].value_counts ( )
def find_13(dane):
pass
def find_best_flats(dane):
pass
def cheapest_flats ( dane , n ):
cheapest = dane[ [ 'Expected' , 'Location' ] ].sort_values ( by=[ "Expected" ] , ascending=False )
return cheapest[ :n ]
def main():
dane = wczytaj_dane()
print(dane[:5])
print("Najpopularniejsza liczba pokoi w mieszkaniu to: {}"
.format(most_common_room_number(dane)))
def find_borough ( desc ):
dzielnice = [ 'Stare Miasto' , 'Wilda' , 'Jeżyce' , 'Rataje' , 'Piątkowo' , 'Winogrady' , 'Miłostowo' , 'Dębiec' ]
print("{} to najłądniejsza dzielnica w Poznaniu."
.format(find_borough("Grunwald i Jeżyce"))))
descSplit = desc.split ( ' ' )
dzielnica = [ ds for ds in descSplit if ds in dzielnice ]
return dzielnica[ 0 ] if len ( dzielnica ) > 0 else 'Inne'
def add_borough ( dane ):
dane[ 'Borough' ] = dane.apply ( lambda row: find_borough ( row[ 'Location' ] ) , axis=1 )
return dane
def write_plot ( dane , filename ):
dane2 = add_borough ( dane )
do_plota = dane2[ 'Borough' ].value_counts ( )
do_plota.plot ( kind='bar' )
# plt.show()
plt.savefig ( filename )
def mean_price ( dane , room_number ):
pokoje = dane[ dane[ 'Rooms' ] == room_number ]
return pokoje[ 'Expected' ].mean ( )
def find_13 ( dane ):
dane2 = add_borough ( dane )
pietro = dane2[ dane2[ 'Floor' ] == 13 ]
return ' '.join ( set ( pietro[ 'Borough' ].tolist ( ) ) )
def find_best_flats ( dane ):
dane2 = add_borough ( dane )
isWinogrady = dane2[ 'Borough' ] == 'Winogrady'
isPierwsze = dane2[ 'Floor' ] == 1
isTrzypokojowe = dane2[ 'Rooms' ] == 3
best = dane2[ isWinogrady & isPierwsze & isTrzypokojowe ]
return 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łądniejsza dzielnica w Poznaniu.".format ( find_borough ( "Grunwald i Jeżyce" ) ))
print("Średnia cena mieszkania 3-pokojowego, to: {:.2f}".format ( mean_price ( dane , 3 ) ))
print("Dzielnice z ofertami na 13 pietrze: {}".format ( find_13 ( dane ) ))
print("Najlepsze oferty: {}".format ( find_best_flats ( dane ) ))
print("Średnia cena mieszkania 3-pokojowego, to: {}"
.format(mean_price(dane, 3)))
if __name__ == "__main__":
main()
main ( )