1
0
Fork 0

Compare commits

..

1 Commits

Author SHA1 Message Date
Tomasz Dwojak a9867f7588 task02 2018-06-03 10:04:16 +02:00
21 changed files with 74 additions and 246 deletions

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -166,9 +166,8 @@ for i in range(5):# range[5] = [0,1,2,3,4]
# In[ ]:
for zmienna in oceny:
for zmienna in lista:
# operacje do wykonania w pętli
pass
# In[ ]:

View File

@ -9,76 +9,48 @@ Zadania wprowadzające do pierwszych ćwiczeń.
"""
Wypisz na ekran swoje imię i nazwisko.
"""
print("Justyna Adamczyk")
"""
Oblicz i wypisz na ekran pole koła o promienie 10. Jako PI przyjmij 3.14.
"""
print(10 ** 2 * 3.14)
"""
Stwórz zmienną pole_kwadratu i przypisz do liczbę: pole kwadratu o boku 3.
"""
pole_kwadratu=3**2
print(pole_kwadratu)
"""
Stwórz 3 elementową listę, która zawiera nazwy 3 Twoich ulubionych owoców.
Wynik przypisz do zmiennej `owoce`.
"""
owoce=["truskwaki", "gruszka", "pigwa"]
print(owoce)
"""
Dodaj do powyższej listy jako nowy element "pomidor".
"""
owoce.append("pomidor")
print(owoce)
"""
Usuń z powyższej listy drugi element.
"""
owoce.pop(1)
print(owoce)
"""
Rozszerz listę o tablice ['Jabłko', "Gruszka"].
"""
owoce.extend(['Jabłko', "Gruszka"])
print(owoce)
"""
Wyświetl listę owoce, ale bez pierwszego i ostatniego elementu.
"""
print("bez pierwszego i ostatniego elementu:", owoce[1:-1])
"""
Wyświetl co trzeci element z listy owoce.
"""
print("co trzeci:", owoce[::3])
"""
Stwórz pusty słownik i przypisz go do zmiennej magazyn.
"""
slownik = {}
magazyn=slownik
"""
Dodaj do słownika magazyn owoce z listy owoce, tak, aby owoce były kluczami,
zaś wartościami były równe 5.
"""
for i in owoce:
magazyn[i]=[5]
print(magazyn)

View File

@ -7,9 +7,7 @@ która zawiera tylko elementy z list o parzystych indeksach.
"""
def even_elements(lista):
moja_lista = lista[::2]
return moja_lista
pass
def tests(f):

View File

@ -6,12 +6,7 @@
"""
def days_in_year(days):
if ((days % 4) == 0 and ((days % 100) != 0)) or ((days % 400) == 0):
dni=366
else:
dni=365
return dni
pass
def tests(f):
inputs = [[2015], [2012], [1900], [2400], [1977]]

View File

@ -11,15 +11,9 @@ litery. (OOV = out of vocabulary) (W pythonie istnieje struktura danych tak
jak 'set', która przechowuje elementy bez powtórzeń.)
"""
from sets import Set
def oov(text, vocab):
rozdzielenie=text.split(' ')
slowo=set()
slowo=(slowo for slowo in rozdzielenie if slowo not in vocab)
return slowo
pass

View File

@ -7,16 +7,7 @@ Jeśli podany argument jest mniejszy od 1 powinna być zwracana wartość 0.
"""
def sum_from_one_to_n(n):
suma = 0
for i in range(n+1):
suma = suma + i
if n < 1:
return 0
else:
return suma
pass
def tests(f):

View File

