1. Given a pandas DataFrame, compute the 30-day moving average of a column.
df['ma'] = df['x'].rolling(30).mean().
Python interview questions for data roles are about pandas and data manipulation, not general software trivia. Real questions with worked answers below, across the data roles that get a Python round.
df['ma'] = df['x'].rolling(30).mean().
fillna (mean/median/mode/forward-fill), dropna, or model-based imputation depending on context.
pd.merge(left, right, on='key', how='left').
Use a dict for counts + heapq.nlargest, or Counter.most_common(k).
Vectorized ops are fastest, map is element-wise on a Series, and apply is flexible but slower (row or column).
Compute Q1 and Q3 with quantile in pandas, take IQR as Q3 minus Q1, and keep rows between Q1 minus 1.5 IQR and Q3 plus 1.5 IQR. Report how many rows the fence removed.
Iterate with prev/curr pointers, reversing next at each step.
df.groupby('cat').agg({'x':'sum','y':'mean'}).
Sort by time, flag new session where gap > 30min, cumsum the flags.
Lazy iterators built with yield, used for large or streamed data to save memory.
Stream it instead of loading it: read_csv with chunksize, or hand it to an engine that spills to disk and reads only the columns you touch (DuckDB, Polars lazy, Spark). If it is a recurring job, convert once to Parquet, columnar plus compression usually cuts both IO and memory by an order of magnitude. The general move is to make the working set fit in memory, not the file.