Reference
Last updated on 2026-08-24 | Edit this page
Python Quick Reference
Common Data Types
PYTHON
# Integers
x = 42
type(x) # <class 'int'>
# Floats
pi = 3.14159
type(pi) # <class 'float'>
# Strings
name = "Alice"
type(name) # <class 'str'>
# Lists (mutable, ordered)
numbers = [1, 2, 3, 4, 5]
numbers[0] # 1
numbers.append(6)
# Tuples (immutable, ordered)
coords = (10, 20)
coords[0] # 10
# Dictionaries (key-value pairs)
person = {'name': 'Bob', 'age': 30}
person['name'] # 'Bob'
NumPy Quick Reference
Array Operations
PYTHON
# Element-wise operations
arr1 = np.array([1, 2, 3])
arr2 = np.array([4, 5, 6])
arr1 + arr2 # [5 7 9]
arr1 * arr2 # [4 10 18]
arr1 ** 2 # [1 4 9]
# Aggregation functions
arr.sum() # Sum of all elements
arr.mean() # Average
arr.std() # Standard deviation
arr.min() # Minimum value
arr.max() # Maximum value
Array Indexing and Slicing
PYTHON
arr = np.array([10, 20, 30, 40, 50])
arr[0] # 10 (first element)
arr[-1] # 50 (last element)
arr[1:4] # [20 30 40] (slice)
arr[::2] # [10 30 50] (every other element)
# 2D arrays
arr_2d = np.array([[1, 2, 3], [4, 5, 6]])
arr_2d[0, 1] # 2 (row 0, column 1)
arr_2d[1, :] # [4 5 6] (entire second row)
Pandas Quick Reference
Creating DataFrames
PYTHON
import pandas as pd
# From dictionary
data = {'name': ['Alice', 'Bob', 'Charlie'],
'age': [25, 30, 35]}
df = pd.DataFrame(data)
# From CSV file
df = pd.read_csv('gapminder_gdp_africa.csv')
# Display
df.head() # First 5 rows
df.tail() # Last 5 rows
df.info() # Column info
df.describe() # Statistical summary
Data Manipulation
PYTHON
# Adding columns
df['age_squared'] = df['age'] ** 2
# Filtering
young = df[df['age'] < 30]
# Sorting
df.sort_values('age') # Sort ascending
df.sort_values('age', ascending=False) # Sort descending
# Grouping and aggregation
df.groupby('category')['age'].mean()
# Missing data
df.isnull() # Check for NaN values
df.fillna(0) # Replace NaN with 0
df.dropna() # Remove rows with NaN
Matplotlib Quick Reference
Customization
PYTHON
plt.plot([1, 2, 3], label='Line 1')
plt.plot([3, 2, 1], label='Line 2')
plt.legend() # Show legend
plt.xlim(0, 4) # Set x-axis limits
plt.ylim(0, 5) # Set y-axis limits
plt.grid(True) # Show grid
# Color and style
plt.plot([1, 2, 3], 'r--') # Red dashed line
plt.scatter([1, 2, 3], s=50, alpha=0.5) # Size and transparency
# Save figure
plt.savefig('my_plot.png', dpi=300)
Jupyter Notebook Keyboard Shortcuts
Navigation
| Shortcut | Action |
|---|---|
Enter |
Edit mode |
Esc |
Command mode |
Up/Down |
Previous/next cell |
Shift+Enter |
Run cell and move to next |
Ctrl+Enter |
Run cell (stay in place) |
Alt+Enter |
Run cell and insert new below |
Useful Resources
- NumPy: https://numpy.org/doc/stable/
- Pandas: https://pandas.pydata.org/docs/
- Matplotlib: https://matplotlib.org/stable/contents.html
- Python Docs: https://docs.python.org/3/
- HPC Support: its-hpc@pomona.edu