@ -8,17 +8,9 @@ dwoma punktami przestrzeni trójwymiarowej. Punkty są dane jako
trzyelementowe listy liczb zmiennoprzecinkowych.
np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5.
"""
import cmath
def euclidean_distance(x, y):
odleglosc=0
for i in range(3):
odleglosc= odleglosc + (x[i] - y[i]) ** 2
odleglosc = cmath.sqrt(odleglosc)
#odleglosc=odleglosc ** (1/2)
return odleglosc
pass
def tests(f):
inputs = [[(2.3, 4.3, -7.5), (2.3, 8.5, -7.5)]]

View File

@ -10,15 +10,7 @@ ma być zwracany napis "It's not a Big 'No!'".
"""
def big_no(n):
if n<5:
zdanie="It's not a Big 'No!'"
else:
zdanie='N'
for i in range(n):
zdanie=zdanie + 'O'
zdanie = zdanie+'!'
return zdanie
pass
def tests(f):
inputs = [[5], [6], [2]]

View File

@ -6,16 +6,7 @@ Napisz funkcję char_sum, która dla zadanego łańcucha zwraca
sumę kodów ASCII znaków.
"""
def char_sum(text):
sumujemy = 0
for znaki in text:
sumujemy = sumujemy + ord(znaki)
return sumujemy
pass
def tests(f):
inputs = [["this is a string"], ["this is another string"]]

View File

@ -7,13 +7,7 @@ przez 3 lub 5 mniejszych niż n.
"""
def sum_div35(n):
suma = 0
for i in range(n-1):
if (i%3==0) or (i%5==0):
suma = suma + i
return suma
pass
def tests(f):
inputs = [[10], [100], [3845]]

View File

@ -9,8 +9,7 @@ Np. leet('leet') powinno zwrócić '1337'.
def leet_speak(text):
return tekst.replace('o', '0').replace('l', '1').replace('e', '3').replace('t', '7')
pass
def tests(f):

View File

@ -7,17 +7,10 @@ Napisz funkcję pokemon_speak, która zamienia w podanym napisie co drugą liter
na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'.
"""
def pokemon_speak(text):
listy = []
pass
for i in range(len(text)):
if i % 2 == 0:
listy.append(text[i].upper())
else:
listy.append(text[i])
return ''.join(listy)
def tests(f):
inputs = [['pokemon'], ['do not want'], ['POKEMON']]

View File

@ -8,14 +8,8 @@ uporządkowaną listę wspólnych liter z lańcuchów string1 i string2.
Oba napisy będą składać się wyłacznie z małych liter.
"""
def common_chars(string1, string2):
s=string1.replace(' ','')
t=string2.replace(' ','')
s=set(s)
t=set(t)
zwracam = sorted(s & t)
return list(''.join(zwracam))
pass
def tests(f):

3
labs02/test_task.py Normal file → Executable file
View File

@ -6,8 +6,7 @@ def suma(a, b):
"""
Napisz funkcję, która zwraca sumę elementów.
"""
wynik = a + b
return wynik
return 0
def tests(f):
inputs = [(2, 3), (0, 0), (1, 1)]

View File

@ -1,21 +0,0 @@
import glob
sciezka = 'scores/*.npz.bleu'
for plik in glob.glob(sciezka):
with open(plik, 'r') as f:
for linia in f.readlines():
numer = float(linia[linia.find("=") + 1:linia.find(",")])
if numer > 0:
max_numer = numer
max_numer_plik = plik
f.close()
print(max_numer_plik)

0
labs04/examples/06_execution_time.py Normal file → Executable file
View File

0
labs04/examples/25_ip2geolocation.py Normal file → Executable file
View File

View File

