Calculated Columns

Calculated Columns: New Columns from Old: Math, np.where and cut, NumPy: The Engine Under pandas.

Updated

  1. New Columns from Old: Math, np.where and cut (Journeyman): Math between columns makes a new column for every row at once, np.where picks one of two values for each row from a True or False column, pd.cut sorts numbers into labeled bands such as budget, mid and premium, and apply runs a function of your own on every value, more slowly than whole-column math.
  2. NumPy: The Engine Under pandas (Journeyman): NumPy's array holds many values of one type and does math on all of them at once, a vectorized operation that a Python list can't do; every pandas column keeps its values in an array (to_numpy hands it over), np.mean gives NaN when a value is missing where pandas skips it, and one type per column is what makes the math fast.