Ugrás a fő tartalomra

Google Colab alapok felület és lehetőségek

Colab Python SqLite használat:

Töltsuk fel az adatbázis filet a content mappába ( Files menüpontból)


Leprogramozandó lépések:


  • modul betöltése
  • kapcsolódás
  • új tábla létrehozás
  • induló adatfeltöltés
  • adatok lekérdezése és megjelenése

Példa:


## Installálás csak egyszerkel
#  !pip install db-sqlite3  

import sqlite3 as lite
import sys
conn = lite.connect("/content/mie_pills_periods.s3db")
cur = conn.cursor()

#---
# cur.execute("CREATE TABLE drinks(Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT, Price REAL)") ## Tábla létrehozása (üres)
# cur.execute("CREATE TABLE fruits(Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT, Price REAL)") ## Tábla létrehozása (üres)

#--
# cur.execute("INSERT INTO drinks(Id, Name, Price ) VALUES ( 4, 'NEV01', 12.1 )")        # Adat feltöltés 1
# cur.execute("INSERT INTO drinks(Id, Name, Price ) VALUES ( 11, 'NEV11', 112.1 )")     # Adat feltöltés 2
# cur.execute("INSERT INTO drinks(Id, Name, Price ) VALUES ( 21, 'NEV21', 42.1 )")      # Adat feltöltés 3

#---
## Véglegesités
conn.commit()

#--- lekérdezés
##list(cur.execute("select * from periods limit 2;"))
#-1
# eredmeny=list(cur.execute("select * from drinks limit 2;"))
# print(eredmeny)

#-2
cur.execute("select * from drinks")
rows = cur.fetchall()
for row in rows:
        print(row)


A minta elérési linkje  vagy egy másik linkje

Alapok1  Alapok2 


$e^{i\pi} + 1 = 0$

$$e^x=\sum_{i=0}^\infty \frac{1}{i!}x^i$$



Gyorsgomb funkció létrehozása:
%%javascript
Jupyter.keyboard_manager.command_shortcuts.add_shortcut('r', {
help 'run cell',
help_index 'zz',
handler function (event) {
IPython.notebook.execute_cell();
return false;
}}
);

[ ]: %%javascript
Jupyter.keyboard_manager.command_shortcuts.add_shortcut('r'function (event) {
IPython.notebook.execute_cell();
return false;
});
Likewise, to remove a shortcut, use remove_shortcut:
[ ]: %%javascript
Jupyter.keyboard_manager.command_shortcuts.remove_shortcut('r');




JavaScript code in custom.js will be executed when the notebook app starts and can then be
used to customize almost anything in the UI and in the behavior of the notebook.
custom.js can be found in the ~/.jupyter/custom/custom.js. You can share your custom.js with others.

###               IPython notebook használata



%pylab inline ## első parancs // futtatása : Shift + Enter

%pylab    ##magic command betölti az IPython namespace-t

az inline direktiva a garfikai megjelenitést engedélyezi külső program nélkül is



%pylab inline     ## első parancs legyen, edit mod bekapcsolására szolgál

--> imports NumPy and matplotlib

--> bekapcsolja az inline plots rajzolás lehetőséget.




Populating the interactive namespace from numpy and matplotlib



Ha parancs kezdete % és %% akkor mágikus parancs / magic commands -al a futtatást befolyásoljuk





Két tipusa a mágikus parancs jelőlő prefixnek:

• Sorra vonatkozó (Line-oriented): Prefixe single percent (%)

• Cellára vonatkozó (Cell-oriented): Prefixe double percent (%%)



from mpl_toolkits.mplot3d import Axes3D ## külün kell betölteni





%lsmagic          ## összes mágikus parancs lehetőség és jelentésének kilistázása



%autosave 300     ## automatikus mentés bekapcsolása, időtartam megadással

%autosave 0       ## automatikus mentés kikapcsolása



%load_ext cythonmagic   ## cythonmagic kiterjesztet modul betöltése

%%cython                ## használat

cimport cython

from libc.math cimport sin

@cython.cdivision(True)



Magic   -> Purpose

%cd    -> Changes the directory

%pwd   -> Prints the current directory

%ls    -> Lists the current directory contents

%mkdir -> Creates a new directory

%rmdir -> Removes a directory

%echo  -> Prints a string

%alias -> Creates an alias



%load lorenz.py   ## python file betöltése

%load http://matplotlib.org/mpl_examples/pylab_examples/boxplot_demo2.py



%run lorenz.py     ## py állomány futtatása



## más program nyelvek használata:

Cell magic -> Language

%%HTML or %%html -> HTML

%%SVG or %%svg -> Scaled Vector Graphics Language (SVGL)

%%bash -> The Bash scripting language, which is available in

Unix-like -> systems such as Ubuntu and Mac OS X

