How can I replace all the " " values with Zero's in a column of a pandas dataframe
<pre><code>titanic_df['Embarked'] = titanic_df['Embarked'].fillna("S")
</code></pre>

<p>titanic_df is data frame,Embarked is a column name. I have to missing cells in my column  i.e blank spaces and I want to add "S" at the missing place but the code I mentioned above is not working.Please help me.</p>

<p>I think you need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.replace.html" rel="nofollow"><code>replace</code></a>:</p>

<pre><code>titanic_df['Embarked'] = titanic_df['Embarked'].replace(" ", "S")
</code></pre>

<p>Sample:</p>

<pre><code>import pandas as pd

titanic_df = pd.DataFrame({'Embarked':['a','d',' ']})
print (titanic_df)
  Embarked
0        a
1        d
2       

titanic_df['Embarked'] = titanic_df['Embarked'].replace(" ", "S")

print (titanic_df)
  Embarked
0        a
1        d
2        S
</code></pre>

<hr>

<p>Also you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.replace.html" rel="nofollow"><code>str.replace</code></a> with regex if need replace one or more whitespaces.<br>
 <code>^</code> means the beginning of whitespace(s), <code>$</code> means the end of  whitespace(s):</p>

<pre><code>titanic_df = pd.DataFrame({'Embarked':['a ',' d',' ', '    ']})
print (titanic_df)
  Embarked
0       a 
1        d
2         
3   

titanic_df['Embarked'] = titanic_df['Embarked'].str.replace("^\s+$", "S")
#same output
#titanic_df['Embarked'] = titanic_df['Embarked'].replace("^\s+$", "S", regex=True)
print (titanic_df)
  Embarked
0       a 
1        d
2        S
3        S
</code></pre>

python pandas