Фишки Python
29 subscribers
2 photos
3 files
29 links
Всё что ты хотел узнать, но ленился спросить.

Декораторы, итераторы и контракты.
Download Telegram
IPython, NumPy, Pandas, Matplotlib, Scikit-Learn
NumPy — для работы с однородными данными в виде массивов
Pandas — для работы с неоднородными и поименованными данными
SciPy — для общих научных вычислительных задач
Matplotlib — для визуализаций типографского качества
IPython — для интерактивного выполнения и совместного использования кода
Scikit-Learn — для машинного обучения и множества других инструментов
Jupyter - автодополнение по Tab (It will also complete filenames in the current directory)
? -> Introduction and overview of IPython's features (this screen).
object? -> Details about 'object'.
object?? -> More detailed, verbose information about 'object'.
%quickref -> Quick reference of all IPython specific syntax and magics.
help -> Access Python's own help system.
%magic for information on the magic subsystem
%hist - история команд
!ls или !dir - запуск команды в системной оболочке
_ih - список последних команд, _i - запуск последней команды, _ii - предпоследней и т.д.
_oh - output history, _ - предыдущий вывод, __ - предпредыдущий
_dh - directory history
?datetime.*t* - list of all items in object with t
Line magics take a single % and cell magics are prefixed with two %%
%timeit x=10 : time the 'x=10' statement with high precision.

%%timeit x=2**100
x**100
Time 'x**100' with a setup of 'x=2**100'; setup code is not counted. This is an example of a cell magic.
cp ${f}.txt $bar : Variable expansion in magics and system commands
files = !ls /usr : Capture system command output
%writefile [-a] filename : Write the contents of the cell to a file.
Esc will take you into command mode where you can navigate around your notebook with arrow keys.

While in command mode:
A to insert a new cell above the current cell, B to insert a new cell below.
M to change the current cell to Markdown, Y to change it back to code
D + D (press the key twice) to delete the current cell
Enter will take you from command mode back into edit mode for the given cell.
Shift + Tab will show you the Docstring (documentation) for the the object you have just typed in a code cell - you can keep pressing this short cut to cycle through a few modes of documentation.
Ctrl + Shift + - will split the current cell into two from where your cursor is.
Esc + F Find and replace on your code but not the outputs.
Esc + O Toggle cell output.
Select Multiple Cells:
Shift + J or Shift + Down selects the next sell in a downwards direction. You can also select sells in an upwards direction by using Shift + K or Shift + Up.
Once cells are selected, you can then delete / copy / cut / paste / run them as a batch. This is helpful when you need to move parts of a notebook.
You can also use Shift + M to merge multiple cells.
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"

Вычисляет и отображает результат по каждой строке, пример:

from pydataset import data
q = data('quakes')
q.head()
q.tail()

Отобразит таблицу и head и tail