forked from tdwojak/Python2017
91 lines
2.6 KiB
Python
Executable File
91 lines
2.6 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import pandas as pd
|
|
|
|
def wczytaj_dane():
|
|
|
|
mieszkania = pd.read_csv('C:\Users\mlyska\Documents\python2017\labs06\mieszkania.csv', sep = ',')
|
|
mieszkania.fillna('', inplace=True)
|
|
mieszkania['Description'] = mieszkania['Description'] + mieszkania['Unnamed: 7'] + mieszkania['Unnamed: 8'] + \
|
|
mieszkania['Unnamed: 9'] + mieszkania['Unnamed: 10'] + mieszkania['Unnamed: 11']
|
|
mieszkania.drop(['Unnamed: 7','Unnamed: 8','Unnamed: 9','Unnamed: 10','Unnamed: 11'], 1, inplace=True)
|
|
return mieszkania
|
|
|
|
def most_common_room_number(dane):
|
|
counter = dane['Rooms'].value_counts()
|
|
maxCount = counter.to_frame()
|
|
return maxCount.index.values[0]
|
|
|
|
def cheapest_flats(dane, n):
|
|
dane.sort_values('Expected')
|
|
return dane.head(n)
|
|
|
|
def find_borough(desc):
|
|
dzielnice = ['Stare Miasto',
|
|
'Wilda',
|
|
'Jeżyce',
|
|
'Rataje',
|
|
'Piątkowo',
|
|
'Winogrady',
|
|
'Miłostowo',
|
|
'Dębiec']
|
|
|
|
for i in dzielnice:
|
|
if i in desc:
|
|
return i
|
|
break
|
|
if desc not in dzielnice:
|
|
return 'Inne'
|
|
|
|
|
|
|
|
def add_borough(dane):
|
|
values = []
|
|
for i in dane['Location']:
|
|
values.append(find_borough(i))
|
|
|
|
tempSeries = pd.Series(values)
|
|
dane['Borough'] = tempSeries.values
|
|
|
|
def write_plot(dane, filename):
|
|
add_borough(dane)
|
|
dataPlot = dane['Borough'].value_counts()
|
|
|
|
imgPlot = dataPlot.plot(kind='bar', alpha=0.5, title='Liczba ogloszen mieszkan z podzialem na dzielnice', fontsize=6, figsize=(8,7))
|
|
imgPlot.set_ylabel('Liczba ogloszen')
|
|
imgPlot.set_xlabel('Dzielnice')
|
|
|
|
filePlot = imgPlot.get_figure()
|
|
filePlot.savefig(filename)
|
|
|
|
def mean_price(dane, room_number):
|
|
x = dane.loc[dane['Rooms'] == room_number]
|
|
return x['Expected'].mean()
|
|
|
|
def find_13(dane):
|
|
x = dane.loc[dane['Floor'] == 13]
|
|
return list(set(x['Borough'].tolist()))
|
|
|
|
def find_best_flats(dane):
|
|
best = dane.loc[dane['Borough'] == 'Winogrady' & dane['Rooms'] == 3 & dane['Floor'] == 1]
|
|
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: {}"
|
|
.format(mean_price(dane, 3)))
|
|
|
|
write_plot(dane, 'ogloszenia.png')
|
|
|
|
if __name__ == "__main__":
|
|
main()
|