%%cmd -> MS Windows command-line language

%%javascript -> JavaScript

%%latex -> LaTeX, the scientific-oriented document preparation language

%%perl -> The PERL scripting language

%%powershell -> The MS Windows PowerShell language

%%python2 or %%python3 -> Run a script written in a version of Python different than the one the notebook is running

%%ruby -> The Ruby scripting language



%automagic off     ## mágikus paracsok kikapcsolása







!dir    ## Shell parancs futatása, könyvtár lista



## Shift + Enter   ## gyors parancs/gyors billentyű kombináció parancs sor tartalmának futtatása



## (normál) modulok importálása

import numpy as np



%timeit sin_area(0, pi, 10000)  ## futásidő vizsgálat



### ---- más prormanyelvek használata

%%SVG

<svg width="400" height="300">

<circle cx="200" cy="150" r="100" style="fill:Wheat; stroke:SteelBlue; stroke-width:5;"/>

<line x1="10" y1="10" x2="250" y2="85" style="stroke:SlateBlue; stroke-width:4"/>

<polyline points="20,30 50,70 100,25 200,120" style="stroke:orange; stroke-width:3; fill:olive; opacity:0.65;"/>

<rect x="30" y="150" width="120" height="75" style="stroke:Navy; stroke-width:4; fill:LightSkyBlue;"/>

<ellipse cx="310" cy="220" rx="55" ry="75" style="stroke:DarkSlateBlue; stroke-width:4; fill:DarkOrange; fill-opacity:0.45;"/>

<polygon points="50,50 15,100 75,200 45,100" style="stroke:DarkTurquoise; stroke-width:5; fill:Beige;"/>





%%html

<h1 id="hellodisplay">Hello, world!</h1>





%%javascript

element = document.getElementById("hellodisplay")

element.style.color = 'blue'





### grafika készítése és mentése

%matplotlib

xvalues = linspace(-pi,pi,200)

fcts = [('sin', sin), ('cos', cos), ('exp', exp)]

for fctname, fct in fcts:

yvalues = fct(xvalues)

fig=figure()

ax = fig.add_subplot(1,1,1)

ax.plot(xvalues, yvalues, color='red')

ax.set_xlabel('$x$')

strname = '$\\%s(x)$' % fctname

ax.set_ylabel(strname)

fig.savefig(fctname + '.png')



### grafika alaphelyzetbe állítása és betöltése

%matplotlib inline



## ---

To run a cell, the following shortcuts are used:

°° To run a cell and move to the next cell, press Shift + Enter

°° To run a cell, but stay in the same cell, press Ctrl + Enter

°° To run a cell and insert a new cell below it, press Alt + Enter

°° To create a new line in the current cell, press Enter







https://github.com/fchollet/deep-learning-with-python-notebooks





A modulok hierarchikus struktúrába rendezhetők.

Ez esetben az almodulokat tartalmazó modulok, amiket packageeknek is neveznek,

a filerendszer könyvtáraiként vannak definiálva.



A modulok elnevezése tehát konkatenációval történik : modul.almodul.

A kód portabilitásának egyszerűbbé tételéhez mindegyik könyvtárnak tartalmazni kell egy

__init__.py nevű fájlt.

Ahhoz, hogy lehetséges legyen valamennyi almodul betöltése,

ennek a fájlnak tartalmazni kell a package moduljainak listáját az __all__ változóban.



$ cat graphical / __init__ .py

__all__ = [ ’basic ’ , ’advanced ’]



Az operációs rendszer neve:

>>> sys. platform



Minden metódus függvényként van definiálva, melynek első argumentuma (a self) azt az objektumot reprezentálja,

melyre a metódus a végrehajtásakor alkalmazva lesz



----- Állomány műveletek : csv, txt, xls, json, xml



----- Adatbázis múveletek: oracle, sqlite



----------------



https://nbviewer.jupyter.org/github/ipython/ipython/blob/6.x/examples/IPython%20Kernel/Cell%20Magics.ipynb





Ctrl + Shift + P  gyorsító gombok



%%javascript





common libraries including NumPy, Pandas, SciPy and Matplotlib.



%lsmagic  ## varázsos parancsok listája



Available line magics:

%alias %alias_magic %autocall %automagic %autosave %bookmark %cat %cd %clear %colors %config %connect ..

Available cell magics:

%%! %%HTML %%SVG %%bash %%capture %%debug %%file %%html %%javascript %%js %%latex %%perl ..

link: https://ipython.readthedocs.io/en/stable/interactive/magics.html



%matplotlib notebook

%matplotlib inline



%run ./two-histograms.ipynb  ## külső py file lefuttatása



%%writefile pythoncode.py    ## paramcs terület tartalmánek kiírása



%store data  ## másik példánynak változó átadása

és


%store -r data


Megjegyzések