skip to content

Data & Analysis Libraries

The libraries that do the actual data work in code — pandas and NumPy in Python, dplyr and ggplot2 in R, plus the plotting layers on top. Interviewers ask about them because they reveal whether you think in vectorized operations or in loops.

on this pageshow

explore

questions

438 · 2 sections

In pandas, how does a DataFrame built from a dict of lists differ from one built from a list of dicts like API records?

level: juniorimportance: must knowfreq 70%
basics
~20 s

A dict of lists is column-oriented: each key is a column and all lists must share one length. A list of dicts is row-oriented: each dict is a row, columns are the union of keys, and a missing key becomes NaN.

open as a page

In pandas, what do shape, dtypes, head(), info() and describe() each tell you about a DataFrame you have just built?

level: juniorimportance: must knowfreq 75%
basics
~20 s

shape gives (rows, columns); dtypes gives each column's type; head() shows the first five rows; info() prints the index, each column's non-null count and dtype; describe() gives count, mean, spread and quartiles of numeric columns unless include='all'.

open as a page

In pandas 3.0, if you take `email = customers['email']` and change a value in `email`, does the `customers` DataFrame change?

level: juniorimportance: must knowfreq 55%
basics
~20 s

No. In pandas 3.0 Copy-on-Write makes every indexing result, including a column taken with [], behave as a copy, so editing it leaves the parent DataFrame untouched; to change the frame, write to the frame itself.

open as a page

In pandas, what do DataFrame.set_index and reset_index do to a product table's row labels, and what does drop change in each?

level: juniorimportance: must knowfreq 60%
basics
~20 s

set_index moves one or more columns into the row labels and, by default, removes them from the columns; reset_index moves the labels back into columns and installs a fresh RangeIndex, or discards them when drop=True.

open as a page

In pandas, a scraped price column holds strings like '$1,200' and 'N/A' — why does astype(float) raise, and how do you convert it?

level: juniorimportance: must knowfreq 70%
basics
~10 s

astype(float) is all-or-nothing: one value that does not parse, such as '$1,200' or 'N/A', raises ValueError. Strip the symbols with .str.replace, call pd.to_numeric(errors='coerce') so leftovers become NaN, then count those NaN.

open as a page

Two columns of 1,000 values each, taken from different tables, are added together — what decides which value pairs with which?

level: juniorimportance: must knowfreq 58%
basics
~10 s

The tool decides, not the expression. Designs that carry a per-row identifier pair the two operands by that identifier first; designs that carry none pair strictly by position and refuse operands of different lengths.

open as a page

A match of two tables on their key columns returns zero rows, though the same codes print on both sides. Why?

level: juniorimportance: must knowfreq 70%
basics
~20 s

Equality compares stored values, not the rendering. Two codes that print alike can differ by letter case, leading or trailing spaces, an invisible character, a lost leading zero, or one side holding digits as text and the other as numbers.

open as a page

Matching 1,000 orders to a customer list on customer id returns 940 rows: which match shape was used, and what do the others keep?

level: juniorimportance: must knowfreq 80%
basics
~20 s

Losing 60 rows means the match kept only rows partnered on both sides. The three alternatives keep the orders table whole, the customer list whole, or both whole, and unpartnered rows then survive with the other side's columns holding the absent-value marker.

open as a page

Twelve monthly pieces are stacked into one longer table - how does that differ from gluing two tables side by side?

level: juniorimportance: must knowfreq 66%
basics
~20 s

Stacking adds records, so the result is longer and the hazard is two pieces whose column sets do not agree. Gluing side by side adds attributes, so the result is wider and the hazard is rows paired in an order nobody checked.

open as a page

A match of 1,000 order rows against a customer reference table returns 1,340 rows - how is that possible?

level: juniorimportance: must knowfreq 76%
basics
~20 s

A key match returns, for each key value, the first side's occurrence count multiplied by the second side's. If a customer identifier appears more than once in the reference table, the orders carrying it are copied and the total grows.

open as a page