set initiall null value and replace later in python 3 code example Example: pandas replace empty string with nan df = df.replace(r'^\s*$', np.NaN, regex=True)