Pandas Cheat Sheet
On This Page
Bonus Chapter: Pandas Cheat Sheet
Quick reference for the Pandas operations covered in Module 14 — the single most important toolkit for real data analytics work.
CS2.1 Reading & Inspecting Data
| Command | Purpose |
|---|
| pd.read_csv('file.csv') | Load a CSV file |
| pd.read_excel('file.xlsx') | Load an Excel file |
| df.head(n) / df.tail(n) | First/last n rows |
| df.shape | (rows, columns) |
| df.info() | Column types & nulls |
| df.describe() | Statistical summary |
| df.columns | List column names |
CS2.2 Selecting & Filtering
df['col'] # single column
df[['col1','col2']] # multiple columns
df.iloc[0] # row by position
df.loc[df['fee'] > 12000] # filter rows by condition
df[(df['course']=='SEO') & (df['fee']>=12000)] # multiple conditions
CS2.3 Cleaning Data
| Command | Purpose |
|---|
| df.isnull().sum() | Count missing values per column |
| df.dropna() | Remove rows with missing values |
| df.fillna(value) | Fill missing values |
| df.drop_duplicates() | Remove duplicate rows |
| df.rename(columns={...}) | Rename columns |
| df.astype(type) | Convert column data type |
CS2.4 GroupBy & Aggregation
df.groupby('course')['fee'].sum()
df.groupby('course')['fee'].mean()
df.groupby('course').agg(['sum','mean','count'])
pd.pivot_table(df, values='fee', index='course', aggfunc='sum')
CS2.5 Merge & Join
| Command | Purpose |
|---|
| pd.merge(df1, df2, on='id') | Join on a common column (like VLOOKUP) |
| pd.concat([df1, df2]) | Stack DataFrames together |
| how='left' / 'right' / 'outer' / 'inner' | Merge type |
CS2.6 Sorting, Apply & Export
| Command | Purpose |
|---|
| df.sort_values('col', ascending=False) | Sort rows |
| df['col'].apply(func) | Apply a custom function |
| df['col'].map({...}) | Map values using a dict |
| df['col'].replace(a, b) | Replace specific values |
| df.to_csv('out.csv', index=False) | Export to CSV |
| df.to_excel('out.xlsx') | Export to Excel |
ℹ Reminder
Full explanations and worked examples for every command on this sheet are in Module 14 of the main training manual.