Loading [MathJax]/extensions/AssistiveMML.js
Plotting and Programming in Python
- Скрипти Python - це звичайні текстові файли.
- Застосування Jupyter Notebook для редагування та запуску Python
- Jupyter Notebook має командний режим та режим редагування.
- Використовуйте клавіатуру та мишу для виділення та редагування
комірок.
- Notebook підтримує мову розмітки текстів Markdown.
- Markdown робить більшість того, що можна зробити у HTML.
- Використовуйте змінні для зберігання значень.
- Використовуйте
print
для виводу значень.
- Змінні зберігаються між комірками.
- Змінні мають бути створені перед їх використанням.
- Змінні можна використовувати для обчислень.
- Використовуйте індекс, щоб отримати один символ із рядка.
- Використовуйте зріз, щоб отримати підрядок.
- Використовуйте вбудовану функцію
len
, щоб знайти
довжину рядка.
- У Python важливо, який регістр використовується.
- Використовуйте змістовні назви змінних.
- Кожне значення має тип.
- Вбудована функція
type
повертає тип значення.
- Типи контролюють, які операції можна виконувати над значеннями.
- Рядки можна додавати і помножувати.
- Рядки мають довжину (але числа її не мають).
- Необхідно перетворювати числа в рядки або навпаки під час виконання
певних операцій.
- Цілі та дійсні числа можна використовувати разом.
- Змінні можуть набути своє значення тільки через присвоювання.
- Використовуйте коментарі при створенні документації програм.
- Функції можуть сприймати нуль або більше аргументів.
- Поширені вбудовані функції
max
, min
та
round
.
- Функції можуть працювати лише з певними аргументами (комбінаціями
аргументів).
- Функції можуть мати значення за замовчуванням для певних
аргументів.
- Використовуйте вбудовану функцію
help
, щоб отримати
довідку щодо функції.
- Є два шляхи отримання допомоги у Jupyter Notebook.
- Кожна функція щось повертає.
- Python повідомляє про синтаксичну помилку, коли він не може
зрозуміти вихідний код програми.
- Python повідомляє про помилку виконання (runtime error), коли щось
йде не так під час виконання програми.
- Якщо перечитаєте вихідний код, можна виправити синтаксичні помилки,
а якщо відстежите дії інтерпретатора - помилки виконання.
- Більша частина потужності мови програмування полягає в її
бібліотеках.
- Щоб використати бібліотечний модуль, його спочатку потрібно
імпортувати.
- Використовуйте
help
, щоб дізнатися про вміст
бібліотечного модуля.
- Імпортуйте певні елементи з бібліотечного модуля, щоб скоротити
програми.
- Створюйте псевдонім для бібліотечного модуля під час його імпорту
для скорочення програм.
- Use the Pandas library to get basic statistics out of tabular
data.
- Use
index_col
to specify that a column’s values should
be used as row headings.
- Use
DataFrame.info
to find out more about a
dataframe.
- The
DataFrame.columns
variable stores information about
the dataframe’s columns.
- Use
DataFrame.T
to transpose a dataframe.
- Use
DataFrame.describe
to get summary statistics about
data.
- Use
DataFrame.iloc[..., ...]
to select values by
integer location.
- Use
:
on its own to mean all columns or all rows.
- Select multiple columns or rows using
DataFrame.loc
and
a named slice.
- Result of slicing can be used in further operations.
- Use comparisons to select data based on value.
- Select values or NaN using a Boolean mask.
-
matplotlib
is the
most widely used scientific plotting library in Python.
- Plot data directly from a Pandas dataframe.
- Select and transform data, then plot it.
- Many styles of plot are available: see the Python Graph
Gallery for more options.
- Can plot many sets of data together.
- A list stores many values in a single structure.
- Use an item’s index to fetch it from a list.
- Lists’ values can be replaced by assigning to them.
- Appending items to a list lengthens it.
- Use
del
to remove items from a list entirely.
- The empty list contains no values.
- Lists may contain values of different types.
- Character strings can be indexed like lists.
- Character strings are immutable.
- Indexing beyond the end of the collection is an error.
- A for loop executes commands once for each value in a
collection.
- A
for
loop is made up of a collection, a loop variable,
and a body.
- The first line of the
for
loop must end with a colon,
and the body must be indented.
- Indentation is always meaningful in Python.
- Loop variables can be called anything (but it is strongly advised to
have a meaningful name to the looping variable).
- The body of a loop can contain many statements.
- Use
range
to iterate over a sequence of numbers.
- The Accumulator pattern turns many values into one.
- Use
if
statements to control whether or not a block of
code is executed.
- Conditionals are often used inside loops.
- Use
else
to execute a block of code when an
if
condition is not true.
- Use
elif
to specify additional tests.
- Conditions are tested once, in order.
- Create a table showing variables’ values to trace a program’s
execution.
- Use a
for
loop to process files given a list of their
names.
- Use
glob.glob
to find sets of files whose names match a
pattern.
- Use
glob
and for
to process batches of
files.
- Break programs down into functions to make them easier to
understand.
- Define a function using
def
with a name, parameters,
and a block of code.
- Defining a function does not run it.
- Arguments in a function call are matched to its defined
parameters.
- Functions may return a result to their caller using
return
.
- The scope of a variable is the part of a program that can ‘see’ that
variable.
- Follow standard Python style in your code.
- Use docstrings to provide builtin help.
- Python supports a large and diverse community across academia and
industry.
- We are constantly seeking to improve this course.