Basics
This cheat sheet provides beginners and intermediate users a guide to starting using Python.
Accessing help and getting object types
Importing packages
Python packages are a collection of useful tools developed by the open-source community. They extend the capabilities of the Python language. To install a new package (for example, pandas), you can go to your command prompt and type in pip install pandas
. Once a package is installed, you can import it as follows:
The working directory
The working directory is the default file path that Python reads or saves files into. An example of the working directory is C://file/path
. The os library is needed to set and get the working directory.
Operators
Arithmetic operators
Assignment operators
Numeric comparison operators
Logical operators
Getting started with lists
A list is an ordered and changeable sequence of elements. It can hold integers, characters, floats, strings, and even objects.
Creating lists
List functions and methods
Selecting list elements
Python lists are zero-indexed (the first element has index 0). For ranges, the first element is included but the last is not.
Concatenating lists
Getting started with dictionaries
A dictionary stores data values in key-value pairs. That is, unlike lists which are indexed by position, dictionaries are indexed by their keys, the names of which must be unique.
Creating dictionaries
Dictionary functions and methods
NumPy arrays
NumPy is a Python package for scientific computing. It provides multidimensional array objects and efficient operations on them. To import NumPy, you can run this Python code import numpy as np
Creating arrays
Math functions and methods
All functions take an array as the input.
Getting started with characters and strings
Creating strings
Selecting string elements
Combining and splitting strings
Mutate strings
Getting started with DataFrames
Pandas is a fast and powerful package for data analysis and manipulation in Python. To import the package, you can use import pandas as pd
. A pandas DataFrame is a structure that contains two-dimensional data stored as rows and columns. A pandas series is a structure that contains one-dimensional data.
Creating DataFrames
Selecting DataFrame Elements
Manipulating DataFrames
Last updated on