1. What is Pandas?
BeginnerAnswer: Python library for data manipulation and analysis
Pandas is a powerful Python library providing data structures and tools for data manipulation and analysis. Built on NumPy, it's essential for data science.
24 questions that come up in Pandas technical interviews, each with the answer and an explanation of why it is right.
Test yourself — 90 question bankAnswer: Python library for data manipulation and analysis
Pandas is a powerful Python library providing data structures and tools for data manipulation and analysis. Built on NumPy, it's essential for data science.
Answer: Using array operations instead of loops
Vectorization uses NumPy array operations instead of Python loops. Dramatically faster. Use built-in methods, broadcasting, avoid apply/iterrows when possible.
Answer: Groups data by column values for aggregation
groupby() splits data into groups based on criteria. Apply aggregation functions (mean, sum, count). Foundation of split-apply-combine pattern in Pandas.
Answer: Series and DataFrame
Series (1D labeled array) and DataFrame (2D labeled data structure) are the two primary Pandas data structures. DataFrame is most commonly used.
Answer: Avoid iteration; use vectorization
Best: avoid iteration with vectorization. If needed: itertuples() > iterrows() > loop. itertuples() fastest. iterrows() slow due to Series creation. Never use loop.
Answer: df.groupby('col').agg(function)
Use df.groupby('col').agg(func). Can use built-in (mean, sum) or custom functions. Pass multiple functions or dict for different columns.
Answer: Joins DataFrames like SQL join
pd.merge(df1, df2) performs database-style joins. Types: inner, outer, left, right. Join on columns or indices. Similar to SQL JOIN operations.
Answer: One-dimensional labeled array
Series is a one-dimensional labeled array that can hold any data type. Like a column in a spreadsheet or dictionary with index labels.
Answer: Memory-efficient storage for categorical data
Category dtype stores categorical data efficiently. Reduces memory for repeated strings. Ordered/unordered. Much faster operations. Convert with astype('category').
Answer: merge joins on columns, join on indices
merge joins on columns (more flexible), join primarily on indices. Both achieve similar results. merge is more explicit and commonly used.
Answer: Two-dimensional labeled data structure with columns
DataFrame is a 2D labeled data structure with columns of potentially different types. Like a spreadsheet or SQL table. Most commonly used Pandas structure.
Answer: Efficient storage for data with many missing values
Sparse data structures efficiently store data with many missing/zero values. Use pd.SparseDtype. Saves memory significantly for sparse datasets.
Answer: All of the above
All methods work, but import pandas as pd is the standard convention. Provides shorter alias while being clear and avoiding namespace pollution.
Answer: Processing large files in chunks
Chunking processes large files in chunks: pd.read_csv(chunksize=10000). Iterate over chunks. Prevents memory errors. Essential for big data in Pandas.
Answer: Concatenates DataFrames along axis
pd.concat([df1, df2]) concatenates along axis. axis=0 (default) stacks vertically, axis=1 horizontally. Use for combining DataFrames without keys.
Answer: pd.DataFrame(dict)
Use pd.DataFrame(dictionary). Keys become column names, values become column data. Most common way to create DataFrame from Python data.
Answer: Reshapes data from long to wide format
pivot() reshapes data: unique values of column become new columns. Creates pivot table. Use pivot_table() for aggregation with duplicate entries.
Answer: Chains operations for readable code
pipe() enables method chaining with functions. df.pipe(func1).pipe(func2). Creates readable data pipelines. Alternative to nested function calls.
Answer: Creates spreadsheet-style pivot table with aggregation
pivot_table() creates pivot table with aggregation. Handles duplicate entries. Specify values, index, columns, aggfunc. More flexible than pivot().
Answer: pd.read_csv('file.csv')
pd.read_csv('filename.csv') reads CSV file into DataFrame. Most common data import method. Supports many parameters for customization (sep, header, etc.).
Answer: JIT compilation for fast custom operations
Numba JIT-compiles Python code to machine code. Use @jit with apply: df.apply(numba_func, engine='numba'). Dramatic speedups for custom operations.
Answer: Parallel computing library for larger-than-memory datasets
Dask provides parallel computing for datasets larger than memory. Similar API to Pandas. Lazy evaluation, task graphs. Use when Pandas hits memory limits.
Answer: df.head()
df.head() displays first 5 rows by default. df.head(n) shows first n rows. Quick way to preview data. Similar: df.tail() for last rows.
Answer: Reshapes data from wide to long format
melt() unpivots DataFrame from wide to long format. Opposite of pivot. Specify id_vars (identifier columns) and value_vars (columns to unpivot).
The full Pandas bank has 90 questions across 3 difficulty levels — timed, shuffled, and scored.
Take the Pandas quiz