Skip to main content

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.

✓ 60+ operations ✓ Searchable by keyword ✓ Copy button on each snippet

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']).

Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$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.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →