Compare commits

...

6 Commits

21 changed files with 165 additions and 60 deletions

11
.idea/Python2018.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.6.5 (C:\software\python3\python3.exe)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>

4
.idea/misc.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6.5 (C:\software\python3\python3.exe)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Python2018.iml" filepath="$PROJECT_DIR$/.idea/Python2018.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -9,13 +9,18 @@ znanych wyrazów vocab. Argumenty funkcji text i vocab to odpowiednio łańcuch
znakowy i lista łańuchów znakowych. Wszystkie wyrazy należy zmienić na małe znakowy i lista łańuchów znakowych. Wszystkie wyrazy należy zmienić na małe
litery. (OOV = out of vocabulary) (W pythonie istnieje struktura danych tak litery. (OOV = out of vocabulary) (W pythonie istnieje struktura danych tak
jak 'set', która przechowuje elementy bez powtórzeń.) jak 'set', która przechowuje elementy bez powtórzeń.)
text - łańcuch znakowy
vocab - lista łańcuchów znakowych
""" """
def oov(text, vocab): def oov(text, vocab):
pass b = set()
a = text.split (" ")
for abc in a:
if abc not in vocab:
b.add(abc)
return b
def tests(f): def tests(f):
inputs = [("this is a string , which i will use for string testing", inputs = [("this is a string , which i will use for string testing",

View File

@ -7,8 +7,10 @@ Jeśli podany argument jest mniejszy od 1 powinna być zwracana wartość 0.
""" """
def sum_from_one_to_n(n): def sum_from_one_to_n(n):
pass if n < 1:
return 0
else:
return sum(range(n+1))
def tests(f): def tests(f):
inputs = [[999], [-100]] inputs = [[999], [-100]]

View File

@ -7,10 +7,15 @@ Napisz funkcję euclidean_distance obliczającą odległość między
dwoma punktami przestrzeni trójwymiarowej. Punkty dane jako dwoma punktami przestrzeni trójwymiarowej. Punkty dane jako
trzyelementowe listy liczb zmiennoprzecinkowych. trzyelementowe listy liczb zmiennoprzecinkowych.
np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5. np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5.
x = [0, 0, 0]
y = [3, 4, 0]
""" """
def euclidean_distance(x, y): def euclidean_distance(x, y):
pass if len(x) != len(y):
return 0
else:
return ((x[0] - y[0])**2 + (x[1]-y[1])**2 + (x[2]-y[2])**2)**0.5
def tests(f): def tests(f):
inputs = [[(2.3, 4.3, -7.5), (2.3, 8.5, -7.5)]] inputs = [[(2.3, 4.3, -7.5), (2.3, 8.5, -7.5)]]

View File

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

View File

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

View File

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

View File

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

View File

@ -9,7 +9,15 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'.
def pokemon_speak(text): def pokemon_speak(text):
pass new_text = ''
capitalize = True
for x in text:
if capitalize is True:
new_text += x.upper()
else:
new_text += x
capitalize = not capitalize
return new_text
def tests(f): def tests(f):

View File

@ -9,7 +9,17 @@ Oba napisy będą składać się wyłacznie z małych liter.
""" """
def common_chars(string1, string2): def common_chars(string1, string2):
pass wspolne = []
string1 = string1.replace(' ', '')
string2 = string2.replace(' ', '')
znaki_z_1 = set(string1)
znaki_z_2 = set(string2)
for x in znaki_z_1:
if x in znaki_z_2:
wspolne.append(x)
return sorted(wspolne)
def tests(f): def tests(f):

View File

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

View File

@ -232,13 +232,13 @@
{ {
"ename": "TypeError", "ename": "TypeError",
"evalue": "unhashable type: 'list'", "evalue": "unhashable type: 'list'",
"output_type": "error",
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-25-2bd2fa17fbf5>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m{\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;32m<ipython-input-25-2bd2fa17fbf5>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m{\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m: unhashable type: 'list'" "\u001b[0;31mTypeError\u001b[0m: unhashable type: 'list'"
] ],
"output_type": "error"
} }
], ],
"source": [ "source": [
@ -398,13 +398,13 @@
{ {
"ename": "ValueError", "ename": "ValueError",
"evalue": "I/O operation on closed file.", "evalue": "I/O operation on closed file.",
"output_type": "error",
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-47-f06513c1bbec>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mlinia\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mplik\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreadlines\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlinia\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mplik\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;32m<ipython-input-47-f06513c1bbec>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mlinia\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mplik\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreadlines\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlinia\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mplik\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mValueError\u001b[0m: I/O operation on closed file." "\u001b[0;31mValueError\u001b[0m: I/O operation on closed file."
] ],
"output_type": "error"
} }
], ],
"source": [ "source": [

View File

@ -1,14 +1,18 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import pandas as pd
import matplotlib.pyplot as plt
def wczytaj_dane(): def wczytaj_dane():
pass dane = pd.read_csv("mieszkania.csv")
dane.head()
def most_common_room_number(dane): def most_common_room_number(dane):
pass return(dane['Rooms'].value_counts().idxmax())
def cheapest_flats(dane, n): def cheapest_flats(dane, n):
pass p = dane.sort_values(['Expected'], ascending=[0])
p.head(n)
def find_borough(desc): def find_borough(desc):
dzielnice = ['Stare Miasto', dzielnice = ['Stare Miasto',
@ -19,23 +23,28 @@ def find_borough(desc):
'Winogrady', 'Winogrady',
'Miłostowo', 'Miłostowo',
'Dębiec'] 'Dębiec']
pass for i in dzielnice:
if desc.find(i) + 1:
return (i)
return ('Inne')
def add_borough(dane): def add_borough(dane):
pass dane['Borough'] = dane['Location'].apply(find_borough)
return (dane)
def write_plot(dane, filename): def write_plot(dane, filename):
pass dane['Borough'].hist()
plt.savefig(filename)
def mean_price(dane, room_number): def mean_price(dane, room_number):
pass return dane.Expected[dane.Rooms == room_number].mean()
def find_13(dane): def find_13(dane):
pass return dane.Borough[dane.Floor == 13].unique()
def find_best_flats(dane): def find_best_flats(dane):
pass return dane[(dane.Borough == 'Winogrady') & (dane.Rooms == 3) & (dane.Floor == 1)]
def main(): def main():
dane = wczytaj_dane() dane = wczytaj_dane()

View File

@ -4,62 +4,61 @@
""" """
1. Zaimportuj bibliotkę pandas jako pd. 1. Zaimportuj bibliotkę pandas jako pd.
""" """
import pandas as pd
""" """
2. Wczytaj zbiór danych `311.csv` do zniennej data. 2. Wczytaj zbiór danych `311.csv` do zmiennej data.
""" """
data = pd.read_csv("./311.csv")
""" """
3. Wyświetl 5 pierwszych wierszy z data. 3. Wyświetl 5 pierwszych wierszy z data.
""" """
print(data.head(5))
""" """
4. Wyświetl nazwy kolumn. 4. Wyświetl nazwy kolumn.
""" """
#print(data.columns)
""" """
5. Wyświetl ile nasz zbiór danych ma kolumn i wierszy. 5. Wyświetl ile nasz zbiór danych ma kolumn i wierszy.
""" """
shape = data.shape
rows = shape[0]
cols = shape[1]
#print(rows, cols)
""" """
6. Wyświetl kolumnę 'City' z powyższego zbioru danych. 6. Wyświetl kolumnę 'City' z powyższego zbioru danych.
""" """
#print(data.City)
""" """
7. Wyświetl jakie wartoścu przyjmuje kolumna 'City'. 7. Wyświetl jakie wartoścu przyjmuje kolumna 'City'.
""" """
#print(data.City.unique())
""" """
8. Wyświetl tabelę rozstawną kolumny City. 8. Wyświetl tabelę rozstawną kolumny City (zliczanie wartosci) value_counts.
""" """
#print(data.City.value_counts())
""" """
9. Wyświetl tylko pierwsze 4 wiersze z wcześniejszego polecenia. 9. Wyświetl tylko pierwsze 4 wiersze z wcześniejszego polecenia.
""" """
#print(data.City.value_counts().head(4))
""" """
10. Wyświetl, w ilu przypadkach kolumna City zawiera NaN. 10. Wyświetl, w ilu przypadkach kolumna City zawiera NaN
""" """
data.City.value_counts()
""" """
11. Wyświetl data.info() 11. Wyświetl data.info()
""" """
data.info()
""" """
12. Wyświetl tylko kolumny Borough i Agency i tylko 5 ostatnich linii. 12. Wyświetl tylko kolumny Borough i Agency i tylko 5 ostatnich linii.
""" """
""" """
13. Wyświetl tylko te dane, dla których wartość z kolumny Agency jest równa 13. Wyświetl tylko te dane, dla których wartość z kolumny Agency jest równa
NYPD. Zlicz ile jest takich przykładów. NYPD. Zlicz ile jest takich przykładów.
@ -69,6 +68,7 @@ NYPD. Zlicz ile jest takich przykładów.
14. Wyświetl wartość minimalną i maksymalną z kolumny Longitude. 14. Wyświetl wartość minimalną i maksymalną z kolumny Longitude.
""" """
""" """
15. Dodaj kolumne diff, która powstanie przez sumowanie kolumn Longitude i Latitude. 15. Dodaj kolumne diff, która powstanie przez sumowanie kolumn Longitude i Latitude.
""" """