user7631183:
I am trying to remove punctuations from a col in a data frame by doing the following:
def remove_punctuation(text):
return text.translate(table)
df['data'] = df['data'].map(lambda x: remove_punctuation(x))
But I am getting the following error:
'float' Object has no attribute 'translate'
I checked the dtype of the col as in here:
from pandas.api.types import is_string_dtype
is_string_dtype(df['data'])
and got the following output:
True
I am not sure what's going wrong in here?
I have also tried the following: translator = str.maketrans('', '', string.punctuation)
def remove_punctuation(text):
return text.translate(translator)
df['data'] = df['data'].map(lambda x: remove_punctuation(x))
but I am still getting the same error
Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots