1
0
forked from tdwojak/Python2017
Python2017/labs06/task02.py

85 lines
1.9 KiB
Python
Raw Normal View History

2017-12-15 14:24:17 +01:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
2017-12-16 13:00:41 +01:00
import pandas as pd
2018-01-02 15:28:01 +01:00
import numpy as np
2017-12-15 14:24:17 +01:00
def wczytaj_dane():
2017-12-16 13:00:41 +01:00
rooms_data = pd.read_csv('mieszkania.csv', # ścieżka do pliku
sep=',', # separator
encoding='utf-8', # kodowanie
index_col='Id') # ustawienie indeksu na kolumnę Date
return rooms_data
2017-12-15 14:24:17 +01:00
def most_common_room_number(dane):
2017-12-16 13:10:58 +01:00
d=dane['Rooms']
d= d.value_counts()
2018-01-02 15:28:01 +01:00
j=0
"""
for i in d:
print d.index[j] , i
j +=1
"""
d = d.index[0]
return d
2017-12-15 14:24:17 +01:00
2017-12-16 13:10:58 +01:00
2017-12-15 14:24:17 +01:00
def cheapest_flats(dane, n):
2018-01-02 15:28:01 +01:00
SortDane = dane.sort_values('Expected',ascending=True)
PriceCheapest = SortDane['Expected']
PriceCheapest = PriceCheapest.head(n)
return PriceCheapest
2017-12-15 14:24:17 +01:00
def find_borough(desc):
dzielnice = ['Stare Miasto',
'Wilda',
'Jeżyce',
'Rataje',
'Piątkowo',
'Winogrady',
'Miłostowo',
'Dębiec']
2018-01-02 15:28:01 +01:00
for district in dzielnice:
if district in desc: return district
return 'Inne'
2017-12-15 14:24:17 +01:00
def add_borough(dane):
pass
def write_plot(dane, filename):
pass
def mean_price(dane, room_number):
2018-01-02 15:28:01 +01:00
AVGdane = dane[dane.Rooms == room_number]
AVGdane = round(AVGdane.Expected.mean(),2)
return AVGdane
2017-12-15 14:24:17 +01:00
def find_13(dane):
pass
def find_best_flats(dane):
pass
def main():
dane = wczytaj_dane()
2017-12-16 13:00:41 +01:00
#print(dane[:5])
2017-12-15 14:24:17 +01:00
2017-12-16 13:00:41 +01:00
print ("Najpopularniejsza liczba pokoi w mieszkaniu to: {}"
2017-12-15 14:24:17 +01:00
.format(most_common_room_number(dane)))
print("{} to najłądniejsza dzielnica w Poznaniu."
2017-12-16 13:00:41 +01:00
.format(find_borough("Grunwald i Jeżyce")))
2017-12-15 14:24:17 +01:00
print("Średnia cena mieszkania 3-pokojowego, to: {}"
.format(mean_price(dane, 3)))
2018-01-02 15:28:01 +01:00
roomCheapest = cheapest_flats(dane, 5)
#print roomCheapest
2017-12-15 14:24:17 +01:00
if __name__ == "__main__":
main()