forked from tdwojak/Python2017
done
This commit is contained in:
parent
def69182d9
commit
5a2a035e5c
@ -1,10 +1,12 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Napisz funkcję ``suma``, która przyjmnie jeden argument: listę liczb i zwróci ich sumę.
|
||||
"""
|
||||
|
||||
def suma(liczby):
|
||||
assert len(liczby) > 0
|
||||
a=reduce(lambda a, b: a+b, liczby)
|
||||
return a
|
||||
return sum(liczby)
|
||||
|
||||
def main():
|
||||
print(suma([1, 2, 3, 4]))
|
||||
|
@ -1,7 +1,14 @@
|
||||
import task00, sys
|
||||
from task00 import suma
|
||||
import sys
|
||||
|
||||
def main():
|
||||
print('%f' % (task00.suma(map(lambda x: float(x), sys.argv[1:]))))
|
||||
arguments=sys.argv[1:]
|
||||
float_arguments=[]
|
||||
for arg in arguments:
|
||||
float_arguments.append(float(arg))
|
||||
|
||||
print(suma(float_arguments))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -1,12 +1,18 @@
|
||||
import task00, sys
|
||||
from task00 import suma
|
||||
import sys
|
||||
|
||||
def main():
|
||||
def a_to_f(a):
|
||||
arg_list = sys.argv[1:]
|
||||
float_arg_list = []
|
||||
for arg in arg_list:
|
||||
try:
|
||||
return float(a)
|
||||
float_arg=float(arg)
|
||||
float_arg_list.append(float_arg)
|
||||
except:
|
||||
return 0
|
||||
print('%f' % (task00.suma(map(a_to_f, sys.argv[1:]))))
|
||||
float_arg_list.append(0)
|
||||
|
||||
print(suma(float_arg_list))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -1,12 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Implementacja narzedzia ``wc`` z linuksa (word counter).
|
||||
Zwraca liczbę słów, znaków i linii.
|
||||
"""
|
||||
|
||||
import sys, argparse
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
|
||||
def count_lines(text):
|
||||
@ -35,16 +28,22 @@ def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-l', help="number of lines", action="store_true")
|
||||
parser.add_argument('-w', help="number of words", action="store_true")
|
||||
parser.add_argument('-c', help="number of characters", action="store_true")
|
||||
parser.add_argument('fn', nargs='?', type=file, default=sys.stdin, help='optional filename to read from')
|
||||
parser.add_argument('-c', help="number of chars", action="store_true")
|
||||
parser.add_argument('-filename', type=argparse.FileType('r'), default='-', help='filename to read from')
|
||||
args = parser.parse_args()
|
||||
lines, words, chars = wc(args.fn.read())
|
||||
if( args.l or args.w or args.c ):
|
||||
if(args.l):
|
||||
print(lines)
|
||||
if(args.w):
|
||||
print(words)
|
||||
if(args.c):
|
||||
|
||||
if args.filename:
|
||||
lines, words, chars = wc(args.filename.read())
|
||||
elif not sys.stdin.isatty():
|
||||
lines, words, chars = wc(args.stdin.read())
|
||||
else:
|
||||
pass
|
||||
|
||||
if(args.l):
|
||||
print(lines)
|
||||
elif(args.w):
|
||||
print(words)
|
||||
elif(args.c):
|
||||
print(chars)
|
||||
else:
|
||||
print(lines, words, chars)
|
||||
@ -52,3 +51,4 @@ def main():
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
@ -1,18 +1,22 @@
|
||||
##!/usr/bin/env python
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import pandas as pd
|
||||
import statistics
|
||||
|
||||
def wczytaj_dane():
|
||||
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
|
||||
raw_data = pd.read_csv('mieszkania.csv',sep=',')
|
||||
data = pd.DataFrame(raw_data)
|
||||
return data
|
||||
|
||||
def most_common_room_number(dane):
|
||||
return dane.mode(numeric_only =True)["Rooms"][0]
|
||||
rooms=dane['Rooms']
|
||||
return(int(statistics.mode(rooms)))
|
||||
|
||||
def cheapest_flats(dane, n):
|
||||
return dane.sort_values("Expected")[:n]
|
||||
cheapest=pd.DataFrame(dane['Expected'])
|
||||
cheapest.sort=cheapest.sort_values(by=['Expected'])
|
||||
return cheapest.sort[:n]
|
||||
|
||||
def find_borough(desc):
|
||||
dzielnice = ['Stare Miasto',
|
||||
@ -23,41 +27,62 @@ def find_borough(desc):
|
||||
'Winogrady',
|
||||
'Miłostowo',
|
||||
'Dębiec']
|
||||
inputList=desc.split(' ')
|
||||
for i in inputList:
|
||||
if i in dzielnice:
|
||||
return i
|
||||
|
||||
return "Inne"
|
||||
for dzielnica in dzielnice:
|
||||
if desc.find(dzielnica)!=-1:
|
||||
return dzielnica
|
||||
return 'Inne'
|
||||
|
||||
|
||||
def add_borough(dane):
|
||||
newcol=dane["Location"].apply(find_borough)
|
||||
dane["Borough"]=newcol
|
||||
borough_list=[]
|
||||
for data in dane['Location']:
|
||||
borough_list.append(find_borough(data))
|
||||
borough_series = pd.Series(borough_list,name='Borough')
|
||||
dane['Borough']=borough_series
|
||||
return dane
|
||||
|
||||
|
||||
def write_plot(dane, filename):
|
||||
bar=dane["Borough"].value_counts().plot(kind="bar", figsize=(6,6))
|
||||
fig=bar.get_figure()
|
||||
fig.savefig(filename)
|
||||
data = add_borough(dane)
|
||||
plot_data = data.groupby(dane['Borough']).size()
|
||||
plt = plot_data.plot.bar()
|
||||
fig = plt.get_figure()
|
||||
fig.savefig('{}.png'.format(filename))
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
def mean_price(dane, room_number):
|
||||
return dane[dane["Rooms"]==room_number]["Expected"].mean()
|
||||
data=dane.loc[dane['Rooms'] == room_number]
|
||||
return round(statistics.mean(data['Expected']),2)
|
||||
|
||||
def find_13(dane):
|
||||
return dane[dane["Floor"]==13]["Borough"].unique()
|
||||
data = add_borough(dane)
|
||||
boroughs = data.loc[data['Floor'] == 13]
|
||||
return set(boroughs['Borough'])
|
||||
|
||||
|
||||
def find_best_flats(dane):
|
||||
return dane[(dane["Borough"]=="Winogrady") & (dane["Floor"]==1) & (dane["Rooms"]==3)]
|
||||
data = add_borough(dane)
|
||||
best_flats = data.loc[(data['Borough'] == 'Winogrady') & (data['Floor'] == 1) & (data['Rooms'] == 3)]
|
||||
return best_flats
|
||||
|
||||
|
||||
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)))
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in New Issue
Block a user