@ -1,68 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pandas as pd
import sys
import numpy as np
def wczytaj_dane():
my_data = pd.read_csv('mieszkania.csv',
encoding='utf-8',
index_col='Id',
sep = ',')
return my_data
def most_common_room_number(dane):
rooms = dane['Rooms']
return rooms.value_counts().index[0]
def cheapest_flats(dane, n):
dane2 = dane.sort_values(by=['Expected'])
return(dane2.head(n))
def find_borough(desc):
dzielnice = ['Stare Miasto',
'Wilda',
'Jeżyce',
'Rataje',
'Piątkowo',
'Winogrady',
'Miłostowo',
'Dębiec']
for dzielnia in dzielnice:
if dzielnia in desc:
return dzielnia
return 'Inne'
def add_borough(dane):
dane['Borough'] = dane.apply(lambda row: find_borough(row['Location']))
def write_plot(dane, filename):
dane['Borough'].value_counts().plot.bar().get_figure().savefig(filename)
def mean_price(dane, room_number):
mean_value = dane.loc[dane['Rooms'] == room_number]['Expected'].mean()
return mean_value
def find_13(dane):
return dane.loc[dane['Floor'] == 13]['Borough'].unique()
def find_best_flats(dane):
best_flats = dane.loc[(df['Borough'] == 'Winogrady') & (dane['Rooms'] == 3) & (dane['Floor'] == 1)]
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()

54
labs06/task02.py Executable file
View File

@ -0,0 +1,54 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def wczytaj_dane():
pass
def most_common_room_number(dane):
pass
def cheapest_flats(dane, n):
pass
def find_borough(desc):
dzielnice = ['Stare Miasto',
'Wilda',
'Jeżyce',
'Rataje',
'Piątkowo',
'Winogrady',
'Miłostowo',
'Dębiec']
pass
def add_borough(dane):
pass
def write_plot(dane, filename):
pass
def mean_price(dane, room_number):
pass
def find_13(dane):
pass
def find_best_flats(dane):
pass
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()

42
labs06/tasks.py Normal file → Executable file
View File

@ -4,111 +4,77 @@
"""
1. Zaimportuj bibliotkę pandas jako pd.
"""
import pandas as pd
"""
2. Wczytaj zbiór danych `311.csv` do zniennej data.
"""
data = pd.read_csv("/home/students/s407531/PycharmProjects/Python2018/labs06/311.csv",low_memory=False)
"""
3. Wyświetl 5 pierwszych wierszy z data.
"""
data.head()
"""
4. Wyświetl nazwy kolumn.
"""
print(data.columns)
"""
5. Wyświetl ile nasz zbiór danych ma kolumn i wierszy.
"""
shape = data.shape
print(shape)
"""
6. Wyświetl kolumnę 'City' z powyższego zbioru danych.
"""
print(data['City'])
"""
7. Wyświetl jakie wartoścu przyjmuje kolumna 'City'.
"""
data.City.unique()
"""
8. Wyświetl tabelę rozstawną kolumny City.
"""
data.City.value_counts()
"""
9. Wyświetl tylko pierwsze 4 wiersze z wcześniejszego polecenia.
"""
data.City.value_counts().head(4)
"""
10. Wyświetl, w ilu przypadkach kolumna City zawiera NaN.
"""
data['City'].isnull().sum()
x=data[data['City'].isnull()]
shape=x.shape
rows=shape[0]
print(rows)
"""
11. Wyświetl data.info()
"""
data.info()
"""
12. Wyświetl tylko kolumny Borough i Agency i tylko 5 ostatnich linii.
"""
print(data[['Borough','Agency']].tail())
"""
13. Wyświetl tylko te dane, dla których wartość z kolumny Agency jest równa
NYPD. Zlicz ile jest takich przykładów.
"""
x=data[data['Agency'] == 'NYPD']
shape=x.shape
rows=shape[0]
print(rows)
"""
14. Wyświetl wartość minimalną i maksymalną z kolumny Longitude.
"""
Longitude=data['Longitude']
Longitude.min()
Longitude.max()
"""
15. Dodaj kolumne diff, która powstanie przez sumowanie kolumn Longitude i Latitude.
"""
Latitude=data['Latitude']
Longitude=data['Longitude']
data['Diff']=Latitude + Longitude
"""
16. Wyświetl tablę rozstawną dla kolumny 'Descriptor', dla której Agency jest
równe NYPD.
"""
y=data[data['Agency']=='NYPD']
y.Descriptor.value_counts()