Pandas Cheat Sheet: 30 Essential Commands for Data Wrangling

If you work with data in Python, the pandas library is the tool you reach for first. But its API is huge, and remembering the exact method for every task is impossible. That is where a good pandas cheat sheet comes in. This guide collects 30 essential commands for data wrangling in Python — the operations you actually use every day to load, clean, filter, transform, and export your data.
Bookmark this pandas cheat sheet, keep it next to your editor, and you will spend less time searching the docs and more time analyzing. Every example assumes you have already run import pandas as pd.
Loading and Inspecting Data
Before you wrangle anything, you need to get data into a DataFrame and understand its shape.
- Read a CSV file:
df = pd.read_csv('data.csv') - Read an Excel file:
df = pd.read_excel('data.xlsx') - Read JSON:
df = pd.read_json('data.json') - Preview the first rows:
df.head()(usedf.tail()for the last rows) - Get dimensions:
df.shapereturns(rows, columns) - Summarize structure and dtypes:
df.info() - Generate summary statistics:
df.describe() - List column names:
df.columns
These eight commands answer the first question of any project: what am I working with? Always run df.info() and df.describe() early — they reveal missing values, surprising data types, and outliers before they cause bugs.
Selecting and Filtering
Data wrangling is mostly about isolating the rows and columns you care about.
- Select one column:
df['price'] - Select multiple columns:
df[['price', 'quantity']] - Select by label:
df.loc[0, 'price'] - Select by position:
df.iloc[0, 2] - Filter rows by condition:
df[df['price'] > 100] - Filter with multiple conditions:
df[(df['price'] > 100) & (df['in_stock'])] - Filter by a list of values:
df[df['category'].isin(['AI', 'Data'])]
Note the parentheses around each condition in command 14 — pandas requires them, and forgetting them is one of the most common beginner errors. Use & for AND and | for OR, never the Python keywords and/or.
Cleaning Messy Data
Real-world data is rarely tidy. This is the part of the pandas cheat sheet you will return to most.
- Count missing values per column:
df.isnull().sum() - Drop rows with missing values:
df.dropna() - Fill missing values:
df['price'].fillna(0) - Remove duplicate rows:
df.drop_duplicates() - Rename columns:
df.rename(columns={'old': 'new'}) - Change a column's type:
df['price'] = df['price'].astype(float) - Apply a function to a column:
df['name'] = df['name'].str.strip().str.lower()
The .str accessor (command 22) unlocks dozens of string methods like .replace(), .contains(), and .split() — invaluable for cleaning text columns. If you are coming from databases, many of these ideas will feel familiar; our SQL commands cheat sheet covers the equivalent operations in SQL.
Transforming and Aggregating
Once your data is clean, you reshape it to answer questions.
- Sort by a column:
df.sort_values('price', ascending=False) - Create a new column:
df['total'] = df['price'] * df['quantity'] - Group and aggregate:
df.groupby('category')['price'].mean() - Multiple aggregations:
df.groupby('category').agg({'price': 'mean', 'quantity': 'sum'}) - Build a pivot table:
df.pivot_table(index='category', values='price', aggfunc='sum') - Apply a custom function:
df['price'].apply(lambda x: x * 1.2)
The groupby pattern (commands 25 and 26) is the workhorse of data analysis — split your data into groups, apply a function, and combine the results. Master it and most analytical questions become one-liners.
Combining and Exporting
Finally, join datasets together and save your results.
- Merge two DataFrames:
pd.merge(df1, df2, on='id', how='left') - Export to CSV:
df.to_csv('output.csv', index=False)
The how parameter in merge controls the join type — left, right, inner, or outer — exactly like a SQL join. Setting index=False on export keeps pandas from writing an extra unnamed index column to your file.
How to Use This Pandas Cheat Sheet Effectively
Memorizing 30 commands is not the goal. The goal is recognition: knowing that a task like "fill missing values" has a clean one-line solution, then looking it up here. Print this pandas cheat sheet or keep the tab open, and over a few weeks the most common commands will become muscle memory.
To go deeper, type these commands yourself rather than copying them. Our free, hands-on Pandas data wrangling course lets you practice each operation on real datasets in the browser. If you want the broader context of how pandas fits into machine learning and analytics workflows, the Python for AI & Data Science path is the natural next step. And once your data is clean, you will want to visualize your data with Matplotlib and Seaborn to turn numbers into insight.
Conclusion
Data wrangling is 80% of most data science work, and pandas is the fastest way to do it in Python. These 30 commands — from read_csv to groupby to merge — cover the vast majority of everyday tasks. Keep this pandas cheat sheet handy, practice on real data, and pair it with our Python cheat sheet for the language fundamentals underneath.
Ready to put it into practice? Start the free Pandas data wrangling course and turn this cheat sheet into a skill you actually own.
Liked this article?
Get the weekly AI digest
New free courses, the latest from the blog, and practical AI tips.
Free forever. Unsubscribe anytime.
Related articles
Python for Finance Professionals: A Complete Guide to Data Analysis
Learn how finance professionals can leverage Python for data analysis, automate financial reports, and perform portfolio analysis. A comprehensive guide covering Python basics, Pandas, NumPy, and the transition from Excel to Python.

10 Essential Python Libraries for Machine Learning in 2026
Discover the 10 essential python libraries machine learning beginners need in 2026. From NumPy to PyTorch, learn what each does and when to use it.

Python Cheat Sheet: Commands You'll Use Every Day
A quick-reference Python cheat sheet covering strings, lists, dicts, file I/O, loops, functions, classes, and common libraries with copy-paste-ready code snippets.

