Pandas Operations Reference
Searchable pandas cheatsheet. Find operations by category or keyword — each snippet shows the code with a copy button and a brief description of what it does.
Frequently Asked Questions
What is pandas?▼
pandas is an open-source Python library for data manipulation and analysis. It provides two primary data structures: DataFrame (2D labeled table, like a spreadsheet or SQL table) and Series (1D labeled array). pandas makes it easy to load, clean, transform, aggregate, and analyze structured data. It's the foundation of Python data science and works seamlessly with NumPy, Matplotlib, and scikit-learn.
What is the difference between loc and iloc?▼
loc selects data by label (row index names and column names): df.loc['row_name', 'col_name']. iloc selects by integer position (zero-based): df.iloc[0, 1] selects row 0, column 1. When your index is integers, loc and iloc may look similar but behave differently — loc includes the end of a slice, iloc does not. Use loc for label-based selection and iloc for positional selection.
How do I handle missing values in pandas?▼
pandas uses NaN (Not a Number) to represent missing values. Key operations: df.isna() or df.isnull() detects NaN values; df.dropna() removes rows (or columns) with NaN; df.fillna(value) replaces NaN with a specified value; df.fillna(method='ffill') forward-fills from the previous valid value. For numeric data, df.fillna(df.mean()) fills with column mean.
What is groupby() and how does it work?▼
groupby() splits data into groups based on one or more column values, applies a function to each group, and combines the results. It follows the split-apply-combine pattern. Example: df.groupby('category')['sales'].sum() groups by 'category' and sums 'sales' per group. You can chain multiple aggregations with .agg({'col1': 'sum', 'col2': 'mean'}).
What is the difference between merge() and concat()?▼
merge() is a SQL-style join that combines DataFrames on a common key column (like JOIN in SQL). It supports inner, left, right, and outer joins. concat() stacks DataFrames along an axis — axis=0 stacks rows (like UNION ALL in SQL), axis=1 stacks columns side by side. Use merge() when combining tables with a shared key; use concat() when adding more rows or columns.
How do I apply a custom function to a DataFrame column?▼
Use .apply() for element-wise or row/column operations. For a single column: df['col'].apply(my_func) applies my_func to each element. For rows: df.apply(my_func, axis=1) applies to each row. For multiple columns at once, use .applymap() (element-wise across DataFrame). For vectorized operations on numeric columns, prefer NumPy functions directly (faster than apply): df['col'] * 2, np.sqrt(df['col']).
Related Products
on GumroadDeveloper Productivity Bundle
Stop rebuilding the same setup every project. 51 VSCode snippets, 40 Git aliases, 5 Docker Compose stacks, 5 GitHub Actions workflows, 5 README templates, and a dotfiles kit. Set up a professional dev environment in under an hour.
Buy on Gumroad →AI Prompt Engineering Toolkit
58 structured prompt templates for Claude, ChatGPT, and Gemini — organized by use case. Code Review, Debugging, Documentation, Architecture, and 10 model-specific tips. Stop writing prompts from scratch.
Buy on Gumroad →Developer Cheat Sheet Bundle
10 print-ready cheat sheets for the tools developers use every day: Git, Docker, Linux CLI, SQL, Regex, HTTP Status codes, VS Code shortcuts, Bash scripting, jq/JSON, and Markdown.
Buy on Gumroad →You Might Also Need
GitHub Actions Workflow Generator
Generate GitHub Actions YAML workflows instantly. Choose triggers (push, PR, schedule), runtime (Node.js, Python, Go, Rust), and jobs (test, lint, build, Docker, GitHub Pages). Copy-ready .github/work
Open free tool →
Regex Tester Pro
Free Regex Tester Pro with real-time match highlighting. Test regular expressions with live visual feedback. Supports JS, Python, and Ruby flavors, all flags, capture groups, and 6 built-in presets. R
Open free tool →
Dockerfile Generator
Interactive wizard to generate production-ready Dockerfiles for Node.js, Python, Go, Java, and Rust. Multi-stage builds, port config, custom layers.
Open free tool →
More Free Tools
Related Articles
Pandas vs Polars vs DuckDB: Python Data Analysis in 2026
Comprehensive comparison of Pandas, Polars, and DuckDB for Python data analysis in 2026. Performance benchmarks, lazy evaluation, SQL interface, memory usage, and real code examples to help you choose the right tool.
DSPy: Building Self-Optimizing LLM Pipelines in 2026
DSPy 2026: build self-optimizing LLM pipelines with signatures, modules, and teleprompters. Real-world examples vs manual prompting for developers.
MLOps Platforms in 2026: MLflow vs Kubeflow vs Vertex AI vs SageMaker
Complete MLOps platform comparison for 2026. MLflow vs Kubeflow vs Vertex AI vs SageMaker — deployment patterns, pricing, pros/cons, and which to choose.
MLflow vs Weights & Biases vs Neptune: ML Experiment Tracking Compared
Compare MLflow, Weights & Biases, and Neptune for ML experiment tracking. Feature comparison, pricing, integrations, and which tool to choose for your team.
PyTorch vs TensorFlow vs JAX: Which ML Framework in 2026?
In-depth comparison of PyTorch, TensorFlow, and JAX for machine learning in 2026. Speed benchmarks, ecosystem, research vs production use cases, and an opinionated verdict.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$9/mo after trial · Cancel anytime
Want the full toolkit?
Get DevPlaybook Pro
Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →