73 lines
2.0 KiB
Python
Executable File
73 lines
2.0 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
import pandas as pd
|
|
from statistics import mode
|
|
import matplotlib.pyplot as plt
|
|
|
|
def wczytaj_dane():
|
|
r = pd.read_csv("mieszkania.csv")
|
|
dane = r.dropna(axis='columns')
|
|
return dane
|
|
|
|
def most_common_room_number(dane):
|
|
return mode(dane.Rooms)
|
|
|
|
def cheapest_flats(dane, n):
|
|
return dane.sort_values(by="Expected").head(n)
|
|
|
|
def find_borough(desc):
|
|
dzielnice = ['Stare Miasto',
|
|
'Wilda',
|
|
'Jeżyce',
|
|
'Rataje',
|
|
'Piątkowo',
|
|
'Winogrady',
|
|
'Miłostowo',
|
|
'Dębiec']
|
|
|
|
indeks = len(desc)
|
|
nazwa_dzielnicy = "Inne"
|
|
for dzielnica in dzielnice:
|
|
indeks_dzielnica = desc.find(dzielnica)
|
|
if indeks_dzielnica < indeks and indeks_dzielnica != -1:
|
|
indeks = indeks_dzielnica
|
|
nazwa_dzielnicy = dzielnica
|
|
return nazwa_dzielnicy
|
|
|
|
def add_borough(dane):
|
|
dane['Borough'] = dane['Location'].apply(find_borough)
|
|
return dane
|
|
|
|
def write_plot(dane, filename):
|
|
add_borough(dane)
|
|
dane_wykres = pd.Series(dane.Borough.value_counts())
|
|
dane_wykres.plot(x='Borough', y='Liczba ogłoszeń', kind = 'bar')
|
|
plt.savefig(filename, pad_inches=1, bbox_inches='tight')
|
|
|
|
def mean_price(dane, room_number):
|
|
return dane.Expected[(dane['Rooms'] == room_number)].mean()
|
|
|
|
def find_13(dane):
|
|
add_borough(dane)
|
|
return dane.Borough[(dane['Floor'] == 13)].unique()
|
|
|
|
def find_best_flats(dane):
|
|
add_borough(dane)
|
|
return dane[(dane['Borough'] == 'Winogrady') & (dane['Rooms'] == 3) & (dane['Floor'] == 1)]
|
|
|
|
def main():
|
|
dane = wczytaj_dane()
|
|
print(dane[:5])
|
|
|
|
print("Najpopularniejsza liczba pokoi w mieszkaniu to: {}"
|
|
.format(most_common_room_number(dane)))
|
|
|
|
print("{} to najładniejsza dzielnica w Poznaniu."
|
|
.format(find_borough("Grunwald i Jeżyce")))
|
|
|
|
print("Średnia cena mieszkania 3-pokojowego, to: {}"
|
|
.format(mean_price(dane, 3)))
|
|
|
|
if __name__ == "__main__":
|
|
main()
|