1
0
Fork 0
Python2017/labs06/task02.py

63 lines
1.7 KiB
Python
Raw Normal View History

2017-12-15 14:24:17 +01:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
2018-01-21 12:25:01 +01:00
import pandas as pd
2017-12-15 14:24:17 +01:00
def wczytaj_dane():
2018-01-21 12:25:01 +01:00
mieszkania = pd.read_csv('mieszkania.csv',sep=',',encoding='UTF-8',usecols=[0,1,2,3,4,5,6])
return mieszkania
2017-12-15 14:24:17 +01:00
def most_common_room_number(dane):
2018-01-21 12:25:01 +01:00
return dane.mode(numeric_only =True)["Rooms"][0]
2017-12-15 14:24:17 +01:00
def cheapest_flats(dane, n):
2018-01-21 12:25:01 +01:00
return dane.sort_values("Expected")[:n]
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-21 12:25:01 +01:00
inputList=desc.split(' ')
for i in inputList:
if i in dzielnice:
return i
break
return "Inne"
2017-12-15 14:24:17 +01:00
def add_borough(dane):
2018-01-21 12:25:01 +01:00
newcol=dane["Location"].apply(find_borough)
dane["Borough"]=newcol
return dane
2017-12-15 14:24:17 +01:00
def write_plot(dane, filename):
2018-01-21 12:25:01 +01:00
bar=dane["Borough"].value_counts().plot(kind="bar", figsize=(6,6))
fig=bar.get_figure()
fig.savefig(filename)
2017-12-15 14:24:17 +01:00
def mean_price(dane, room_number):
2018-01-21 12:25:01 +01:00
return dane[dane["Rooms"]==room_number]["Expected"].mean()
2017-12-15 14:24:17 +01:00
def find_13(dane):
2018-01-21 12:25:01 +01:00
return dane[dane["Floor"]==13]["Borough"].unique()
2017-12-15 14:24:17 +01:00
def find_best_flats(dane):
2018-01-21 12:25:01 +01:00
return dane[(dane["Borough"]=="Winogrady") & (dane["Floor"]==1) & (dane["Rooms"]==3)]
2017-12-15 14:24:17 +01:00
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."
2018-01-21 12:25:01 +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)))
if __name__ == "__main__":
2018-01-21 12:25:01 +01:00
main()