Introduction


  • Python is an interpreted language.
  • Code is commonly developed inside an integrated development environment.
  • A typical Python workflow uses base Python and additional Python packages developed for statistical programming purposes.
  • In-line and external documentation helps ensure that your code is readable.
  • You can find help through the built-in help function and external resources.

Python Fundamentals


  • Basic data types in Python include integers, strings, and floating-point numbers.
  • Use variable = value to assign a value to a variable in order to record it in memory.
  • Variables are created on demand whenever a value is assigned to them.
  • Use print(something) to display the value of something.
  • Use # some kind of explanation to add comments to programs.
  • Built-in functions are always available to use.

Data Transformation


List and Dictionary Methods


  • Lists can contain any Python object including other lists
  • Lists are ordered i.e. indexed and can therefore be sliced by index number
  • Unlike strings and integers, the values inside a list can be modified in place
  • A list which contains other lists is referred to as a nested list
  • Dictionaries behave like unordered lists and are defined using key-value pairs
  • Dictionary keys are unique
  • A dictionary which contains other dictionaries is referred to as a nested dictionary
  • Values inside nested lists and dictionaries can be accessed by an additional index

Loops and Conditional Logic


  • Use for variable in sequence to process the elements of a sequence one at a time.
  • The body of a for loop must be indented.
  • Use len(thing) to determine the length of something that contains other values.
  • Use if condition to start a conditional statement, elif condition to provide additional tests, and else to provide a default.
  • The bodies of the branches of conditional statements must be indented.
  • Use == to test for equality.
  • X and Y is only true if both X and Y are true.
  • X or Y is true if either X or Y, or both, are true.
  • Zero, the empty string, and the empty list are considered false; all other numbers, strings, and lists are considered true.
  • True and False represent truth values.

Alternatives to Loops


  • NULL

Creating Functions


  • Define a function using def function_name(parameter).
  • The body of a function must be indented.
  • Call a function using function_name(value).
  • Numbers are stored as integers or floating-point numbers.
  • Variables defined within a function can only be seen and used within the body of the function.
  • Variables created outside of any function are called global variables.
  • Within a function, we can access global variables.
  • Variables created within a function override global variables if their names match.
  • Use help(thing) to view help for something.
  • Put docstrings in functions to provide help for that function.
  • Specify default values for parameters when defining a function using name=value in the parameter list.
  • Parameters can be passed by matching based on name, by position, or by omitting them (in which case the default value is used).
  • Put code whose parameters change frequently in a function, then call it with different parameter values to customize its behavior.

Data Analysis


  • NULL

Visualizations


  • NULL

Errors and Exceptions


  • NULL