WEB:
$ pip install django
$ django-admin help
Create a new project:
$ django-admin startproject myproject
Get Help:
$ python manage.py help
Run a web server
$ python manage.py runserver
Create a page app
$ python manage.py startapp mypages
--------------
Convert UI file prepared with QT 5 Designer to PY file to be used in Python.
pyuic5 MainWindow.ui -o MainWindow.py
--------
isinstance(obj, tuple) #check if the obj is a tuple
-----
Pandas DataFrame
import pandas as pd
s1 = pd.Series([1,2,3,4])
s2 = pd.Series([10,20,30,40])
data = dict(apples = s1, oranges = s2)
df = pd.DataFrame(data)
print(df)
apples oranges
0 1 10
1 2 20
...
df = pd.DataFrame([["x", 10], ["y", 20], ["z", 30]], columns=["A", "B"], index=[3,4,5], dtype=float)
print(df)
A B
3 x 10.0
4 y 20.0
5 z 30.0
df["A"] #get column A
df[["A", "B"]] #column A, B
df.loc[4] #Get row with custom index 4
df.loc["row", "column"]
df.loc[:, ["B", "A"]] # get all rows with column B, A
df.iloc(2) #get row using its position, 0 based index
Add new column
df["C"] = pd.Series([100,200,300], [3,4,5])
df["D"] = df["C"] + df["B"]
df.drop("C")
df = pd.read_csv('sample.csv')
df = pd.read_json('sample.json', encoding="UTF-8")
import sqlite3
con = sqlite3.connect("sample.db")
df.read_sql_query("SELECT * FROM tbl", con)
-------
import pandas as pd
nums=[10, 20, 30, "abc"]
pdseri = pd.series(nums)
#creates key value pairs for items
pdseri = pd.Series([10, 20, 30], ["a", "b", "c"])
pdseri[0] #20
pdseri["a"] #20
pdseri[:1] #a 10
pdseri[-1:] #c 30
pdseri[["a","b", "x"]] # a 10 \n b 20 \n NaN
pdseri.sum() #60
pdseri.max() #30
pdseri.ndim #1 - dimension
pdseri + 5 # a 15 \n b 25 \n c 35
result = pdseri >=20
#result = a False \n b True \n c True
result = pdseri % 3 == 0
# result = a False \n b False \n c True
print(pdseri[pdseri % 2 == 0])
#a 10 \n b 20
pdseri2 = pd.Series([5, 15, 25], ["b", "c", "d"])
total = pdseri + pdseri2
#total= a NaN \n b 25 \n c 35 \n d NaN
total["c"] # 35
------
import numpy as np
arr1 = np.array([1,2,3,4])
arr2=arr1.reshape(2,2)
arr1.ndim #1 - get dimensions
arr2.ndim #2
arr1.shape #(4,)
arr2.shape #(2,2)
arr1.mean() #2.5 - average
np.arange(1,9,2) #[1,3,5,7]
np.random.randint(0,100, 3)
np.random.rand(3) #[0.44, 0.92, 0.788]
-------
pip install requests #install a library
pip list #lists installed packages
----
import json
print(json.__file__) #gets the path of the library
-----
names=["ali", "veli", "ahmet"]
name = random.choice(names)
#shuffle list items.
random.shuffle(names)
#get a small portion of list
nums=list(range(100))
parts = random.sample(nums, 3)
------
import math
print(dir(math)) #list all functions in a module
print(help(math)) #get help about all functions in a module
print(help(math.sin)) #get help about specific function
--
#Using alias:
import math as islem
a = islem.ceil(5.3) #6
-----
#using all functions directly
from random import * #imports all
from math import sqrt, sin, factorial, ceil
a = ceil(5.3) #6
b = randint(1,10)
-----
global x #to use the globally defined variable in a function
x=100
y=100
def test():
global x
x=200
y=200
test()
print(x) #200
print(y) #100
----
def checkEven(num): return num % 2 == 0
nums=[1,3,5,6,8,9]
result = list(filter(checkEven, nums))
#result=[6,8]
----
def square(num): return num ** 2
nums=[1, 4, 7, 9]
for item in map(square, nums):
print(item)
#1 - 16 - 49 - 81
result = list(map(square, nums))
#result = [1, 16, 49, 81]
...
result = list(map(lambda num: num ** 2, nums))
#result=[1, 16, 49, 81]
square2 = lambda num: num ** 2
result=square2(11)
#result= 121
-----
FUNCTIONS:
def myFunc(a, *args, **pdict):
print(a)
print(args)
print(pdict)
myFunc(5, 7, 8, key1='val 1', key2 = 'val 2')
#5 \n (7, 8) \n {'key1': 'val 1', 'key2': 'val 2'}
----
#args as dict
def displayUser(**args):
for key, value in args.items():
print(key, value)
displayUser(name='Ali', age=22, city='Ankara')
...
#params as tuple
def add(*params):
top=0
for p in params:
top+=p
return top
add(1,3,4,6,9)
....
def Topla(num1, num2, num3=0):
'''
DOCSTRING: Toplama yapar
INPUT: Sayi
OUTPUT: Sayilarin toplami
'''
return num1 + num2
a = Topla(3, 5)
b=Topla(2, 8, 11)
help(Topla)
#DOCSTRING: ....;
----------
nums =[(x,y) for x in range(3) for y in range(2)]
#nums=[(0, 0), (0, 1), (1, 0), (1, 1), (2, 0), (2, 1)]
results=[x if x%2==0 else 'TEK' for x in range(1,5)]
#results=['TEK', 2, 'TEK', 4]
years=[1983, 1999, 2000]
ages = [2019-year for year in years]
#ages=[36, 20, 19]
list1 = [letter for letter in "Hello"]
print(list1) # ["H", "e", "l", "l", "o"]
numbers = [x for x in range(5)]
#numbers=[0, 1, 2, 3, 4]
nums = [x**2 for x in range(4)]
#nums = [0, 1, 4, 9]
nums = [x*x for x in range(10) if x%3==0]
#nums=[0, 9, 36, 81]
-----------
list1= [1, 2, 3]
list2 = ["a", "b", "c"]
list(zip(list1, list2)) # [(1,'a'), (2, 'b'), (3, 'c')
----
for item in range(50, 100, 10):
print(item)
#50, 60, 70, 80, 90
list(range(5, 33, 10) # [5, 15, 25]
msg="Hello"
for index,letter in enumerate(msg):
print(index, letter)
#0 H, 1 e, 2 l, 3 l, 4 o
---
import datetime
dt1 = datetime.datetime(2020, 12, 30)
dtFark = datetime.datetime.now() - dt1
print(dtFark.days)
----
if (userName=="a"):
print("hello")
else:
print("no")
---
a=[1,2,3]
b=[1,2,3]
result = a == b # True
result = a is b # False
result = a is not b # True
name= "Ahmet"
print('h' in name) # True
print('h' not in name) # False
(x > 5) and (x <10)
(x > 5) or (x < 10)
result = not (x<10)
---
values= (1, 2, 3) #tuple
x, y, z = values
print(x, y, z) # 1, 2, 3
values = 1, 2, 3, 4, 5 #tuple
x, y, *z = values
print(x, y, z) # 1, 2, [3, 4, 5]
----
SETS
list1 = [1,2,3,1]
print(set(list1)) # [1,2,3] -- unique items.
fruits={"orange", "apple", "banana"}
fruits.add("carrot")
fruits.update(['mango', "grape"])
for item in fruits:
print(item)
---------
DICTIONARY
plakalar = ["adana": "01", "istanbul": "34"]
plakalar["adana"] #01
plakalar["ankara"]="06"
print(plakalar) # ["adana": "01", "istanbul": "34", "ankara", "06"}
...
users = {
"user1": {
"age": 33,
"email": "no",
"roles": [1, 2]
},
"user2": {
"age":11,
"email": "mail2",
"roles": [2,5]
}
}
users["user1"]["age"] #33
users["user2"]["email"] #mail2
users["user2"]["roles"][0] #2
#add more
userName="user3"
email="none"
roles=[1,2,5]
users.update(
{
userName: {
"age": 44,
"email": email,
"roles": roles
}
}
)
dic = {"k1": 1, "k2": 2}
for k,v in dic.items():
print(k, v)
#k1 1 \n k2 2
-------
t = (1, "iki", 3)
print(type(t)) #tuple
t[1]=2 #gives erorr.
tuple works like a list. but items cannot be changed individually.
tpl = [(1,2), (3,5), (2,7)]
for t in tpl:
print (t)
#(1,2) \n (3,5) \n (2,7)
for a,b in tpl:
print(a, b)
#1 2 \n 3 5 \n 2 7
-----
nums=[1,4,7,8,11, 7]
nums.index(7) #2
min(nums) #1
nums.append(44) #add item
nums.insert(-2,33) #insert
item = nums.pop(2) #gets and removes item
nums.remove(44) #removes item
nums.sort()
nums.reverse() #reverse items
numbers.count(7) #2 - gets the item count found in array
nums.clear()
--------
list1=["bir", 3]
print(list1[-2]) #"bir"
isExist= "bir" in list1 #true
list2=[True, 55.3]
list3=list1 + list2
#list3=["bir", 3, True, 55.3]
list3[0:3] #["bir", 3, True]
list3[-2:] = ["hello", 11]
#list3=["bir", 3, "hello", 11]
del list3[-1] #delete item
#list3=["bir", 3, "hello"]
list4=list3[::-1] #reverse items
#list4=["hello", 3, "bir"]
list5=[list1, list2]
#list5=[[l"bir", 3], [True, 55.3]]
print(list5[1][1]) #55.3
copy array values (create a new array)
cities=["Ankara", "İstanbul"]
sehirler=cities[:]
---
msg = "this is a test"
msg.replace("test", "food") # this is a food
msg.upper()
msg.lower()
msg.title() #This Is A Test
msg.capitalize() #This is a test
msg.strip() #trimming
arr = msg.split(' ') #splits.
print(arr[0]) # this
print('---'.join(arr)) #joins the array
#this---is---a---test
msg.find('is') #2 - get index of
msg.rfind('is') #5 - get last index of
msg.startswith("This")
msg.endswith("test")
print(msg.center(50,".")) #aligns the text
#...................This is a test..............
msg.ljust(40,"*")
msg.rjust(40,"*")
msg.count('is') #2 - get repeated count
---------
name="Ali"
surname="Veli"
print(''My name is {} {}'.format(name, surname)); #My name is Ali Veli
print(''My name is {1} {0}'.format(name, surname)); #My name is Veli Ali
print(''My name is {n} {s}'.format(n=name, s=surname)); #My name is Ali Veli
print(f"My name is {name}")
result = 2 / 7
print('the result is {r:8.3}'.format(r=result))
#____0.286
----
isim="Ahmet Ali"
print(isim[2]) #m
len(isim) #9
isim[-1] #i - get char from end.
isim[2:4] #me - get part of string
isim[4:] #t Ali - get the rest
isim[:4] #Ahmet - get the beginning part
isim[1:8:2] #he l - get every 2nd char in the range 1, 8
isim[::-1] #ilA temhA - reverse the text
print(isim*2) # Ahmet AliAhmet Ali
---
x=input("sayı1: ")
toplam = int(x) + 11
a=float(x)
print(type(a)) #float
b=str(x)
print(type(b)) #str
isOnline=True
print(type(isOnline)) #bool
Değişken tanımlanırken değer atanmalı.
Toplu değişken tanımlama:
x, y, name, isStudent = (1, 2.3, "Ahmet", True)
10//3 #3
**: pow
2**3 # 8
type(2) #int
number types: int, float
----------
8.2 - Class
8.3 - Class Methods
8.4 - Inheritance
8.5 - Özel metodlar
12.2 - Fonksiyondan fonksiyon döndürme
12.3 - Fonksiyonları Parametre Olarak Gönderme
12.4 - Decorator Fonksiyonlar
13.1_Pythonda Iterators
14.1_Pythonda Generators
19.3_Numpy Dizilerinin Indekslenmesi
19.4_Numpy Dizi Operasyonları
19.5_Uygulama - Python Numpy
20.8_Pandas DataFrame ile Groupby Kullanımı
20.9_Pandas ile Kayıp ve Bozuk Veri Analizi
20.10_Pandas ile String Fonksiyonları Kullanımı
20.11_Pandas ile Join ve Merge
20.12_Pandas ile DataFrame Metotları
20.14_Uygulama - Youtube İstatistik Verilerinin Analizi
21.2_Matplotlib ile Grafik Oluşturma Plot, SubPlot ve Axes
21.3_Matplotlib ile Figure Oluşturma
24.6_Pyqt5 Qt Designer Kullanımı
25.9_Tablolar
25.13_Formlar
25.16_Dropdown
25.20_Açılır Kutular
25.25_Izgara Sistemi
25.26_Responsive Tasarım
26.3_Pages Uygulamasını Projemize Ekleyelim
26.4_Pages Templates & Layout
26.5_Static Dosyalar
26.6_Bootstrap ile Tasarım
26.7_Movies Uygulamasının Eklenmesi
26.8_Admin Panelinin Aktif Edilmesi
26.9_Model Oluşturma ve Admin Paneline Ekleme
26.10_Admin Panelini Özelleştirelim
26.11_Movie Listeleme Sayfası
26.12_Movie Detay Sayfası
26.13_User Uygulaması
26.14_Register Kullanıcı Oluşturma Sayfası
26.15_Login Kullanıcı Giriş Sayfası
26.16_Django Mesajları
26.17_Nav Links & Logout