i have a 'fct' column and 'true' column, how to create a new column with mse for each row in a pandas dataframe in python

If df is the pandas DataFrame containing the columns fct and true, the new column MSE can be created as follows:

main.py
import numpy as np
import pandas as pd

df['MSE'] = np.square(df['fct'] - df['true'])
86 chars
5 lines

This computes the square of the difference between the fct and true columns for each row, and stores the result in the new MSE column.

related categories

gistlibby LogSnag