Have a question?
Message sent Close

10 Pandas One-Liners Every Data Analyst Should Know

Pandas can either feel like magic or like fighting NumPy with both hands tied. Ten one-liners cover the vast majority of day-to-day analyst work — memorise these and your notebooks shrink by half. The ten…

10 Pandas One-Liners Every Data Analyst Should Know

Pandas can either feel like magic or like fighting NumPy with both hands tied. Ten one-liners cover the vast majority of day-to-day analyst work — memorise these and your notebooks shrink by half.

The ten

  • Top rows per groupdf.groupby('city').head(3).
  • Conditional columndf['tier'] = np.where(df['amount'] > 1000, 'high', 'low').
  • Cross-tabpd.crosstab(df.city, df.product, values=df.revenue, aggfunc='sum').
  • Rolling averagedf['ma7'] = df['sales'].rolling(7).mean().
  • Percent changedf['pct'] = df['sales'].pct_change().
  • Pivotdf.pivot_table(index='date', columns='city', values='sales', aggfunc='sum').
  • Drop duplicates by columndf.drop_duplicates(subset=['email'], keep='last').
  • Filter by multiple valuesdf[df['city'].isin(['Chennai', 'Pune'])].
  • String containsdf[df['title'].str.contains('Engineer', case=False, na=False)].
  • Apply with axisdf.apply(lambda r: r['a'] + r['b'], axis=1).

The bonus skill

Learn .assign() for chainable column additions and you stop reassigning to df at every step. Method chaining makes notebooks read like a recipe.

When to leave pandas

Above ten million rows, pandas becomes painful. Reach for DuckDB (SQL on Parquet, brilliant), Polars (pandas-like API, much faster), or just push the work into the warehouse. Knowing when to step off pandas is itself a senior signal.

Practice tip

Take a Kaggle dataset and redo any familiar tutorial entirely with method chains. The discipline forces these one-liners into muscle memory.

Keep reading

More from Data Science & Analytics

Data Analyst vs Data Scientist vs Data Engineer: Salary & Roles in 2026
Data Science & Analytics

Data Analyst vs Data Scientist vs Data Engineer: Salary & Roles in 2026

May 10, 2026 · 1 min read
SQL Interview Questions That Trip Up Every Junior Analyst
Data Science & Analytics

SQL Interview Questions That Trip Up Every Junior Analyst

Apr 18, 2026 · 1 min read
Power BI vs Tableau in 2026: A Practical Comparison
Data Science & Analytics

Power BI vs Tableau in 2026: A Practical Comparison

Apr 5, 2026 · 1 min read
Call us Chat on WhatsApp