pandas mark empty string as nan code example Example: pandas replace empty string with nan Click to copydf = df.replace(r'^\s*$', np.NaN, regex=True)