replace(r'^ s*$' np.nan regex=true inplace=true) code example Example: pandas replace empty string with nan df = df.replace(r'^\s*$', np.NaN, regex=True)