Remove punctuations in pandas
<pre><code>code: df['review'].head()
        index         review
output: 0      These flannel wipes are OK, but in my opinion
</code></pre>

<p>I want to remove punctuations from the column of the dataframe and create a new column.</p>

<pre><code>code: import string 
      def remove_punctuations(text):
          return text.translate(None,string.punctuation)

      df["new_column"] = df['review'].apply(remove_punctuations)

Error:
  return text.translate(None,string.punctuation)
  AttributeError: 'float' object has no attribute 'translate'
</code></pre>

<p>I am using python 2.7. Any suggestions would be helpful.</p>

<p>I solved the problem by looping through the string.punctuation</p>

<pre><code>def remove_punctuations(text):
    for punctuation in string.punctuation:
        text = text.replace(punctuation, '')
    return text
</code></pre>

<p>You can call the function the same way you did and It should work.</p>

<pre><code>df["new_column"] = df['review'].apply(remove_punctuations)
</code></pre>

python python-2.7 pandas