Python + NumPy + Pandas Functions Cheat Sheet (with Descriptions)
------------------------------------------------------------------
Python Built-in Functions
Math
- abs(x): Return the absolute value of a number.
- round(x): Round a number to the nearest integer.
- pow(x, y): Return x raised to the power y.
- min(x), max(x): Return the smallest/largest item.
- sum(iterable): Sum all elements in an iterable.
- divmod(x, y): Return the quotient and remainder of division.
Type Conversion
- int(x): Convert to integer.
- float(x): Convert to float.
- str(x): Convert to string.
- bool(x): Convert to boolean.
- list(x): Convert to list.
- tuple(x): Convert to tuple.
- set(x): Convert to set.
- dict(x): Convert to dictionary.
String Handling
- len(s): Return the number of characters in a string.
- format(): Format a string.
- split(): Split a string into a list.
- join(): Join a list into a string.
- strip(): Remove leading/trailing spaces.
- replace(old, new): Replace substring.
- find(sub): Find first occurrence of substring.
- count(sub): Count occurrences of substring.
List/Collection
- append(x): Add element at end.
- extend(iterable): Extend list by appending elements.
- insert(i, x): Insert at a given position.
- remove(x): Remove first occurrence.
- pop(i): Remove and return element.
- sort(): Sort list in place.
- sorted(iterable): Return sorted list.
- reverse(): Reverse list.
Dictionary
- keys(): Return dictionary keys.
- values(): Return dictionary values.
- items(): Return dictionary items.
- get(key): Get value by key.
- update(other_dict): Update dictionary.
- pop(key): Remove key and return its value.
File Handling
- open(file): Open a file.
- read(): Read file content.
- write(data): Write to a file.
- close(): Close a file.
Iteration
- enumerate(iterable): Return index and value.
- zip(*iterables): Aggregate elements.
- map(func, iterable): Apply function to all items.
- filter(func, iterable): Filter items.
- reduce(func, iterable): Apply function cumulatively (from functools).
Miscellaneous
- print(): Output to console.
- input(): Get input from user.
- help(): Display help information.
- id(obj): Return memory address.
- isinstance(obj, type): Check type.
- type(obj): Get type.
- dir(obj): List valid attributes.
NumPy Functions
Array Creation
- array(): Create a NumPy array.
- arange(): Create array with range.
- linspace(): Create array with evenly spaced values.
- zeros(): Create array of zeros.
- ones(): Create array of ones.
- eye(): Create identity matrix.
- full(shape, fill_value): Create filled array.
- empty(shape): Create empty array.
- identity(n): Create identity matrix.
(Random, Math Operations, Statistics, Matrix Operations, Logical Operations continued...)
Pandas Functions
(Data Creation, Export, Viewing Data, Selection, Manipulation, Aggregation, Missing Values,
Merging)
Other Popular Libraries
(Matplotlib, Seaborn, Scikit-learn, OS & Sys...)
Sample Python + NumPy + Pandas Code
```python
import numpy as np
import pandas as pd
arr = np.array([1, 2, 3, 4, 5])
print(np.mean(arr)) # 3.0
df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
print(df.head())
```