My problem is the definition of the function I adapted from an SO post. In the function I have 3 arguments: plot_with_checks(df, x_col, y_col), while as in in the plotting I have plt.plot(x=x_col, y=y_col), 2 arguments. In calling the function I call it with df (which is the full dataframe), hence the problem. So I think I need to have a function consistent with the call to function.