forked from tdwojak/Python2017
lab 6 filled
This commit is contained in:
parent
bd731bbc44
commit
3fa9c4f31f
103
labs06/task02.py
103
labs06/task02.py
@ -1,54 +1,77 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import pandas as pd
|
||||||
def wczytaj_dane():
|
import matplotlib.pyplot as plt
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
def add_borough(dane):
|
def wczytaj_dane ( ):
|
||||||
pass
|
return pd.read_csv ( 'mieszkania.csv' )
|
||||||
|
|
||||||
def write_plot(dane, filename):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def mean_price(dane, room_number):
|
def most_common_room_number ( dane ):
|
||||||
pass
|
return dane[ 'Rooms' ].value_counts ( )
|
||||||
|
|
||||||
def find_13(dane):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def find_best_flats(dane):
|
def cheapest_flats ( dane , n ):
|
||||||
pass
|
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: {}"
|
def find_borough ( desc ):
|
||||||
.format(most_common_room_number(dane)))
|
dzielnice = [ 'Stare Miasto' , 'Wilda' , 'Jeżyce' , 'Rataje' , 'Piątkowo' , 'Winogrady' , 'Miłostowo' , 'Dębiec' ]
|
||||||
|
|
||||||
print("{} to najłądniejsza dzielnica w Poznaniu."
|
descSplit = desc.split ( ' ' )
|
||||||
.format(find_borough("Grunwald i Jeżyce"))))
|
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__":
|
if __name__ == "__main__":
|
||||||
main()
|
main ( )
|
Loading…
Reference in New Issue
Block a user