forked from tdwojak/Python2017
Homework#6
This commit is contained in:
parent
ba9dc1422a
commit
689e3bc8ee
BIN
labs06/barPlot.png
Normal file
BIN
labs06/barPlot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
@ -1,14 +1,18 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import pandas as pd
|
||||||
def wczytaj_dane():
|
def wczytaj_dane():
|
||||||
pass
|
mieszkania = pd.read_csv('mieszkania.csv', # ścieżka do pliku
|
||||||
|
sep=',', # separator
|
||||||
|
encoding='UTF-8',
|
||||||
|
usecols=[0,1,2,3,4,5,6])
|
||||||
|
return mieszkania
|
||||||
|
|
||||||
def most_common_room_number(dane):
|
def most_common_room_number(dane):
|
||||||
pass
|
return dane.mode(numeric_only =True)["Rooms"][0]
|
||||||
|
|
||||||
def cheapest_flats(dane, n):
|
def cheapest_flats(dane, n):
|
||||||
pass
|
return dane.sort_values("Expected")[:n]
|
||||||
|
|
||||||
def find_borough(desc):
|
def find_borough(desc):
|
||||||
dzielnice = ['Stare Miasto',
|
dzielnice = ['Stare Miasto',
|
||||||
@ -19,36 +23,41 @@ def find_borough(desc):
|
|||||||
'Winogrady',
|
'Winogrady',
|
||||||
'Miłostowo',
|
'Miłostowo',
|
||||||
'Dębiec']
|
'Dębiec']
|
||||||
pass
|
inputList=desc.split(' ')
|
||||||
|
for i in inputList:
|
||||||
|
if i in dzielnice:
|
||||||
|
return i
|
||||||
|
break
|
||||||
|
return "Inne"
|
||||||
|
|
||||||
|
|
||||||
def add_borough(dane):
|
def add_borough(dane):
|
||||||
pass
|
newcol=dane["Location"].apply(find_borough)
|
||||||
|
dane["Borough"]=newcol
|
||||||
|
return dane
|
||||||
|
|
||||||
def write_plot(dane, filename):
|
def write_plot(dane, filename):
|
||||||
pass
|
bar=dane["Borough"].value_counts().plot(kind="bar", figsize=(6,6))
|
||||||
|
fig=bar.get_figure()
|
||||||
|
fig.savefig(filename)
|
||||||
|
|
||||||
def mean_price(dane, room_number):
|
def mean_price(dane, room_number):
|
||||||
pass
|
return dane[dane["Rooms"]==room_number]["Expected"].mean()
|
||||||
|
|
||||||
def find_13(dane):
|
def find_13(dane):
|
||||||
pass
|
return dane[dane["Floor"]==13]["Borough"].unique()
|
||||||
|
|
||||||
def find_best_flats(dane):
|
def find_best_flats(dane):
|
||||||
pass
|
return dane[(dane["Borough"]=="Winogrady") & (dane["Floor"]==1) & (dane["Rooms"]==3)]
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
dane = wczytaj_dane()
|
dane = wczytaj_dane()
|
||||||
print(dane[:5])
|
print(dane[:5])
|
||||||
|
|
||||||
print("Najpopularniejsza liczba pokoi w mieszkaniu to: {}"
|
print("Najpopularniejsza liczba pokoi w mieszkaniu to: {}"
|
||||||
.format(most_common_room_number(dane)))
|
.format(most_common_room_number(dane)))
|
||||||
|
|
||||||
print("{} to najłądniejsza dzielnica w Poznaniu."
|
print("{} to najłądniejsza dzielnica w Poznaniu."
|
||||||
.format(find_borough("Grunwald i Jeżyce"))))
|
.format(find_borough("Grunwald i Jeżyce")))
|
||||||
|
|
||||||
print("Średnia cena mieszkania 3-pokojowego, to: {}"
|
print("Średnia cena mieszkania 3-pokojowego, to: {}"
|
||||||
.format(mean_price(dane, 3)))
|
.format(mean_price(dane, 3)))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user